Chris@392: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@392: Chris@392: /* Chris@392: Sonic Visualiser Chris@392: An audio file viewer and annotation editor. Chris@392: Centre for Digital Music, Queen Mary, University of London. Chris@392: This file copyright 2008 QMUL. Chris@392: Chris@392: This program is free software; you can redistribute it and/or Chris@392: modify it under the terms of the GNU General Public License as Chris@392: published by the Free Software Foundation; either version 2 of the Chris@392: License, or (at your option) any later version. See the file Chris@392: COPYING included with this distribution for more information. Chris@392: */ Chris@392: Chris@392: #include "ModelDataTableDialog.h" Chris@392: Chris@392: #include "data/model/ModelDataTableModel.h" Chris@395: #include "data/model/TabularModel.h" Chris@398: #include "data/model/Model.h" Chris@392: Chris@393: #include "CommandHistory.h" Chris@399: #include "IconLoader.h" Chris@393: Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@399: #include Chris@399: #include Chris@392: Chris@393: #include Chris@393: Chris@398: ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) : Chris@396: QMainWindow(parent) Chris@392: { Chris@392: setWindowTitle(tr("Data Editor")); Chris@392: Chris@396: QToolBar *toolbar = addToolBar(tr("Toolbar")); Chris@399: Chris@399: IconLoader il; Chris@399: Chris@399: QAction *action = new QAction(il.load("datainsert"), tr("Insert New Item"), this); Chris@399: action->setShortcut(tr("Insert")); Chris@399: action->setStatusTip(tr("Insert a new item")); Chris@399: connect(action, SIGNAL(triggered()), this, SLOT(insertRow())); Chris@399: toolbar->addAction(action); Chris@399: Chris@399: action = new QAction(il.load("datadelete"), tr("Delete Selected Items"), this); Chris@399: action->setShortcut(tr("Delete")); Chris@399: action->setStatusTip(tr("Delete the selected item or items")); Chris@399: connect(action, SIGNAL(triggered()), this, SLOT(deleteRow())); Chris@399: toolbar->addAction(action); Chris@399: Chris@399: action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this); Chris@399: action->setShortcut(tr("Edit")); Chris@399: action->setStatusTip(tr("Edit the selected item")); Chris@399: connect(action, SIGNAL(triggered()), this, SLOT(editRow())); Chris@399: toolbar->addAction(action); Chris@399: Chris@396: CommandHistory::getInstance()->registerToolbar(toolbar); Chris@396: Chris@396: QFrame *mainFrame = new QFrame; Chris@396: setCentralWidget(mainFrame); Chris@396: Chris@392: QGridLayout *grid = new QGridLayout; Chris@396: mainFrame->setLayout(grid); Chris@392: Chris@392: QGroupBox *box = new QGroupBox; Chris@398: if (title != "") { Chris@398: box->setTitle(title); Chris@398: } else { Chris@398: box->setTitle(tr("Data in Layer")); Chris@398: } Chris@392: grid->addWidget(box, 0, 0); Chris@392: grid->setRowStretch(0, 15); Chris@392: Chris@392: QGridLayout *subgrid = new QGridLayout; Chris@392: box->setLayout(subgrid); Chris@392: Chris@392: subgrid->setSpacing(0); Chris@392: subgrid->setMargin(5); Chris@392: Chris@392: m_tableView = new QTableView; Chris@392: subgrid->addWidget(m_tableView); Chris@392: Chris@399: // m_tableView->verticalHeader()->hide(); Chris@392: // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); Chris@395: m_tableView->setSortingEnabled(true); Chris@396: m_tableView->sortByColumn(0, Qt::AscendingOrder); Chris@392: Chris@392: m_table = new ModelDataTableModel(model); Chris@392: m_tableView->setModel(m_table); Chris@392: Chris@393: connect(m_tableView, SIGNAL(clicked(const QModelIndex &)), Chris@393: this, SLOT(viewClicked(const QModelIndex &))); Chris@393: connect(m_tableView, SIGNAL(pressed(const QModelIndex &)), Chris@393: this, SLOT(viewPressed(const QModelIndex &))); Chris@397: connect(m_table, SIGNAL(executeCommand(Command *)), Chris@397: this, SLOT(executeCommand(Command *))); Chris@393: Chris@392: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); Chris@396: connect(bb, SIGNAL(rejected()), this, SLOT(close())); Chris@392: grid->addWidget(bb, 2, 0); Chris@392: grid->setRowStretch(2, 0); Chris@392: Chris@392: QDesktopWidget *desktop = QApplication::desktop(); Chris@392: QRect available = desktop->availableGeometry(); Chris@392: Chris@392: int width = available.width() / 3; Chris@392: int height = available.height() / 2; Chris@392: if (height < 370) { Chris@392: if (available.height() > 500) height = 370; Chris@392: } Chris@392: if (width < 500) { Chris@392: if (available.width() > 650) width = 500; Chris@392: } Chris@392: Chris@392: resize(width, height); Chris@392: } Chris@392: Chris@392: ModelDataTableDialog::~ModelDataTableDialog() Chris@392: { Chris@392: delete m_table; Chris@392: } Chris@392: Chris@393: void Chris@394: ModelDataTableDialog::scrollToFrameRequested(unsigned long frame) Chris@393: { Chris@393: m_tableView->scrollTo(m_table->getModelIndexForFrame(frame)); Chris@393: } Chris@393: Chris@393: void Chris@393: ModelDataTableDialog::viewClicked(const QModelIndex &index) Chris@393: { Chris@393: std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl; Chris@394: emit scrollToFrame(m_table->getFrameForModelIndex(index)); Chris@393: } Chris@393: Chris@393: void Chris@393: ModelDataTableDialog::viewPressed(const QModelIndex &index) Chris@393: { Chris@393: std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl; Chris@393: } Chris@393: Chris@393: void Chris@399: ModelDataTableDialog::insertRow() Chris@399: { Chris@399: } Chris@399: Chris@399: void Chris@399: ModelDataTableDialog::deleteRow() Chris@399: { Chris@399: } Chris@399: Chris@399: void Chris@399: ModelDataTableDialog::editRow() Chris@399: { Chris@399: } Chris@399: Chris@399: void Chris@393: ModelDataTableDialog::executeCommand(Command *command) Chris@393: { Chris@397: std::cerr << "ModelDataTableDialog::executeCommand(" << command << ")" << std::endl; Chris@397: CommandHistory::getInstance()->addCommand(command, false, true); Chris@393: } Chris@393: