QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 ) { mWidgetOwnsGeometry = value; }
45
46 public slots:
47
48 void resizeToContents();
49
50 protected:
51 void changeEvent( QEvent *e ) override;
52
53 void keyPressEvent( QKeyEvent *e ) override;
54
55 private:
56 void updateMinimumSize();
57
58 bool mWeakEditorMode = false;
59 int mOriginalWidth = -1;
60 int mOriginalHeight = -1;
61 bool mWidgetOwnsGeometry = false;
62};
63
64class QgsTableEditorDelegate : public QStyledItemDelegate
65{
66 Q_OBJECT
67 public:
68 QgsTableEditorDelegate( QObject *parent );
69
74 void setWeakEditorMode( bool weakEditorMode );
75
76 signals:
77
78 void updateNumericFormatForIndex( const QModelIndex &index ) const;
79
80 protected:
81 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override;
82 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
83 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
84
85 private:
86 bool mWeakEditorMode = false;
87 mutable QModelIndex mLastIndex;
88};
89
91
92#endif
93
105class GUI_EXPORT QgsTableEditorWidget : public QTableWidget
106{
107 Q_OBJECT
108 public:
112 QgsTableEditorWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
113 ~QgsTableEditorWidget() override;
114
120 void setTableContents( const QgsTableContents &contents );
121
128
137
149
156
168 Q_DECL_DEPRECATED QColor selectionForegroundColor() SIP_DEPRECATED;
169
180
189 Qt::Alignment selectionHorizontalAlignment();
190
199 Qt::Alignment selectionVerticalAlignment();
200
210
219
226 double selectionRowHeight();
227
234 double selectionColumnWidth();
235
240 double tableRowHeight( int row );
241
246 double tableColumnWidth( int column );
247
256 void setTableRowHeight( int row, double height );
257
266 void setTableColumnWidth( int column, double width );
267
273 QList<int> rowsAssociatedWithSelection();
274
281
287 QVariantList tableHeaders() const;
288
292 bool isHeaderCellSelected() const;
293
299 bool canMergeSelection() const;
300
306 bool canSplitSelection() const;
307
308 public slots:
309
315 void insertRowsBelow();
316
322 void insertRowsAbove();
323
329 void insertColumnsBefore();
330
336 void insertColumnsAfter();
337
343 void deleteRows();
344
350 void deleteColumns();
351
357 void expandRowSelection();
358
365
369 void clearSelectedCells();
370
379 Q_DECL_DEPRECATED void setSelectionForegroundColor( const QColor &color ) SIP_DEPRECATED;
380
387 void setSelectionBackgroundColor( const QColor &color );
388
397 void setSelectionHorizontalAlignment( Qt::Alignment alignment );
398
407 void setSelectionVerticalAlignment( Qt::Alignment alignment );
408
414 void setSelectionCellProperty( const QgsProperty &property );
415
421 void setSelectionTextFormat( const QgsTextFormat &format );
422
428 void setSelectionRowHeight( double height );
429
435 void setSelectionColumnWidth( double height );
436
440 void setIncludeTableHeader( bool included );
441
447 void setTableHeaders( const QVariantList &headers );
448
455 void mergeSelectedCells();
456
463 void splitSelectedCells();
464
465 protected:
466 void keyPressEvent( QKeyEvent *event ) override;
467
468 signals:
469
474
479
480 private slots:
481
482 void updateNumericFormatForIndex( const QModelIndex &index );
483
484 private:
486 enum Roles
487 {
488 PresetBackgroundColorRole = Qt::UserRole + 1,
489 RowHeight,
490 ColumnWidth,
491 CellContent,
492 TextFormat,
493 HorizontalAlignment,
494 VerticalAlignment,
495 CellProperty,
496 };
497
498 void updateHeaders();
499
500 bool collectConsecutiveRowRange( const QModelIndexList &list, int &minRow, int &maxRow ) const;
501 bool collectConsecutiveColumnRange( const QModelIndexList &list, int &minColumn, int &maxColumn ) const;
502 QList<int> collectUniqueRows( const QModelIndexList &list ) const;
503 QList<int> collectUniqueColumns( const QModelIndexList &list ) const;
504 bool isRectangularSelection( const QModelIndexList &list ) const;
505 bool hasMergedCells( const QModelIndexList &list ) const;
506
507 int mBlockSignals = 0;
508 QHash<QTableWidgetItem *, QgsNumericFormat *> mNumericFormats;
509 QMenu *mHeaderMenu = nullptr;
510 QMenu *mCellMenu = nullptr;
511 bool mIncludeHeader = false;
512 bool mFirstSet = true;
513
515};
516
517#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:113
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_TRANSFER
Definition qgis_sip.h:35
QVector< QgsTableRow > QgsTableContents
A set of table rows.