itom
Loading...
Searching...
No Matches
dataObjectTable.h
1/* ********************************************************************
2 itom measurement system
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2021, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 itom is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, as a special exception, the Institut für Technische
23 Optik (ITO) gives you certain additional rights.
24 These rights are described in the ITO LGPL Exception version 1.0,
25 which can be found in the file LGPL_EXCEPTION.txt in this package.
26*********************************************************************** */
27
28#pragma once
29
30#include "DataObject/dataobj.h"
31
32#include <qtableview.h>
33#include <qsharedpointer.h>
34#include <qheaderview.h>
35#include <qitemselectionmodel.h>
36#include <qhash.h>
37
38#include "commonWidgets.h"
39
40class QKeyEvent;
41class QContextMenuEvent;
42class DataObjectModel;
45
46class ITOMWIDGETS_EXPORT DataObjectTable : public QTableView
47{
48 Q_OBJECT
49
50 Q_PROPERTY(QSharedPointer<ito::DataObject> data READ getData WRITE setData DESIGNABLE false);
51 Q_PROPERTY(bool readOnly READ getReadOnly WRITE setReadOnly DESIGNABLE true);
52 Q_PROPERTY(double min READ getMin WRITE setMin DESIGNABLE true);
53 Q_PROPERTY(double max READ getMax WRITE setMax DESIGNABLE true);
54 Q_PROPERTY(int decimals READ getDecimals WRITE setDecimals DESIGNABLE true);
55 Q_PROPERTY(int editorDecimals READ getEditorDecimals WRITE setEditorDecimals DESIGNABLE true);
56 Q_PROPERTY(int defaultCols READ getDefaultCols WRITE setDefaultCols DESIGNABLE true);
57 Q_PROPERTY(int defaultRows READ getDefaultRows WRITE setDefaultRows DESIGNABLE true);
58 Q_PROPERTY(QStringList horizontalLabels READ getHorizontalLabels WRITE setHorizontalLabels DESIGNABLE true);
59 Q_PROPERTY(QStringList verticalLabels READ getVerticalLabels WRITE setVerticalLabels DESIGNABLE true);
60 Q_PROPERTY(QStringList suffixes READ getSuffixes WRITE setSuffixes DESIGNABLE true);
61 Q_PROPERTY(QHeaderView::ResizeMode horizontalResizeMode READ getHorizontalResizeMode WRITE setHorizontalResizeMode DESIGNABLE true);
62 Q_PROPERTY(QHeaderView::ResizeMode verticalResizeMode READ getVerticalResizeMode WRITE setVerticalResizeMode DESIGNABLE true);
63 Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment DESIGNABLE true);
64 Q_PROPERTY(NumberFormat numberFormat READ getNumberFormat WRITE setNumberFormat DESIGNABLE true);
65
66
67 Q_CLASSINFO("prop://data", "dataObject that is displaye in the table view");
68 Q_CLASSINFO("prop://readOnly", "enable write protection");
69 Q_CLASSINFO("prop://min", "minimum acceptable value (if editing is allowed)");
70 Q_CLASSINFO("prop://max", "maximum acceptable value (if editing is allowed)");
71 Q_CLASSINFO("prop://decimals", "number of visible decimals for floating point numbers");
72 Q_CLASSINFO("prop://editorDecimals", "number of possible decimals during the edit of floating point numbers");
73 Q_CLASSINFO("prop://defaultCols", "number of column to be shown");
74 Q_CLASSINFO("prop://defaultRows", "number of rows to be shown");
75 Q_CLASSINFO("prop://horizontalLabels", "list with labels for each shown column (if more columns are shown than labels, a default numbering is used for additional columns)");
76 Q_CLASSINFO("prop://verticalLabels", "list with labels for each shown row (if more rows are shown than labels, a default numbering is used for additional rows)");
77 Q_CLASSINFO("prop://suffixes", "list with suffixes for each column. If less suffixes than columns are indicated, the last suffix is repeated.");
78 Q_CLASSINFO("prop://horizontalResizeMode", "defines the mode how the rows can be resized or are stretched over the available space (ResizeToContents, Interactive, Stretch, Fixed, Custom -> see QHeaderView::ResizeMode).");
79 Q_CLASSINFO("prop://verticalResizeMode", "defines the mode how the columns can be resized or are stretched over the available space (ResizeToContents, Interactive, Stretch, Fixed, Custom -> see QHeaderView::ResizeMode).");
80 Q_CLASSINFO("prop://alignment", "alignment of the text cells.");
81 Q_CLASSINFO("prop://numberFormat", "number format notation for floating point numbers, e.g. 0.002 or 2e-3. The meaning of ``decimals`` depends on this property.")
82
83 Q_CLASSINFO("signal://activated", "signal emitted if a cell is activated. Arguments are (row,column) of the cell.")
84 Q_CLASSINFO("signal://clicked", "signal emitted if a cell is clicked by the mouse. Arguments are (row,column) of the cell.")
85 Q_CLASSINFO("signal://doubleClicked", "signal emitted if a cell is double clicked by the mouse. Arguments are (row,column) of the cell.")
86 Q_CLASSINFO("signal://entered", "signal emitted if a cell is entered by the mouse cursor. Arguments are (row,column) of the cell. Property 'mouseTracking' needs to be enabled for this feature to work.")
87 Q_CLASSINFO("signal://pressed", "signal emitted if a cell if the mouse is pressed on a cell. Arguments are (row,column) of the cell.")
88
89public:
90 enum NumberFormat { Standard = 0, Scientific = 1, Auto = 2 };
91 Q_ENUM(NumberFormat)
92
93 enum HeatmapType { Off = 0, RealColor = 1, RedYellowGreen = 2, GreenYellowRed = 3, RedWhiteGreen = 4, GreenWhiteRed = 5 };
94 Q_ENUM(HeatmapType)
95
96 DataObjectTable(QWidget *parent = 0);
98
99 void setData(QSharedPointer<ito::DataObject> dataObj);
100 QSharedPointer<ito::DataObject> getData() const;
101
102 bool getReadOnly() const;
103 void setReadOnly(bool value);
104
105 double getMin() const;
106 void setMin(double value);
107
108 double getMax() const;
109 void setMax(double value);
110
111 int getDecimals() const;
112 void setDecimals(int value);
113
114 void setNumberFormat(const NumberFormat& format);
115 NumberFormat getNumberFormat() const;
116
117 Qt::Alignment getAlignment() const;
118 void setAlignment(Qt::Alignment alignment);
119
120 int getEditorDecimals() const;
121 void setEditorDecimals(int value);
122
123 QHeaderView::ResizeMode getHorizontalResizeMode() const;
124 void setHorizontalResizeMode(QHeaderView::ResizeMode mode);
125
126 QHeaderView::ResizeMode getVerticalResizeMode() const;
127 void setVerticalResizeMode(QHeaderView::ResizeMode mode);
128
129 int getDefaultCols() const;
130 void setDefaultCols(int value);
131
132 int getDefaultRows() const;
133 void setDefaultRows(int value);
134
135 QStringList getVerticalLabels() const;
136 void setVerticalLabels(QStringList value);
137
138 QStringList getHorizontalLabels() const;
139 void setHorizontalLabels(QStringList value);
140
141 QStringList getSuffixes() const;
142 void setSuffixes(QStringList value);
143
144 virtual QSize sizeHint() const;
145
146
147protected:
148 DataObjectModel *m_pModel;
149 DataObjectDelegate *m_pDelegate;
150
151 void createActions();
152 void restoreSelection(const QModelIndexList &indices);
153
154 void keyPressEvent(QKeyEvent *e);
155 void contextMenuEvent(QContextMenuEvent *event);
156
157 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
158
159
160
161private:
163 static QHash<DataObjectTable*, DataObjectTablePrivate*> PrivateHash;
164
165private slots:
166 inline void _activated (const QModelIndex &index) { emit activated(index.row(), index.column()); }
167 inline void _clicked (const QModelIndex &index) { emit clicked(index.row(), index.column()); }
168 inline void _doubleClicked (const QModelIndex &index) { emit doubleClicked(index.row(), index.column()); }
169 inline void _entered (const QModelIndex &index) { emit entered(index.row(), index.column()); }
170 inline void _pressed (const QModelIndex &index) { emit pressed(index.row(), index.column()); }
171 void copySelectionToClipboard();
172 void saveSelectionToCSV();
173 void setDecimalsGUI();
174 void configureHeatmap();
175 void numberFormatTriggered(QAction *a);
176 void heatmapTriggered(QAction *a);
177
178signals:
179 void activated (int row, int column);
180 void clicked (int row, int column);
181 void doubleClicked (int row, int column);
182 void entered (int row, int column);
183 void pressed (int row, int column);
184 void selectionInformationChanged(const QString &selectionInformation);
185};
Definition dataObjectDelegate.h:41
Definition dataObjectModel.h:47
Definition dataObjectTable.h:47
static QHash< DataObjectTable *, DataObjectTablePrivate * > PrivateHash
< todo: convert to classical private class if the addInInterface is incremented for the next time
Definition dataObjectTable.h:163
Definition dataObjectTable.cpp:52