QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgstableeditorwidget.h
Go to the documentation of this file.
1// This file is part of CppSheets.
2//
3// Copyright 2018 Patrick Flynn <[email protected]>
4//
5// CppSheets is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// CppSheets is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with CppSheets. If not, see <https://www.gnu.org/licenses/>.
17
18#ifndef QGSTABLEEDITORWIDGET_H
19#define QGSTABLEEDITORWIDGET_H
20
21#include "qgis_gui.h"
22#include "qgstablecell.h"
23#include "qgsproperty.h"
24#include <QTableWidget>
25#include <QPlainTextEdit>
26#include <QStyledItemDelegate>
27
28
29#ifndef SIP_RUN
31
32class QgsTableEditorTextEdit : public QPlainTextEdit
33{
34 Q_OBJECT
35 public:
36 QgsTableEditorTextEdit( QWidget *parent );
37
42 void setWeakEditorMode( bool weakEditorMode );
43
44 void setWidgetOwnsGeometry( bool value )
45 {
46 mWidgetOwnsGeometry = value;
47 }
48
49 public slots:
50
51 void resizeToContents();
52
53 protected:
54 void changeEvent( QEvent *e ) override;
55
56 void keyPressEvent( QKeyEvent *e ) override;
57
58 private:
59
60 void updateMinimumSize();
61
62 bool mWeakEditorMode = false;
63 int mOriginalWidth = -1;
64 int mOriginalHeight = -1;
65 bool mWidgetOwnsGeometry = false;
66
67};
68
69class QgsTableEditorDelegate : public QStyledItemDelegate
70{
71 Q_OBJECT
72 public:
73 QgsTableEditorDelegate( QObject *parent );
74
79 void setWeakEditorMode( bool weakEditorMode );
80
81 signals:
82
83 void updateNumericFormatForIndex( const QModelIndex &index ) const;
84
85 protected:
86 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override;
87 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
88 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
89
90 private:
91
92 bool mWeakEditorMode = false;
93 mutable QModelIndex mLastIndex;
94};
95
97
98#endif
99
111class GUI_EXPORT QgsTableEditorWidget : public QTableWidget
112{
113 Q_OBJECT
114 public:
115
119 QgsTableEditorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
120 ~QgsTableEditorWidget() override;
121
127 void setTableContents( const QgsTableContents &contents );
128
134 QgsTableContents tableContents() const;
135
143 void setSelectionNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
144
155 QgsNumericFormat *selectionNumericFormat();
156
162 bool hasMixedSelectionNumericFormat();
163
175 Q_DECL_DEPRECATED QColor selectionForegroundColor() SIP_DEPRECATED;
176
186 QColor selectionBackgroundColor();
187
196 Qt::Alignment selectionHorizontalAlignment();
197
206 Qt::Alignment selectionVerticalAlignment();
207
216 QgsProperty selectionCellProperty();
217
225 QgsTextFormat selectionTextFormat();
226
233 double selectionRowHeight();
234
241 double selectionColumnWidth();
242
247 double tableRowHeight( int row );
248
253 double tableColumnWidth( int column );
254
263 void setTableRowHeight( int row, double height );
264
273 void setTableColumnWidth( int column, double width );
274
280 QList<int> rowsAssociatedWithSelection();
281
287 QList<int> columnsAssociatedWithSelection();
288
294 QVariantList tableHeaders() const;
295
299 bool isHeaderCellSelected();
300
301 public slots:
302
308 void insertRowsBelow();
309
315 void insertRowsAbove();
316
322 void insertColumnsBefore();
323
329 void insertColumnsAfter();
330
336 void deleteRows();
337
343 void deleteColumns();
344
350 void expandRowSelection();
351
357 void expandColumnSelection();
358
362 void clearSelectedCells();
363
372 Q_DECL_DEPRECATED void setSelectionForegroundColor( const QColor &color ) SIP_DEPRECATED;
373
380 void setSelectionBackgroundColor( const QColor &color );
381
390 void setSelectionHorizontalAlignment( Qt::Alignment alignment );
391
400 void setSelectionVerticalAlignment( Qt::Alignment alignment );
401
407 void setSelectionCellProperty( const QgsProperty &property );
408
414 void setSelectionTextFormat( const QgsTextFormat &format );
415
421 void setSelectionRowHeight( double height );
422
428 void setSelectionColumnWidth( double height );
429
433 void setIncludeTableHeader( bool included );
434
440 void setTableHeaders( const QVariantList &headers );
441
442 protected:
443 void keyPressEvent( QKeyEvent *event ) override;
444
445 signals:
446
451
456
457 private slots:
458
459 void updateNumericFormatForIndex( const QModelIndex &index );
460
461 private:
462
464 enum Roles
465 {
466 PresetBackgroundColorRole = Qt::UserRole + 1,
467 RowHeight,
468 ColumnWidth,
469 CellContent,
470 TextFormat,
471 HorizontalAlignment,
472 VerticalAlignment,
473 CellProperty,
474 };
475
476 void updateHeaders();
477
478 bool collectConsecutiveRowRange( const QModelIndexList &list, int &minRow, int &maxRow ) const;
479 bool collectConsecutiveColumnRange( const QModelIndexList &list, int &minColumn, int &maxColumn ) const;
480 QList< int > collectUniqueRows( const QModelIndexList &list ) const;
481 QList< int > collectUniqueColumns( const QModelIndexList &list ) const;
482
483 int mBlockSignals = 0;
484 QHash< QTableWidgetItem *, QgsNumericFormat * > mNumericFormats;
485 QMenu *mHeaderMenu = nullptr;
486 bool mIncludeHeader = false;
487 bool mFirstSet = true;
488
489 friend class QgsTableEditorDelegate;
490
491};
492
493#endif // QGSTABLEEDITORWIDGET_H
A numeric formatter allows for formatting a numeric value for display, using a variety of different f...
A store for object properties.
A reusable widget for editing simple spreadsheet-style tables.
void activeCellChanged()
Emitted whenever the active (or selected) cell changes in the widget.
void tableChanged()
Emitted whenever the table contents are changed.
Container for all settings relating to text rendering.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
QVector< QgsTableRow > QgsTableContents
A set of table rows.