Mercurial > retraceit
annotate src/metadataview.cpp @ 88:3916cb3c9105
Add new FilterSort model that allows to include empty values
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 19 Jun 2015 14:26:16 +0200 |
parents | 9a03703622b8 |
children | b8c7644a9d49 |
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" |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
11 #include "includeemptysortmodel.h" |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
12 #include "constants.h" |
2
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 #include <QTextCodec> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 #include <QTableView> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 #include <QSortFilterProxyModel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 #include <QVBoxLayout> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 #include <QLabel> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 #include <QDebug> |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 #include <QModelIndex> |
22
0a08c1c2531a
Fix missing include and update translations accordingly
Andre Heinecke <andre.heinecke@intevation.de>
parents:
17
diff
changeset
|
21 #include <QHeaderView> |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 #include <QItemSelectionModel> |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
23 #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
|
24 #include <QFontMetrics> |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
25 #include <QApplication> |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 |
56
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
27 /**@brief Small wrapper around csv model to enable numerical sorting. */ |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
28 class numericSortCSVModel : public QxtCsvModel |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
29 { |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
30 public: |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
31 /**@brief returns the data as string, integer or double variant. */ |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
32 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const { |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
33 QVariant base = QxtCsvModel::data(index, role); |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
34 bool ok = false; |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
35 int intVal = base.toInt(&ok); |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
36 if (ok) { |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
37 return intVal; |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
38 } |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
39 double dblVal = base.toDouble(&ok); |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
40 if (ok) { |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
41 return dblVal; |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
42 } |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
43 return base; |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
44 } |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
45 }; |
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
46 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 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
|
48 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
|
49 mDateColIdx(-1) { |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 /* Create models */ |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
51 mSortModel = new IncludeEmptySortModel; |
56
016cbcb1a233
Wrap the CSV model to have it return not only string variants but also numerical types
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
52 mCSVModel = new numericSortCSVModel; |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 setupGUI(); |
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 connect(mView->selectionModel(), &QItemSelectionModel::selectionChanged, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 this, &MetaDataView::viewSelectionChanged); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
57 connect(mSortModel, &QSortFilterProxyModel::dataChanged, |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
58 this, &MetaDataView::dataChanged); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 } |
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 void MetaDataView::setupGUI() { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 QVBoxLayout *baseLayout = new QVBoxLayout; |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
64 |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
65 mFilterWidget = new FilterWidget(mSortModel, true); |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
66 connect(mFilterWidget, &FilterWidget::filterHasChanged, |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
67 this, &MetaDataView::applyDefaultSort); |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
68 connect(mFilterWidget, &FilterWidget::includeEmptyChanged, |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
69 mSortModel, &IncludeEmptySortModel::setIncludeEmpty); |
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
70 connect(mFilterWidget, &FilterWidget::filterHasChanged, |
53
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
71 this, &MetaDataView::selectFirstRow); |
88
3916cb3c9105
Add new FilterSort model that allows to include empty values
Andre Heinecke <andre.heinecke@intevation.de>
parents:
82
diff
changeset
|
72 baseLayout->addWidget(mFilterWidget); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
73 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 mView = new QTableView; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 mView->setModel(mSortModel); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 mView->horizontalHeader()->setStretchLastSection(true); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 // mView->setColumnWidth(0, 60); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 mView->setSelectionBehavior(QAbstractItemView::SelectRows); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 mView->setSelectionMode(QAbstractItemView::SingleSelection); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 mView->setSortingEnabled(true); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 mView->setEditTriggers(QAbstractItemView::NoEditTriggers); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 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
|
85 mView->verticalHeader()->setVisible(false); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 setLayout(baseLayout); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 QString MetaDataView::parseMetaData(const QString& filePath) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 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
|
92 if (!mCSVModel->rowCount()) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 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
|
94 } |
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 mSortModel->setSourceModel(mCSVModel); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 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
|
98 applyDefaultSort(); |
35
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
99 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
|
100 |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 break; |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
109 } |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
110 } |
73e6b6b12412
(issue 1,2) Make the column used for the Timestamp value configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
37
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 } |
81
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
115 setupHeaderTooltips(); |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 return QString(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
119 void MetaDataView::dataChanged() |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
120 { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
121 QItemSelectionModel *selection = mView->selectionModel(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
122 QModelIndexList selected = selection->selectedIndexes(); |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
123 |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
124 qDebug() << "Data Changed."; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
125 if (selected.isEmpty()) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
126 /* 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
|
127 * the viewer otherwise selection changed handles it. */ |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
128 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
|
129 QString(), 0); |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
130 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
131 } |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
132 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 void MetaDataView::viewSelectionChanged(const QItemSelection& selected, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 const QItemSelection& deselected) { |
4
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
135 if (selected.indexes().isEmpty()) { |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
136 /* Nothing selected */ |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
137 return; |
e4748da7140b
Add filter functionalty to metadataview
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
138 } |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 /* One row selected */ |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 bool ok; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 } |
3
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 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
|
153 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
|
154 qDebug() << "Selection changed: " << idx.data(); |
82
9a03703622b8
Scroll to selection when invisible
Andre Heinecke <andre.heinecke@intevation.de>
parents:
81
diff
changeset
|
155 if (!isVisible()) { |
9a03703622b8
Scroll to selection when invisible
Andre Heinecke <andre.heinecke@intevation.de>
parents:
81
diff
changeset
|
156 mView->scrollTo(selected.indexes()[0], QAbstractItemView::PositionAtTop); |
9a03703622b8
Scroll to selection when invisible
Andre Heinecke <andre.heinecke@intevation.de>
parents:
81
diff
changeset
|
157 } |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 |
53
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
160 void MetaDataView::selectFirstRow() { |
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
161 qDebug() << "Selecting first row"; |
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
162 selectRow(0); |
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
163 } |
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
164 |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
165 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
|
166 QItemSelectionModel *selection = mView->selectionModel(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
167 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
|
168 qDebug() << "Invalid row: " << row; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
169 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
170 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
171 QModelIndex newIdx = mSortModel->index(row, 0); |
53
28d5a77db9fb
Ensure that the first row is properly set after filtering
Andre Heinecke <andre.heinecke@intevation.de>
parents:
44
diff
changeset
|
172 selection->select(newIdx, QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); |
3
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
173 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
174 |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
175 void MetaDataView::selectPrevRow() { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
176 QItemSelectionModel *selection = mView->selectionModel(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
177 QModelIndexList selected = selection->selectedIndexes(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
178 int row = 0, |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
179 col = 0; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
180 if (selected.isEmpty()) { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
185 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
186 } else { |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
187 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
|
188 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
|
189 qDebug() << "No less rows."; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
190 return; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
191 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
192 row = old.row() - 1; |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
193 col = old.column(); |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
194 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
195 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
|
196 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
|
197 } |
248d5d1cdb38
Add functionalty to control buttons and make picture resizable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
2
diff
changeset
|
198 |
2
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
199 void MetaDataView::selectNextRow() { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
200 QItemSelectionModel *selection = mView->selectionModel(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
201 QModelIndexList selected = selection->selectedIndexes(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
202 int row = 0, |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
203 col = 0; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
204 if (selected.isEmpty()) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
205 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
|
206 if (!mSortModel->hasIndex(row, col)) { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
207 qDebug() << "Empty model. Failed to advance."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
208 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
209 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
210 } else { |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
211 QModelIndex old = selection->selectedIndexes().first(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
212 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
|
213 qDebug() << "No more rows."; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
214 return; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 row = old.row() + 1; |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
217 col = old.column(); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
218 } |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
219 QModelIndex newIdx = mSortModel->index(row, col); |
97d2c8869c39
First prototype implementation of table view and player
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
220 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
|
221 } |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
222 |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
223 void MetaDataView::applyDefaultSort() { |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
224 QSettings settings; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
225 QString sortField = settings.value(SORT_COLUMN_KEY, SORT_COLUMN_DEFAULT).toString(); |
55
23672cbc3e5f
Write out default values for sortsettings in the ini file.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
53
diff
changeset
|
226 settings.setValue(SORT_COLUMN_KEY, sortField); |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
227 bool sortAsc = settings.value(SORT_ORDER_KEY, SORT_ORDER_VALUE).toBool(); |
55
23672cbc3e5f
Write out default values for sortsettings in the ini file.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
53
diff
changeset
|
228 settings.setValue(SORT_ORDER_KEY, sortAsc); |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
229 |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
230 int idx = -1; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 idx = i; |
28
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
235 break; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
236 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
237 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
238 if (idx == -1) { |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
239 return; |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
240 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
241 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
|
242 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
|
243 } |
4e16fbd10945
(issue3-5) Make the default sort order configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
244 |
35
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
245 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
|
246 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
|
247 /* 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
|
248 * 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
|
249 * 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 } |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
257 } |
f10d4e035eec
(issue10) Use width of header as minimum of the column size
Andre Heinecke <andre.heinecke@intevation.de>
parents:
28
diff
changeset
|
258 } |
81
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
259 |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
260 void MetaDataView::setupHeaderTooltips() { |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
261 QSettings settings; |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
262 settings.beginGroup(TOOLTIP_CONFIG_GROUP); |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
263 for (int i=0; i < mSortModel->columnCount(); i++) { |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
264 QString entry = mSortModel->headerData(i, Qt::Horizontal).toString(); |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
265 QString toolTip = settings.value(entry).toString(); |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
266 settings.setValue(entry, toolTip); |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
267 if (!mSortModel->setHeaderData(i, Qt::Horizontal, toolTip, Qt::ToolTipRole)) { |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
268 qDebug() << "Failed to set header data"; |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
269 } |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
270 } |
5923d569167b
Make Header tooltips configurable
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
271 } |