annotate widgets/ModelDataTableDialog.cpp @ 393:6671eb37d6d6

* basics of data editing in data table view
author Chris Cannam
date Mon, 09 Jun 2008 16:01:50 +0000
parents 1d85aa5a49be
children 592d692b4f8b
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@392 19
Chris@393 20 #include "CommandHistory.h"
Chris@393 21
Chris@392 22 #include <QTableView>
Chris@392 23 #include <QGridLayout>
Chris@392 24 #include <QGroupBox>
Chris@392 25 #include <QDialogButtonBox>
Chris@392 26 #include <QHeaderView>
Chris@392 27 #include <QApplication>
Chris@392 28 #include <QDesktopWidget>
Chris@392 29
Chris@393 30 #include <iostream>
Chris@393 31
Chris@392 32 ModelDataTableDialog::ModelDataTableDialog(Model *model, QWidget *parent) :
Chris@392 33 QDialog(parent)
Chris@392 34 {
Chris@392 35 setWindowTitle(tr("Data Editor"));
Chris@392 36
Chris@392 37 QGridLayout *grid = new QGridLayout;
Chris@392 38 setLayout(grid);
Chris@392 39
Chris@392 40 QGroupBox *box = new QGroupBox;
Chris@392 41 box->setTitle(tr("Layer Data"));
Chris@392 42 grid->addWidget(box, 0, 0);
Chris@392 43 grid->setRowStretch(0, 15);
Chris@392 44
Chris@392 45 QGridLayout *subgrid = new QGridLayout;
Chris@392 46 box->setLayout(subgrid);
Chris@392 47
Chris@392 48 subgrid->setSpacing(0);
Chris@392 49 subgrid->setMargin(5);
Chris@392 50
Chris@392 51 m_tableView = new QTableView;
Chris@392 52 subgrid->addWidget(m_tableView);
Chris@392 53
Chris@392 54 m_tableView->verticalHeader()->hide();
Chris@392 55 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
Chris@393 56 // m_tableView->setShowGrid(false);
Chris@393 57 // m_tableView->setSortingEnabled(true);
Chris@392 58
Chris@392 59 m_table = new ModelDataTableModel(model);
Chris@392 60 m_tableView->setModel(m_table);
Chris@392 61
Chris@393 62 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
Chris@393 63 this, SLOT(viewClicked(const QModelIndex &)));
Chris@393 64 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
Chris@393 65 this, SLOT(viewPressed(const QModelIndex &)));
Chris@393 66
Chris@392 67 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@392 68 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@392 69 grid->addWidget(bb, 2, 0);
Chris@392 70 grid->setRowStretch(2, 0);
Chris@392 71
Chris@392 72 QDesktopWidget *desktop = QApplication::desktop();
Chris@392 73 QRect available = desktop->availableGeometry();
Chris@392 74
Chris@392 75 int width = available.width() / 3;
Chris@392 76 int height = available.height() / 2;
Chris@392 77 if (height < 370) {
Chris@392 78 if (available.height() > 500) height = 370;
Chris@392 79 }
Chris@392 80 if (width < 500) {
Chris@392 81 if (available.width() > 650) width = 500;
Chris@392 82 }
Chris@392 83
Chris@392 84 resize(width, height);
Chris@392 85 }
Chris@392 86
Chris@392 87 ModelDataTableDialog::~ModelDataTableDialog()
Chris@392 88 {
Chris@392 89 delete m_table;
Chris@392 90 }
Chris@392 91
Chris@393 92 void
Chris@393 93 ModelDataTableDialog::scrollToFrame(unsigned long frame)
Chris@393 94 {
Chris@393 95 m_tableView->scrollTo(m_table->getModelIndexForFrame(frame));
Chris@393 96 }
Chris@393 97
Chris@393 98 void
Chris@393 99 ModelDataTableDialog::viewClicked(const QModelIndex &index)
Chris@393 100 {
Chris@393 101 std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl;
Chris@393 102 }
Chris@393 103
Chris@393 104 void
Chris@393 105 ModelDataTableDialog::viewPressed(const QModelIndex &index)
Chris@393 106 {
Chris@393 107 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl;
Chris@393 108 }
Chris@393 109
Chris@393 110 void
Chris@393 111 ModelDataTableDialog::executeCommand(Command *command)
Chris@393 112 {
Chris@393 113 CommandHistory::getInstance()->addCommand(command, true, true);
Chris@393 114 }
Chris@393 115