QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 void updateMinimumSize();
60
61 bool mWeakEditorMode = false;
62 int mOriginalWidth = -1;
63 int mOriginalHeight = -1;
64 bool mWidgetOwnsGeometry = false;
65};
66
67class QgsTableEditorDelegate : public QStyledItemDelegate
68{
69 Q_OBJECT
70 public:
71 QgsTableEditorDelegate( QObject *parent );
72
77 void setWeakEditorMode( bool weakEditorMode );
78
79 signals:
80
81 void updateNumericFormatForIndex( const QModelIndex &index ) const;
82
83 protected:
84 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override;
85 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
86 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
87
88 private:
89 bool mWeakEditorMode = false;
90 mutable QModelIndex mLastIndex;
91};
92
94
95#endif
96
108class GUI_EXPORT QgsTableEditorWidget : public QTableWidget
109{
110 Q_OBJECT
111 public:
115 QgsTableEditorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
116 ~QgsTableEditorWidget() override;
117
123 void setTableContents( const QgsTableContents &contents );
124
130 QgsTableContents tableContents() const;
131
139 void setSelectionNumericFormat( QgsNumericFormat *format SIP_TRANSFER );
140
151 QgsNumericFormat *selectionNumericFormat();
152
158 bool hasMixedSelectionNumericFormat();
159
171 Q_DECL_DEPRECATED QColor selectionForegroundColor() SIP_DEPRECATED;
172
182 QColor selectionBackgroundColor();
183
192 Qt::Alignment selectionHorizontalAlignment();
193
202 Qt::Alignment selectionVerticalAlignment();
203
212 QgsProperty selectionCellProperty();
213
221 QgsTextFormat selectionTextFormat();
222
229 double selectionRowHeight();
230
237 double selectionColumnWidth();
238
243 double tableRowHeight( int row );
244
249 double tableColumnWidth( int column );
250
259 void setTableRowHeight( int row, double height );
260
269 void setTableColumnWidth( int column, double width );
270
276 QList<int> rowsAssociatedWithSelection();
277
283 QList<int> columnsAssociatedWithSelection();
284
290 QVariantList tableHeaders() const;
291
295 bool isHeaderCellSelected() const;
296
302 bool canMergeSelection() const;
303
309 bool canSplitSelection() const;
310
311 public slots:
312
318 void insertRowsBelow();
319
325 void insertRowsAbove();
326
332 void insertColumnsBefore();
333
339 void insertColumnsAfter();
340
346 void deleteRows();
347
353 void deleteColumns();
354
360 void expandRowSelection();
361
367 void expandColumnSelection();
368
372 void clearSelectedCells();
373
382 Q_DECL_DEPRECATED void setSelectionForegroundColor( const QColor &color ) SIP_DEPRECATED;
383
390 void setSelectionBackgroundColor( const QColor &color );
391
400 void setSelectionHorizontalAlignment( Qt::Alignment alignment );
401
410 void setSelectionVerticalAlignment( Qt::Alignment alignment );
411
417 void setSelectionCellProperty( const QgsProperty &property );
418
424 void setSelectionTextFormat( const QgsTextFormat &format );
425
431 void setSelectionRowHeight( double height );
432
438 void setSelectionColumnWidth( double height );
439
443 void setIncludeTableHeader( bool included );
444
450 void setTableHeaders( const QVariantList &headers );
451
458 void mergeSelectedCells();
459
466 void splitSelectedCells();
467
468 protected:
469 void keyPressEvent( QKeyEvent *event ) override;
470
471 signals:
472
477
482
483 private slots:
484
485 void updateNumericFormatForIndex( const QModelIndex &index );
486
487 private:
489 enum Roles
490 {
491 PresetBackgroundColorRole = Qt::UserRole + 1,
492 RowHeight,
493 ColumnWidth,
494 CellContent,
495 TextFormat,
496 HorizontalAlignment,
497 VerticalAlignment,
498 CellProperty,
499 };
500
501 void updateHeaders();
502
503 bool collectConsecutiveRowRange( const QModelIndexList &list, int &minRow, int &maxRow ) const;
504 bool collectConsecutiveColumnRange( const QModelIndexList &list, int &minColumn, int &maxColumn ) const;
505 QList<int> collectUniqueRows( const QModelIndexList &list ) const;
506 QList<int> collectUniqueColumns( const QModelIndexList &list ) const;
507 bool isRectangularSelection( const QModelIndexList &list ) const;
508 bool hasMergedCells( const QModelIndexList &list ) const;
509
510 int mBlockSignals = 0;
511 QHash<QTableWidgetItem *, QgsNumericFormat *> mNumericFormats;
512 QMenu *mHeaderMenu = nullptr;
513 QMenu *mCellMenu = nullptr;
514 bool mIncludeHeader = false;
515 bool mFirstSet = true;
516
517 friend class QgsTableEditorDelegate;
518};
519
520#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.