QGIS API Documentation 3.41.0-Master (3440c17df1d)
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() const;
300
306 bool canMergeSelection() const;
307
313 bool canSplitSelection() const;
314
315 public slots:
316
322 void insertRowsBelow();
323
329 void insertRowsAbove();
330
336 void insertColumnsBefore();
337
343 void insertColumnsAfter();
344
350 void deleteRows();
351
357 void deleteColumns();
358
364 void expandRowSelection();
365
371 void expandColumnSelection();
372
376 void clearSelectedCells();
377
386 Q_DECL_DEPRECATED void setSelectionForegroundColor( const QColor &color ) SIP_DEPRECATED;
387
394 void setSelectionBackgroundColor( const QColor &color );
395
404 void setSelectionHorizontalAlignment( Qt::Alignment alignment );
405
414 void setSelectionVerticalAlignment( Qt::Alignment alignment );
415
421 void setSelectionCellProperty( const QgsProperty &property );
422
428 void setSelectionTextFormat( const QgsTextFormat &format );
429
435 void setSelectionRowHeight( double height );
436
442 void setSelectionColumnWidth( double height );
443
447 void setIncludeTableHeader( bool included );
448
454 void setTableHeaders( const QVariantList &headers );
455
462 void mergeSelectedCells();
463
470 void splitSelectedCells();
471
472 protected:
473 void keyPressEvent( QKeyEvent *event ) override;
474
475 signals:
476
481
486
487 private slots:
488
489 void updateNumericFormatForIndex( const QModelIndex &index );
490
491 private:
492
494 enum Roles
495 {
496 PresetBackgroundColorRole = Qt::UserRole + 1,
497 RowHeight,
498 ColumnWidth,
499 CellContent,
500 TextFormat,
501 HorizontalAlignment,
502 VerticalAlignment,
503 CellProperty,
504 };
505
506 void updateHeaders();
507
508 bool collectConsecutiveRowRange( const QModelIndexList &list, int &minRow, int &maxRow ) const;
509 bool collectConsecutiveColumnRange( const QModelIndexList &list, int &minColumn, int &maxColumn ) const;
510 QList< int > collectUniqueRows( const QModelIndexList &list ) const;
511 QList< int > collectUniqueColumns( const QModelIndexList &list ) const;
512 bool isRectangularSelection( const QModelIndexList &list ) const;
513 bool hasMergedCells( const QModelIndexList &list ) const;
514
515 int mBlockSignals = 0;
516 QHash< QTableWidgetItem *, QgsNumericFormat * > mNumericFormats;
517 QMenu *mHeaderMenu = nullptr;
518 QMenu *mCellMenu = nullptr;
519 bool mIncludeHeader = false;
520 bool mFirstSet = true;
521
522 friend class QgsTableEditorDelegate;
523
524};
525
526#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.