Mercurial > retraceit
annotate src/metadataview.cpp @ 17:73efe717b944
Fix bug in csv model to allow changing headerdata
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 14 Apr 2015 18:55:55 +0200 |
parents | e4748da7140b |
children | 0a08c1c2531a |
rev | line source |
---|---|
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 #include "metadataview.h" |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 #include "qxtcsvmodel.h" |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
3 #include "filterwidget.h" |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 #include <QTextCodec> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 #include <QTableView> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 #include <QSortFilterProxyModel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include <QVBoxLayout> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include <QLabel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include <QDebug> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QModelIndex> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QItemSelectionModel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) : |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 QWidget(parent, f) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 /* Create models */ |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 mSortModel = new QSortFilterProxyModel; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 mCSVModel = new QxtCsvModel; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 setupGUI(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 this, &MetaDataView::viewSelectionChanged); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
23 connect(mSortModel, &QSortFilterProxyModel::dataChanged, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
24 this, &MetaDataView::dataChanged); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 void MetaDataView::setupGUI() { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 QVBoxLayout *baseLayout = new QVBoxLayout; |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
30 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
31 FilterWidget *filterWidget = new FilterWidget(mSortModel); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
32 baseLayout->addWidget(filterWidget); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
33 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 mView = new QTableView; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 mView->setModel(mSortModel); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 mView->horizontalHeader()->setStretchLastSection(true); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 mView->resizeColumnsToContents(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 // mView->setColumnWidth(0, 60); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 mView->setSelectionBehavior(QAbstractItemView::SelectRows); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 mView->setSelectionMode(QAbstractItemView::SingleSelection); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 mView->setSortingEnabled(true); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 mView->setEditTriggers(QAbstractItemView::NoEditTriggers); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 baseLayout->addWidget(mView); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 setLayout(baseLayout); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 QString MetaDataView::parseMetaData(const QString& filePath) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 mCSVModel->setSource(filePath, true, ';', QTextCodec::codecForName("UTF8")); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 if (!mCSVModel->rowCount()) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 return tr("Failed to parse file: '%1'").arg(filePath); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 mSortModel->setSourceModel(mCSVModel); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 return QString(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
61 void MetaDataView::dataChanged() |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
62 { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
63 QItemSelectionModel *selection = mView->selectionModel(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
64 QModelIndexList selected = selection->selectedIndexes(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
65 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
66 qDebug() << "Data Changed."; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
67 if (selected.isEmpty()) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
68 /* Nothing selected still we need to emit this signal to update |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
69 * the viewer otherwise selection changed handles it. */ |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
70 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
71 QDateTime()); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
72 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
73 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
74 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 const QItemSelection& deselected) { |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
77 if (selected.indexes().isEmpty()) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
78 /* Nothing selected */ |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
79 return; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
80 } |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 /* One row selected */ |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 const QModelIndex idx = selected.indexes()[0]; |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
84 const QString dateString = selected.indexes()[1].data().toString(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
85 bool ok; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
86 qint64 secondsSinceEpoch = dateString.toLongLong(&ok); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
87 if (!ok) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
88 // TODO emit error |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
89 qDebug() << "Unparsable date."; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
90 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
91 QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
92 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1, |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
93 timestamp); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 qDebug() << "Selection changed: " << idx.data(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
97 void MetaDataView::selectRow(int row) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
98 QItemSelectionModel *selection = mView->selectionModel(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
99 if (!mSortModel->hasIndex(row, 0)) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
100 qDebug() << "Invalid row: " << row; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
101 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
102 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
103 QModelIndex newIdx = mSortModel->index(row, 0); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
104 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
105 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
106 |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
107 void MetaDataView::selectPrevRow() { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
108 QItemSelectionModel *selection = mView->selectionModel(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
109 QModelIndexList selected = selection->selectedIndexes(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
110 int row = 0, |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
111 col = 0; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
112 if (selected.isEmpty()) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
113 qDebug() << "Selection empty. Start at row 0"; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
114 if (!mSortModel->hasIndex(row, col)) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
115 qDebug() << "Empty model. Failed to advance."; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
116 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
117 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
118 } else { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
119 QModelIndex old = selection->selectedIndexes().first(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
120 if (!mSortModel->hasIndex(old.row() - 1, old.column())) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
121 qDebug() << "No less rows."; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
122 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
123 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
124 row = old.row() - 1; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
125 col = old.column(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
126 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
127 QModelIndex newIdx = mSortModel->index(row, col); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
128 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
129 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
130 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 void MetaDataView::selectNextRow() { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 QItemSelectionModel *selection = mView->selectionModel(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 QModelIndexList selected = selection->selectedIndexes(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 int row = 0, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 col = 0; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 if (selected.isEmpty()) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 qDebug() << "Selection empty. Start at row 0"; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 if (!mSortModel->hasIndex(row, col)) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 qDebug() << "Empty model. Failed to advance."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 } else { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
143 QModelIndex old = selection->selectedIndexes().first(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 if (!mSortModel->hasIndex(old.row() + 1, old.column())) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 qDebug() << "No more rows."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 row = old.row() + 1; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 col = old.column(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 QModelIndex newIdx = mSortModel->index(row, col); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 selection->select(newIdx, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 } |