Mercurial > retraceit
annotate src/metadataview.cpp @ 44:73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
If the column contains a number it is interpreted as seconds since
epoch. Otherwise its a verbatim copy of the column string.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 06 May 2015 19:45:26 +0200 |
parents | 0c05958d254c |
children | 28d5a77db9fb |
rev | line source |
---|---|
25
64a51a42c01f
Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
24
diff
changeset
|
1 /* Copyright (C) 2015 by ETH Zürich |
64a51a42c01f
Assign copyright correctly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
24
diff
changeset
|
2 * Software engineering by Intevation GmbH |
24
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
22
diff
changeset
|
3 * |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
22
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
22
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
22
diff
changeset
|
6 * See LICENSE.txt for details. |
6b9b5efcd7f4
Add missing copyright header
Andre Heinecke <andre.heinecke@intevation.de>
parents:
22
diff
changeset
|
7 */ |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include "metadataview.h" |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include "qxtcsvmodel.h" |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
10 #include "filterwidget.h" |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
11 #include "constants.h" |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 #include <QTextCodec> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 #include <QTableView> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 #include <QSortFilterProxyModel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 #include <QVBoxLayout> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 #include <QLabel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 #include <QDebug> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 #include <QModelIndex> |
22
0a08c1c2531a
Fix missing include and update translations accordingly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
17
diff
changeset
|
20 #include <QHeaderView> |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 #include <QItemSelectionModel> |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
22 #include <QSettings> |
35
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
23 #include <QFontMetrics> |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
24 #include <QApplication> |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 MetaDataView::MetaDataView(QWidget *parent, Qt::WindowFlags f) : |
44
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
27 QWidget(parent, f), |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
28 mDateColIdx(-1) { |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 /* Create models */ |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 mSortModel = new QSortFilterProxyModel; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 mCSVModel = new QxtCsvModel; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 setupGUI(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 this, &MetaDataView::viewSelectionChanged); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
36 connect(mSortModel, &QSortFilterProxyModel::dataChanged, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
37 this, &MetaDataView::dataChanged); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 void MetaDataView::setupGUI() { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 QVBoxLayout *baseLayout = new QVBoxLayout; |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
43 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
44 FilterWidget *filterWidget = new FilterWidget(mSortModel); |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
45 connect(filterWidget, &FilterWidget::filterHasChanged, |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
46 this, &MetaDataView::applyDefaultSort); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
47 baseLayout->addWidget(filterWidget); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
48 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 mView = new QTableView; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 mView->setModel(mSortModel); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 mView->horizontalHeader()->setStretchLastSection(true); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 // mView->setColumnWidth(0, 60); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 mView->setSelectionBehavior(QAbstractItemView::SelectRows); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 mView->setSelectionMode(QAbstractItemView::SingleSelection); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 mView->setSortingEnabled(true); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 mView->setEditTriggers(QAbstractItemView::NoEditTriggers); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 baseLayout->addWidget(mView); |
37
0c05958d254c
(issue 13, 6) Add constant index number column to data and view
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
60 mView->verticalHeader()->setVisible(false); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 setLayout(baseLayout); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 QString MetaDataView::parseMetaData(const QString& filePath) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 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
|
67 if (!mCSVModel->rowCount()) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 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
|
69 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 mSortModel->setSourceModel(mCSVModel); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 qDebug() << "Parsed: " << mCSVModel->rowCount() << " rows."; |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
73 applyDefaultSort(); |
35
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
74 resizeColsToHeaders(); |
44
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
75 |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
76 QSettings settings; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
77 const QString displayDate = settings.value(DATE_COLUMN_KEY, DATE_COLUMN_DEFAULT).toString(); |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
78 settings.setValue(DATE_COLUMN_KEY, displayDate); |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
79 for (int i=0; i < mSortModel->columnCount(); i++) { |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
80 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString(); |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
81 if (entry.toLower() == displayDate.toLower()) { |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
82 mDateColIdx = i; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
83 break; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
84 } |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
85 } |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
86 if (mDateColIdx == -1) { |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
87 qDebug() << "Failed to find displayDate column: " << displayDate; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
88 mDateColIdx = DATE_COLUMN_FALLBACK_IDX; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
89 } |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 return QString(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
93 void MetaDataView::dataChanged() |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
94 { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
95 QItemSelectionModel *selection = mView->selectionModel(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
96 QModelIndexList selected = selection->selectedIndexes(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
97 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
98 qDebug() << "Data Changed."; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
99 if (selected.isEmpty()) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
100 /* 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
|
101 * the viewer otherwise selection changed handles it. */ |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
102 emit selectionChanged(QString(), 0, mSortModel->rowCount() - 1, |
44
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
103 QString(), 0); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
104 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
105 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
106 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 const QItemSelection& deselected) { |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
109 if (selected.indexes().isEmpty()) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
110 /* Nothing selected */ |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
111 return; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
112 } |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 /* One row selected */ |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 Q_ASSERT(selected.indexes().count() == mCSVModel->columnCount()); |
44
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
115 const QModelIndex idx = selected.indexes()[FILENAME_COLUMN_IDX]; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
116 const QString dateString = selected.indexes()[mDateColIdx].data().toString(); |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
117 bool ok; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
118 qint64 secondsSinceEpoch = dateString.toLongLong(&ok); |
44
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
119 QString timestamp = dateString; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
120 if (ok) { |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
121 QDateTime datetime = QDateTime::fromMSecsSinceEpoch(secondsSinceEpoch * 1000); |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
122 if (datetime.isValid()) { |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
123 timestamp = datetime.toString(LONG_DATE_FORMAT); |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
124 } |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
125 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
126 emit selectionChanged(idx.data().toString(), idx.row(), mSortModel->rowCount() - 1, |
37
0c05958d254c
(issue 13, 6) Add constant index number column to data and view
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
127 timestamp, selected.indexes()[0].data().toInt()); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 qDebug() << "Selection changed: " << idx.data(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
131 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
|
132 QItemSelectionModel *selection = mView->selectionModel(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
133 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
|
134 qDebug() << "Invalid row: " << row; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
135 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
136 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
137 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
|
138 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
|
139 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
140 |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
141 void MetaDataView::selectPrevRow() { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
142 QItemSelectionModel *selection = mView->selectionModel(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
143 QModelIndexList selected = selection->selectedIndexes(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
144 int row = 0, |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
145 col = 0; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
146 if (selected.isEmpty()) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
151 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
152 } else { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
153 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
|
154 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
|
155 qDebug() << "No less rows."; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
156 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
157 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
158 row = old.row() - 1; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
159 col = old.column(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
160 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
161 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
|
162 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
|
163 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
164 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 void MetaDataView::selectNextRow() { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 QItemSelectionModel *selection = mView->selectionModel(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 QModelIndexList selected = selection->selectedIndexes(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
168 int row = 0, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 col = 0; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 if (selected.isEmpty()) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
171 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
|
172 if (!mSortModel->hasIndex(row, col)) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 qDebug() << "Empty model. Failed to advance."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
175 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
176 } else { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
177 QModelIndex old = selection->selectedIndexes().first(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
178 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
|
179 qDebug() << "No more rows."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
180 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
181 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
182 row = old.row() + 1; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
183 col = old.column(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
184 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
185 QModelIndex newIdx = mSortModel->index(row, col); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
186 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
|
187 } |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
188 |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
189 void MetaDataView::applyDefaultSort() { |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
190 QSettings settings; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
191 QString sortField = settings.value(SORT_COLUMN_KEY, SORT_COLUMN_DEFAULT).toString(); |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
192 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool(); |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
193 |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
194 int idx = -1; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
195 for (int i=0; i < mSortModel->columnCount(); i++) { |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
196 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString(); |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
197 if (entry.toLower() == sortField.toLower()) { |
37
0c05958d254c
(issue 13, 6) Add constant index number column to data and view
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
198 idx = i; |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
199 break; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
200 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
201 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
202 if (idx == -1) { |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
203 return; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
204 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
205 qDebug() << "Applying default sort order on column " << idx; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
206 mView->sortByColumn(idx, sortAsc ? Qt::AscendingOrder : Qt::DescendingOrder); |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
207 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
208 |
35
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
209 void MetaDataView::resizeColsToHeaders() { |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
210 QFontMetrics fm(qApp->font()); |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
211 /* We do this manually here to avoid resizing to the real contents as |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
212 * we want the columns in the width of the header data. And we only |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
213 * want to increase that size. */ |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
214 for (int i=0; i < mSortModel->columnCount(); i++) { |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
215 const QString entry = mSortModel->headerData(i, Qt::Horizontal).toString(); |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
216 int w = fm.width(entry) + 20; |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
217 if (w > mView->horizontalHeader()->sectionSize(i)) { |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
218 mView->horizontalHeader()->resizeSection(i, w); |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
219 qDebug() << "Resizing " << i << " to: " << w; |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
220 } |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
221 } |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
222 } |