comparison widgets/ModelDataTableDialog.cpp @ 396:2669267fb7ea

* sorting arbitrary columns in data editor
author Chris Cannam
date Thu, 12 Jun 2008 09:03:00 +0000
parents 33c2f268c950
children 2c59b0cd176b
comparison
equal deleted inserted replaced
395:33c2f268c950 396:2669267fb7ea
29 #include <QDesktopWidget> 29 #include <QDesktopWidget>
30 30
31 #include <iostream> 31 #include <iostream>
32 32
33 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QWidget *parent) : 33 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QWidget *parent) :
34 QDialog(parent) 34 QMainWindow(parent)
35 { 35 {
36 setWindowTitle(tr("Data Editor")); 36 setWindowTitle(tr("Data Editor"));
37 37
38 QToolBar *toolbar = addToolBar(tr("Toolbar"));
39 CommandHistory::getInstance()->registerToolbar(toolbar);
40
41 QFrame *mainFrame = new QFrame;
42 setCentralWidget(mainFrame);
43
38 QGridLayout *grid = new QGridLayout; 44 QGridLayout *grid = new QGridLayout;
39 setLayout(grid); 45 mainFrame->setLayout(grid);
40 46
41 QGroupBox *box = new QGroupBox; 47 QGroupBox *box = new QGroupBox;
42 box->setTitle(tr("Layer Data")); 48 box->setTitle(tr("Layer Data"));
43 grid->addWidget(box, 0, 0); 49 grid->addWidget(box, 0, 0);
44 grid->setRowStretch(0, 15); 50 grid->setRowStretch(0, 15);
52 m_tableView = new QTableView; 58 m_tableView = new QTableView;
53 subgrid->addWidget(m_tableView); 59 subgrid->addWidget(m_tableView);
54 60
55 m_tableView->verticalHeader()->hide(); 61 m_tableView->verticalHeader()->hide();
56 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); 62 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
57 // m_tableView->setShowGrid(false);
58 m_tableView->setSortingEnabled(true); 63 m_tableView->setSortingEnabled(true);
64 m_tableView->sortByColumn(0, Qt::AscendingOrder);
59 65
60 m_table = new ModelDataTableModel(model); 66 m_table = new ModelDataTableModel(model);
61 m_tableView->setModel(m_table); 67 m_tableView->setModel(m_table);
62 68
63 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)), 69 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
64 this, SLOT(viewClicked(const QModelIndex &))); 70 this, SLOT(viewClicked(const QModelIndex &)));
65 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)), 71 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
66 this, SLOT(viewPressed(const QModelIndex &))); 72 this, SLOT(viewPressed(const QModelIndex &)));
67 73
68 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); 74 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
69 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); 75 connect(bb, SIGNAL(rejected()), this, SLOT(close()));
70 grid->addWidget(bb, 2, 0); 76 grid->addWidget(bb, 2, 0);
71 grid->setRowStretch(2, 0); 77 grid->setRowStretch(2, 0);
72 78
73 QDesktopWidget *desktop = QApplication::desktop(); 79 QDesktopWidget *desktop = QApplication::desktop();
74 QRect available = desktop->availableGeometry(); 80 QRect available = desktop->availableGeometry();