QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgsproperty.h"
23#include "qgstablecell.h"
24
25#include <QPlainTextEdit>
26#include <QStyledItemDelegate>
27#include <QTableWidget>
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
131
140
152
159
171 Q_DECL_DEPRECATED QColor selectionForegroundColor() SIP_DEPRECATED;
172
183
192 Qt::Alignment selectionHorizontalAlignment();
193
202 Qt::Alignment selectionVerticalAlignment();
203
213
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
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
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
518};
519
520#endif // QGSTABLEEDITORWIDGET_H
Abstract base class for numeric formatters, which allow for formatting a numeric value for display.
A store for object properties.
void setSelectionVerticalAlignment(Qt::Alignment alignment)
Sets the vertical alignment for the currently selected cells.
Q_DECL_DEPRECATED void setSelectionForegroundColor(const QColor &color)
Sets the foreground color for the currently selected cells.
void splitSelectedCells()
Splits (un-merges) selected table cells.
QgsProperty selectionCellProperty()
Returns the QgsProperty used for the contents of the currently selected cells.
QVariantList tableHeaders() const
Returns the table header values.
void setSelectionTextFormat(const QgsTextFormat &format)
Sets the text format for the selected cells.
void setTableHeaders(const QVariantList &headers)
Sets the table headers.
void setSelectionBackgroundColor(const QColor &color)
Sets the background color for the currently selected cells.
void activeCellChanged()
Emitted whenever the active (or selected) cell changes in the widget.
Qt::Alignment selectionHorizontalAlignment()
Returns the horizontal alignment for the currently selected cells.
QgsTextFormat selectionTextFormat()
Returns the text format for the currently selected cells.
void insertColumnsAfter()
Inserts new columns after the current selection.
double selectionRowHeight()
Returns the height (in millimeters) of the rows associated with the current selection,...
void clearSelectedCells()
Clears the contents of the currently selected cells.
bool hasMixedSelectionNumericFormat()
Returns true if the current selection has a mix of numeric formats.
QList< int > rowsAssociatedWithSelection()
Returns a list of the rows associated with the current table selected cells.
QList< int > columnsAssociatedWithSelection()
Returns a list of the columns associated with the current table selected cells.
void deleteRows()
Deletes all rows associated with the current selected cells.
void setSelectionHorizontalAlignment(Qt::Alignment alignment)
Sets the horizontal alignment for the currently selected cells.
void setSelectionRowHeight(double height)
Sets the row height (in millimeters) for the currently selected rows, or 0 for automatic row height.
void insertRowsBelow()
Inserts new rows below the current selection.
double tableRowHeight(int row)
Returns the configured row height for the specified row, or 0 if an automatic height should be used f...
QColor selectionBackgroundColor()
Returns the background color for the currently selected cells.
QgsTableEditorWidget(QWidget *parent=nullptr)
Constructor for QgsTableEditorWidget with the specified parent widget.
bool canMergeSelection() const
Returns true if a selection has been made which can be merged.
Qt::Alignment selectionVerticalAlignment()
Returns the horizontal alignment for the currently selected cells.
void insertRowsAbove()
Inserts new rows above the current selection.
void setTableColumnWidth(int column, double width)
Sets the configured column width for the specified column.
void setSelectionCellProperty(const QgsProperty &property)
Sets the cell contents QgsProperty for the currently selected cells.
void setSelectionColumnWidth(double height)
Sets the column width (in millimeters) for the currently selected columns, or 0 for automatic column ...
double selectionColumnWidth()
Returns the width (in millimeters) of the columns associated with the current selection,...
bool canSplitSelection() const
Returns true if a selection has been made which can be split.
void expandRowSelection()
Expands out the selection to include whole rows associated with the current selected cells.
double tableColumnWidth(int column)
Returns the configured column width for the specified column, or 0 if an automatic width should be us...
void setIncludeTableHeader(bool included)
Sets whether the table includes a header row.
QgsNumericFormat * selectionNumericFormat()
Returns the numeric format used for the currently selected cells, or nullptr if the selection has no ...
void setTableRowHeight(int row, double height)
Sets the configured row height for the specified row.
void keyPressEvent(QKeyEvent *event) override
QgsTableContents tableContents() const
Returns the current contents of the editor widget table.
void deleteColumns()
Deletes all columns associated with the current selected cells.
bool isHeaderCellSelected() const
Returns true if any header cells are selected.
void setTableContents(const QgsTableContents &contents)
Sets the contents to show in the editor widget.
void tableChanged()
Emitted whenever the table contents are changed.
void insertColumnsBefore()
Inserts new columns before the current selection.
void mergeSelectedCells()
Merges selected table cells.
void setSelectionNumericFormat(QgsNumericFormat *format)
Sets the numeric format to use for the currently selected cells.
void expandColumnSelection()
Expands out the selection to include whole columns associated with the current selected cells.
Q_DECL_DEPRECATED QColor selectionForegroundColor()
Returns the foreground color for the currently selected cells.
Container for all settings relating to text rendering.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_TRANSFER
Definition qgis_sip.h:36
QVector< QgsTableRow > QgsTableContents
A set of table rows.