annotate widgets/ModelDataTableDialog.cpp @ 399:80c7dd3c8dce

* Add audio device selection to preferences * Add (not yet functional) insert, delete, edit buttons to data edit window * Add proper set methods for time fields in data edit window (using general sparse model base class)
author Chris Cannam
date Fri, 13 Jun 2008 21:09:43 +0000
parents 80e279e4f9fe
children 32acd578fcba
rev   line source
Chris@392 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@392 2
Chris@392 3 /*
Chris@392 4 Sonic Visualiser
Chris@392 5 An audio file viewer and annotation editor.
Chris@392 6 Centre for Digital Music, Queen Mary, University of London.
Chris@392 7 This file copyright 2008 QMUL.
Chris@392 8
Chris@392 9 This program is free software; you can redistribute it and/or
Chris@392 10 modify it under the terms of the GNU General Public License as
Chris@392 11 published by the Free Software Foundation; either version 2 of the
Chris@392 12 License, or (at your option) any later version. See the file
Chris@392 13 COPYING included with this distribution for more information.
Chris@392 14 */
Chris@392 15
Chris@392 16 #include "ModelDataTableDialog.h"
Chris@392 17
Chris@392 18 #include "data/model/ModelDataTableModel.h"
Chris@395 19 #include "data/model/TabularModel.h"
Chris@398 20 #include "data/model/Model.h"
Chris@392 21
Chris@393 22 #include "CommandHistory.h"
Chris@399 23 #include "IconLoader.h"
Chris@393 24
Chris@392 25 #include <QTableView>
Chris@392 26 #include <QGridLayout>
Chris@392 27 #include <QGroupBox>
Chris@392 28 #include <QDialogButtonBox>
Chris@392 29 #include <QHeaderView>
Chris@392 30 #include <QApplication>
Chris@392 31 #include <QDesktopWidget>
Chris@399 32 #include <QAction>
Chris@399 33 #include <QToolBar>
Chris@392 34
Chris@393 35 #include <iostream>
Chris@393 36
Chris@398 37 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) :
Chris@396 38 QMainWindow(parent)
Chris@392 39 {
Chris@392 40 setWindowTitle(tr("Data Editor"));
Chris@392 41
Chris@396 42 QToolBar *toolbar = addToolBar(tr("Toolbar"));
Chris@399 43
Chris@399 44 IconLoader il;
Chris@399 45
Chris@399 46 QAction *action = new QAction(il.load("datainsert"), tr("Insert New Item"), this);
Chris@399 47 action->setShortcut(tr("Insert"));
Chris@399 48 action->setStatusTip(tr("Insert a new item"));
Chris@399 49 connect(action, SIGNAL(triggered()), this, SLOT(insertRow()));
Chris@399 50 toolbar->addAction(action);
Chris@399 51
Chris@399 52 action = new QAction(il.load("datadelete"), tr("Delete Selected Items"), this);
Chris@399 53 action->setShortcut(tr("Delete"));
Chris@399 54 action->setStatusTip(tr("Delete the selected item or items"));
Chris@399 55 connect(action, SIGNAL(triggered()), this, SLOT(deleteRow()));
Chris@399 56 toolbar->addAction(action);
Chris@399 57
Chris@399 58 action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this);
Chris@399 59 action->setShortcut(tr("Edit"));
Chris@399 60 action->setStatusTip(tr("Edit the selected item"));
Chris@399 61 connect(action, SIGNAL(triggered()), this, SLOT(editRow()));
Chris@399 62 toolbar->addAction(action);
Chris@399 63
Chris@396 64 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@396 65
Chris@396 66 QFrame *mainFrame = new QFrame;
Chris@396 67 setCentralWidget(mainFrame);
Chris@396 68
Chris@392 69 QGridLayout *grid = new QGridLayout;
Chris@396 70 mainFrame->setLayout(grid);
Chris@392 71
Chris@392 72 QGroupBox *box = new QGroupBox;
Chris@398 73 if (title != "") {
Chris@398 74 box->setTitle(title);
Chris@398 75 } else {
Chris@398 76 box->setTitle(tr("Data in Layer"));
Chris@398 77 }
Chris@392 78 grid->addWidget(box, 0, 0);
Chris@392 79 grid->setRowStretch(0, 15);
Chris@392 80
Chris@392 81 QGridLayout *subgrid = new QGridLayout;
Chris@392 82 box->setLayout(subgrid);
Chris@392 83
Chris@392 84 subgrid->setSpacing(0);
Chris@392 85 subgrid->setMargin(5);
Chris@392 86
Chris@392 87 m_tableView = new QTableView;
Chris@392 88 subgrid->addWidget(m_tableView);
Chris@392 89
Chris@399 90 // m_tableView->verticalHeader()->hide();
Chris@392 91 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
Chris@395 92 m_tableView->setSortingEnabled(true);
Chris@396 93 m_tableView->sortByColumn(0, Qt::AscendingOrder);
Chris@392 94
Chris@392 95 m_table = new ModelDataTableModel(model);
Chris@392 96 m_tableView->setModel(m_table);
Chris@392 97
Chris@393 98 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
Chris@393 99 this, SLOT(viewClicked(const QModelIndex &)));
Chris@393 100 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
Chris@393 101 this, SLOT(viewPressed(const QModelIndex &)));
Chris@397 102 connect(m_table, SIGNAL(executeCommand(Command *)),
Chris@397 103 this, SLOT(executeCommand(Command *)));
Chris@393 104
Chris@392 105 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@396 106 connect(bb, SIGNAL(rejected()), this, SLOT(close()));
Chris@392 107 grid->addWidget(bb, 2, 0);
Chris@392 108 grid->setRowStretch(2, 0);
Chris@392 109
Chris@392 110 QDesktopWidget *desktop = QApplication::desktop();
Chris@392 111 QRect available = desktop->availableGeometry();
Chris@392 112
Chris@392 113 int width = available.width() / 3;
Chris@392 114 int height = available.height() / 2;
Chris@392 115 if (height < 370) {
Chris@392 116 if (available.height() > 500) height = 370;
Chris@392 117 }
Chris@392 118 if (width < 500) {
Chris@392 119 if (available.width() > 650) width = 500;
Chris@392 120 }
Chris@392 121
Chris@392 122 resize(width, height);
Chris@392 123 }
Chris@392 124
Chris@392 125 ModelDataTableDialog::~ModelDataTableDialog()
Chris@392 126 {
Chris@392 127 delete m_table;
Chris@392 128 }
Chris@392 129
Chris@393 130 void
Chris@394 131 ModelDataTableDialog::scrollToFrameRequested(unsigned long frame)
Chris@393 132 {
Chris@393 133 m_tableView->scrollTo(m_table->getModelIndexForFrame(frame));
Chris@393 134 }
Chris@393 135
Chris@393 136 void
Chris@393 137 ModelDataTableDialog::viewClicked(const QModelIndex &index)
Chris@393 138 {
Chris@393 139 std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl;
Chris@394 140 emit scrollToFrame(m_table->getFrameForModelIndex(index));
Chris@393 141 }
Chris@393 142
Chris@393 143 void
Chris@393 144 ModelDataTableDialog::viewPressed(const QModelIndex &index)
Chris@393 145 {
Chris@393 146 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl;
Chris@393 147 }
Chris@393 148
Chris@393 149 void
Chris@399 150 ModelDataTableDialog::insertRow()
Chris@399 151 {
Chris@399 152 }
Chris@399 153
Chris@399 154 void
Chris@399 155 ModelDataTableDialog::deleteRow()
Chris@399 156 {
Chris@399 157 }
Chris@399 158
Chris@399 159 void
Chris@399 160 ModelDataTableDialog::editRow()
Chris@399 161 {
Chris@399 162 }
Chris@399 163
Chris@399 164 void
Chris@393 165 ModelDataTableDialog::executeCommand(Command *command)
Chris@393 166 {
Chris@397 167 std::cerr << "ModelDataTableDialog::executeCommand(" << command << ")" << std::endl;
Chris@397 168 CommandHistory::getInstance()->addCommand(command, false, true);
Chris@393 169 }
Chris@393 170