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@393
|
23
|
Chris@392
|
24 #include <QTableView>
|
Chris@392
|
25 #include <QGridLayout>
|
Chris@392
|
26 #include <QGroupBox>
|
Chris@392
|
27 #include <QDialogButtonBox>
|
Chris@392
|
28 #include <QHeaderView>
|
Chris@392
|
29 #include <QApplication>
|
Chris@392
|
30 #include <QDesktopWidget>
|
Chris@392
|
31
|
Chris@393
|
32 #include <iostream>
|
Chris@393
|
33
|
Chris@398
|
34 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) :
|
Chris@396
|
35 QMainWindow(parent)
|
Chris@392
|
36 {
|
Chris@392
|
37 setWindowTitle(tr("Data Editor"));
|
Chris@392
|
38
|
Chris@396
|
39 QToolBar *toolbar = addToolBar(tr("Toolbar"));
|
Chris@396
|
40 CommandHistory::getInstance()->registerToolbar(toolbar);
|
Chris@396
|
41
|
Chris@396
|
42 QFrame *mainFrame = new QFrame;
|
Chris@396
|
43 setCentralWidget(mainFrame);
|
Chris@396
|
44
|
Chris@392
|
45 QGridLayout *grid = new QGridLayout;
|
Chris@396
|
46 mainFrame->setLayout(grid);
|
Chris@392
|
47
|
Chris@392
|
48 QGroupBox *box = new QGroupBox;
|
Chris@398
|
49 if (title != "") {
|
Chris@398
|
50 box->setTitle(title);
|
Chris@398
|
51 } else {
|
Chris@398
|
52 box->setTitle(tr("Data in Layer"));
|
Chris@398
|
53 }
|
Chris@392
|
54 grid->addWidget(box, 0, 0);
|
Chris@392
|
55 grid->setRowStretch(0, 15);
|
Chris@392
|
56
|
Chris@392
|
57 QGridLayout *subgrid = new QGridLayout;
|
Chris@392
|
58 box->setLayout(subgrid);
|
Chris@392
|
59
|
Chris@392
|
60 subgrid->setSpacing(0);
|
Chris@392
|
61 subgrid->setMargin(5);
|
Chris@392
|
62
|
Chris@392
|
63 m_tableView = new QTableView;
|
Chris@392
|
64 subgrid->addWidget(m_tableView);
|
Chris@392
|
65
|
Chris@392
|
66 m_tableView->verticalHeader()->hide();
|
Chris@392
|
67 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
Chris@395
|
68 m_tableView->setSortingEnabled(true);
|
Chris@396
|
69 m_tableView->sortByColumn(0, Qt::AscendingOrder);
|
Chris@392
|
70
|
Chris@392
|
71 m_table = new ModelDataTableModel(model);
|
Chris@392
|
72 m_tableView->setModel(m_table);
|
Chris@392
|
73
|
Chris@393
|
74 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
|
Chris@393
|
75 this, SLOT(viewClicked(const QModelIndex &)));
|
Chris@393
|
76 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
|
Chris@393
|
77 this, SLOT(viewPressed(const QModelIndex &)));
|
Chris@397
|
78 connect(m_table, SIGNAL(executeCommand(Command *)),
|
Chris@397
|
79 this, SLOT(executeCommand(Command *)));
|
Chris@393
|
80
|
Chris@392
|
81 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
|
Chris@396
|
82 connect(bb, SIGNAL(rejected()), this, SLOT(close()));
|
Chris@392
|
83 grid->addWidget(bb, 2, 0);
|
Chris@392
|
84 grid->setRowStretch(2, 0);
|
Chris@392
|
85
|
Chris@392
|
86 QDesktopWidget *desktop = QApplication::desktop();
|
Chris@392
|
87 QRect available = desktop->availableGeometry();
|
Chris@392
|
88
|
Chris@392
|
89 int width = available.width() / 3;
|
Chris@392
|
90 int height = available.height() / 2;
|
Chris@392
|
91 if (height < 370) {
|
Chris@392
|
92 if (available.height() > 500) height = 370;
|
Chris@392
|
93 }
|
Chris@392
|
94 if (width < 500) {
|
Chris@392
|
95 if (available.width() > 650) width = 500;
|
Chris@392
|
96 }
|
Chris@392
|
97
|
Chris@392
|
98 resize(width, height);
|
Chris@392
|
99 }
|
Chris@392
|
100
|
Chris@392
|
101 ModelDataTableDialog::~ModelDataTableDialog()
|
Chris@392
|
102 {
|
Chris@392
|
103 delete m_table;
|
Chris@392
|
104 }
|
Chris@392
|
105
|
Chris@393
|
106 void
|
Chris@394
|
107 ModelDataTableDialog::scrollToFrameRequested(unsigned long frame)
|
Chris@393
|
108 {
|
Chris@393
|
109 m_tableView->scrollTo(m_table->getModelIndexForFrame(frame));
|
Chris@393
|
110 }
|
Chris@393
|
111
|
Chris@393
|
112 void
|
Chris@393
|
113 ModelDataTableDialog::viewClicked(const QModelIndex &index)
|
Chris@393
|
114 {
|
Chris@393
|
115 std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl;
|
Chris@394
|
116 emit scrollToFrame(m_table->getFrameForModelIndex(index));
|
Chris@393
|
117 }
|
Chris@393
|
118
|
Chris@393
|
119 void
|
Chris@393
|
120 ModelDataTableDialog::viewPressed(const QModelIndex &index)
|
Chris@393
|
121 {
|
Chris@393
|
122 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl;
|
Chris@393
|
123 }
|
Chris@393
|
124
|
Chris@393
|
125 void
|
Chris@393
|
126 ModelDataTableDialog::executeCommand(Command *command)
|
Chris@393
|
127 {
|
Chris@397
|
128 std::cerr << "ModelDataTableDialog::executeCommand(" << command << ")" << std::endl;
|
Chris@397
|
129 CommandHistory::getInstance()->addCommand(command, false, true);
|
Chris@393
|
130 }
|
Chris@393
|
131
|