Skip to content

Commit f76ed22

Browse files
committedNov 24, 2017
Port ui for attribute table
1 parent cca7c74 commit f76ed22

16 files changed

+4477
-4
lines changed
 

‎python/core/layout/qgslayoutmultiframe.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class QgsLayoutMultiFrame: QgsLayoutObject, QgsLayoutUndoObjectInterface
3636
UndoHtmlBreakDistance,
3737
UndoHtmlSource,
3838
UndoHtmlStylesheet,
39+
UndoTableCellStyle,
40+
UndoTableMaximumFeatures,
41+
UndoTableMargin,
42+
UndoTableHeaderFontColor,
43+
UndoTableContentFontColor,
44+
UndoTableGridStrokeWidth,
45+
UndoTableGridColor,
46+
UndoTableBackgroundColor,
3947
UndoNone,
4048
};
4149

‎python/core/layout/qgslayouttablecolumn.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212

13-
class QgsLayoutTableColumn
13+
class QgsLayoutTableColumn : QObject
1414
{
1515
%Docstring
1616
Stores properties of a column for a QgsLayoutTable. Some properties of aQgsLayoutTableColumn

‎src/app/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ SET(QGIS_APP_SRCS
178178

179179
layout/qgslayoutaddpagesdialog.cpp
180180
layout/qgslayoutapputils.cpp
181+
layout/qgslayoutattributeselectiondialog.cpp
182+
layout/qgslayoutattributetablewidget.cpp
181183
layout/qgslayoutdesignerdialog.cpp
182184
layout/qgslayoutguidewidget.cpp
183185
layout/qgslayouthtmlwidget.cpp
@@ -195,6 +197,7 @@ SET(QGIS_APP_SRCS
195197
layout/qgslayoutpropertieswidget.cpp
196198
layout/qgslayoutscalebarwidget.cpp
197199
layout/qgslayoutshapewidget.cpp
200+
layout/qgslayouttablebackgroundcolorsdialog.cpp
198201

199202
locator/qgsinbuiltlocatorfilters.cpp
200203
locator/qgslocatoroptionswidget.cpp
@@ -389,6 +392,8 @@ SET (QGIS_APP_MOC_HDRS
389392

390393
layout/qgslayoutaddpagesdialog.h
391394
layout/qgslayoutappmenuprovider.h
395+
layout/qgslayoutattributeselectiondialog.h
396+
layout/qgslayoutattributetablewidget.h
392397
layout/qgslayoutdesignerdialog.h
393398
layout/qgslayoutguidewidget.h
394399
layout/qgslayouthtmlwidget.h
@@ -405,6 +410,7 @@ SET (QGIS_APP_MOC_HDRS
405410
layout/qgslayoutpropertieswidget.h
406411
layout/qgslayoutscalebarwidget.h
407412
layout/qgslayoutshapewidget.h
413+
layout/qgslayouttablebackgroundcolorsdialog.h
408414

409415
locator/qgsinbuiltlocatorfilters.h
410416
locator/qgslocatoroptionswidget.h

‎src/app/layout/qgslayoutapputils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "qgslayouthtmlwidget.h"
4040
#include "qgslayoutscalebarwidget.h"
4141
#include "qgslayoutitemattributetable.h"
42+
#include "qgslayoutattributetablewidget.h"
4243
#include "qgisapp.h"
4344
#include "qgsmapcanvas.h"
4445

@@ -285,7 +286,7 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
285286
auto attributeTableItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutAttributeTable, QObject::tr( "Attribute Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddTable.svg" ) ),
286287
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
287288
{
288-
return nullptr; //new QgsLayoutHtmlWidget( qobject_cast< QgsLayoutFrame * >( item ) );
289+
return new QgsLayoutAttributeTableWidget( qobject_cast< QgsLayoutFrame * >( item ) );
289290
}, createRubberBand );
290291
attributeTableItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem*
291292
{

‎src/app/layout/qgslayoutattributeselectiondialog.cpp

Lines changed: 1073 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
/***************************************************************************
2+
qgslayoutattributeselectiondialog.h
3+
-----------------------------------
4+
begin : November 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSLAYOUTATTRIBUTESELECTIONDIALOG_H
19+
#define QGSLAYOUTATTRIBUTESELECTIONDIALOG_H
20+
21+
#include <QDialog>
22+
#include <QMap>
23+
#include <QSet>
24+
#include <QItemDelegate>
25+
#include <QAbstractTableModel>
26+
#include <QSortFilterProxyModel>
27+
#include "qgis.h"
28+
#include "ui_qgslayoutattributeselectiondialogbase.h"
29+
#include "qgsexpressioncontextgenerator.h"
30+
31+
class QGridLayout;
32+
class QgsVectorLayer;
33+
class QPushButton;
34+
class QgsLayoutItemAttributeTable;
35+
class QgsLayoutAttributeTableColumnModel;
36+
class QgsLayoutTableSortColumnsProxyModel;
37+
class QgsLayoutTableAvailableSortProxyModel;
38+
class QgsLayoutObject;
39+
class QgsLayoutTableColumn;
40+
41+
//QgsLayoutAttributeTableColumnModel
42+
43+
/**
44+
* A model for displaying columns shown in a QgsLayoutAttributeTable
45+
*/
46+
class QgsLayoutAttributeTableColumnModel: public QAbstractTableModel
47+
{
48+
Q_OBJECT
49+
50+
public:
51+
52+
/**
53+
* Controls whether a row/column is shifted up or down
54+
*/
55+
enum ShiftDirection
56+
{
57+
ShiftUp, //!< Shift the row/column up
58+
ShiftDown //!< Shift the row/column down
59+
};
60+
61+
/**
62+
* Constructor for QgsLayoutAttributeTableColumnModel.
63+
* \param table QgsLayoutItemAttributeTable the model is attached to
64+
* \param parent optional parent
65+
*/
66+
QgsLayoutAttributeTableColumnModel( QgsLayoutItemAttributeTable *table, QObject *parent SIP_TRANSFERTHIS = 0 );
67+
68+
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
69+
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
70+
virtual QVariant data( const QModelIndex &index, int role ) const override;
71+
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
72+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
73+
Qt::ItemFlags flags( const QModelIndex &index ) const override;
74+
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
75+
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
76+
QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
77+
QModelIndex parent( const QModelIndex &child ) const override;
78+
79+
/**
80+
* Moves the specified row up or down in the model. Used for rearranging the attribute tables
81+
* columns.
82+
* \returns true if the move is allowed
83+
* \param row row in model representing attribute table column to move
84+
* \param direction direction to move the attribute table column
85+
*/
86+
bool moveRow( int row, ShiftDirection direction );
87+
88+
/**
89+
* Resets the attribute table's columns to match the source layer's fields. Remove all existing
90+
* attribute table columns and column customisations.
91+
*/
92+
void resetToLayer();
93+
94+
/**
95+
* Returns the QgsLayoutTableColumn corresponding to an index in the model.
96+
* \see indexFromColumn()
97+
*/
98+
QgsLayoutTableColumn *columnFromIndex( const QModelIndex &index ) const;
99+
100+
/**
101+
* Returns a QModelIndex corresponding to a QgsLayoutTableColumn in the model.
102+
* \see columnFromIndex()
103+
*/
104+
QModelIndex indexFromColumn( QgsLayoutTableColumn *column );
105+
106+
/**
107+
* Sets a specified column as a sorted column in the QgsLayoutItemAttributeTable. The column will be
108+
* added to the end of the sort rank list, ie it will take the next largest available sort rank.
109+
* \see removeColumnFromSort()
110+
* \see moveColumnInSortRank()
111+
*/
112+
void setColumnAsSorted( QgsLayoutTableColumn *column, Qt::SortOrder order );
113+
114+
/**
115+
* Sets a specified column as an unsorted column in the QgsLayoutItemAttributeTable. The column will be
116+
* removed from the sort rank list.
117+
* \see setColumnAsSorted()
118+
*/
119+
void setColumnAsUnsorted( QgsLayoutTableColumn *column );
120+
121+
/**
122+
* Moves a column up or down in the sort rank for the QgsLayoutItemAttributeTable.
123+
* \see setColumnAsSorted()
124+
*/
125+
bool moveColumnInSortRank( QgsLayoutTableColumn *column, ShiftDirection direction );
126+
127+
private:
128+
QgsLayoutItemAttributeTable *mTable = nullptr;
129+
130+
};
131+
132+
133+
//QgsLayoutTableSortColumnsProxyModel
134+
135+
/**
136+
* Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted
137+
*/
138+
class QgsLayoutTableSortColumnsProxyModel: public QSortFilterProxyModel
139+
{
140+
Q_OBJECT
141+
142+
public:
143+
144+
/**
145+
* Controls whether the proxy model shows sorted or unsorted columns
146+
*/
147+
enum ColumnFilterType
148+
{
149+
ShowSortedColumns, //!< Show only sorted columns
150+
ShowUnsortedColumns//!< Show only unsorted columns
151+
};
152+
153+
/**
154+
* Constructor for QgsLayoutTableSortColumnsProxyModel.
155+
* \param table QgsLayoutItemAttributeTable the model is attached to
156+
* \param filterType filter for columns, controls whether sorted or unsorted columns are shown
157+
* \param parent optional parent
158+
*/
159+
QgsLayoutTableSortColumnsProxyModel( QgsLayoutItemAttributeTable *table, ColumnFilterType filterType, QObject *parent SIP_TRANSFERTHIS = 0 );
160+
161+
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
162+
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
163+
virtual QVariant data( const QModelIndex &index, int role ) const override;
164+
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
165+
Qt::ItemFlags flags( const QModelIndex &index ) const override;
166+
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
167+
168+
/**
169+
* Returns the QgsLayoutTableColumn corresponding to a row in the proxy model.
170+
* \see columnFromIndex()
171+
*/
172+
QgsLayoutTableColumn *columnFromRow( int row );
173+
174+
/**
175+
* Returns the QgsLayoutTableColumn corresponding to an index in the proxy model.
176+
* \see columnFromRow()
177+
* \see columnFromSourceIndex()
178+
*/
179+
QgsLayoutTableColumn *columnFromIndex( const QModelIndex &index ) const;
180+
181+
/**
182+
* Returns the QgsLayoutTableColumn corresponding to an index from the source
183+
* QgsLayoutItemAttributeTableColumnModel model.
184+
* \see columnFromRow()
185+
* \see columnFromIndex()
186+
*/
187+
QgsLayoutTableColumn *columnFromSourceIndex( const QModelIndex &sourceIndex ) const;
188+
189+
/**
190+
* Invalidates the current filter used by the proxy model
191+
*/
192+
void resetFilter();
193+
194+
protected:
195+
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
196+
197+
private:
198+
QgsLayoutItemAttributeTable *mTable = nullptr;
199+
ColumnFilterType mFilterType;
200+
201+
/**
202+
* Returns a list of QgsLayoutTableColumn without a set sort rank
203+
*/
204+
QList<QgsLayoutTableColumn *> columnsWithoutSortRank() const;
205+
206+
};
207+
208+
// QgsLayoutColumnAlignmentDelegate
209+
210+
//! A delegate for showing column alignment as a combo box
211+
class QgsLayoutColumnAlignmentDelegate : public QItemDelegate
212+
{
213+
Q_OBJECT
214+
215+
public:
216+
explicit QgsLayoutColumnAlignmentDelegate( QObject *parent = nullptr );
217+
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
218+
void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
219+
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
220+
void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
221+
222+
};
223+
224+
225+
// QgsLayoutColumnSourceDelegate
226+
227+
//! A delegate for showing column attribute source as a QgsFieldExpressionWidget
228+
class QgsLayoutColumnSourceDelegate : public QItemDelegate, private QgsExpressionContextGenerator
229+
{
230+
Q_OBJECT
231+
232+
public:
233+
QgsLayoutColumnSourceDelegate( QgsVectorLayer *vlayer, QObject *parent = nullptr, const QgsLayoutObject *layoutObject = nullptr );
234+
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
235+
void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
236+
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
237+
void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
238+
public slots:
239+
void commitAndCloseEditor();
240+
private:
241+
QgsVectorLayer *mVectorLayer = nullptr;
242+
const QgsLayoutObject *mLayoutObject = nullptr;
243+
QgsExpressionContext createExpressionContext() const override;
244+
};
245+
246+
// QgsLayoutColumnWidthDelegate
247+
248+
//! A delegate for showing column width as a spin box
249+
class QgsLayoutColumnWidthDelegate : public QItemDelegate
250+
{
251+
Q_OBJECT
252+
253+
public:
254+
explicit QgsLayoutColumnWidthDelegate( QObject *parent = nullptr );
255+
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
256+
void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
257+
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
258+
void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
259+
260+
};
261+
262+
263+
// QgsLayoutColumnSortOrderDelegate
264+
265+
//! A delegate for showing column sort order as a combo box
266+
class QgsLayoutColumnSortOrderDelegate : public QItemDelegate
267+
{
268+
Q_OBJECT
269+
270+
public:
271+
explicit QgsLayoutColumnSortOrderDelegate( QObject *parent = nullptr );
272+
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
273+
void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
274+
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
275+
void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
276+
277+
};
278+
279+
280+
// QgsLayoutAttributeSelectionDialog
281+
282+
//! A dialog to select what attributes to display (in the table item), set the column properties and specify a sort order
283+
class QgsLayoutAttributeSelectionDialog: public QDialog, private Ui::QgsLayoutAttributeSelectionDialogBase
284+
{
285+
Q_OBJECT
286+
public:
287+
QgsLayoutAttributeSelectionDialog( QgsLayoutItemAttributeTable *table, QgsVectorLayer *vLayer, QWidget *parent = nullptr, Qt::WindowFlags f = 0 );
288+
289+
~QgsLayoutAttributeSelectionDialog();
290+
291+
private slots:
292+
void mRemoveColumnPushButton_clicked();
293+
void mAddColumnPushButton_clicked();
294+
void mColumnUpPushButton_clicked();
295+
void mColumnDownPushButton_clicked();
296+
void mResetColumnsPushButton_clicked();
297+
void mClearColumnsPushButton_clicked();
298+
void mAddSortColumnPushButton_clicked();
299+
void mRemoveSortColumnPushButton_clicked();
300+
void mSortColumnUpPushButton_clicked();
301+
void mSortColumnDownPushButton_clicked();
302+
303+
private:
304+
QgsLayoutItemAttributeTable *mTable = nullptr;
305+
306+
const QgsVectorLayer *mVectorLayer = nullptr;
307+
308+
QgsLayoutAttributeTableColumnModel *mColumnModel = nullptr;
309+
310+
QgsLayoutTableSortColumnsProxyModel *mSortedProxyModel = nullptr;
311+
312+
QgsLayoutTableSortColumnsProxyModel *mAvailableSortProxyModel = nullptr;
313+
314+
QgsLayoutColumnAlignmentDelegate *mColumnAlignmentDelegate = nullptr;
315+
QgsLayoutColumnSourceDelegate *mColumnSourceDelegate = nullptr;
316+
QgsLayoutColumnSortOrderDelegate *mColumnSortOrderDelegate = nullptr;
317+
QgsLayoutColumnWidthDelegate *mColumnWidthDelegate = nullptr;
318+
319+
};
320+
321+
#endif // QGSLAYOUTATTRIBUTESELECTIONDIALOG_H

‎src/app/layout/qgslayoutattributetablewidget.cpp

Lines changed: 967 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/***************************************************************************
2+
qgslayoutattributetablewidget.h
3+
---------------------------------
4+
begin : November 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSLAYOUTATTRIBUTETABLEWIDGET_H
19+
#define QGSLAYOUTATTRIBUTETABLEWIDGET_H
20+
21+
#include "ui_qgslayoutattributetablewidgetbase.h"
22+
#include "qgslayoutitemwidget.h"
23+
24+
class QgsLayoutItemAttributeTable;
25+
class QgsLayoutFrame;
26+
27+
class QgsLayoutAttributeTableWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutAttributeTableWidgetBase
28+
{
29+
Q_OBJECT
30+
public:
31+
QgsLayoutAttributeTableWidget( QgsLayoutFrame *frame );
32+
33+
protected:
34+
35+
bool setNewItem( QgsLayoutItem *item ) override;
36+
37+
private:
38+
QgsLayoutItemAttributeTable *mTable = nullptr;
39+
QgsLayoutFrame *mFrame = nullptr;
40+
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
41+
42+
//! Blocks / unblocks the signals of all GUI elements
43+
void blockAllSignals( bool b );
44+
45+
void toggleSourceControls();
46+
47+
void toggleAtlasSpecificControls( const bool atlasEnabled );
48+
49+
private slots:
50+
void mRefreshPushButton_clicked();
51+
void mAttributesPushButton_clicked();
52+
void composerMapChanged( QgsLayoutItem *item );
53+
void mMaximumRowsSpinBox_valueChanged( int i );
54+
void mMarginSpinBox_valueChanged( double d );
55+
void mGridStrokeWidthSpinBox_valueChanged( double d );
56+
void mGridColorButton_colorChanged( const QColor &newColor );
57+
void mBackgroundColorButton_colorChanged( const QColor &newColor );
58+
void headerFontChanged();
59+
void mHeaderFontColorButton_colorChanged( const QColor &newColor );
60+
void contentFontChanged();
61+
void mContentFontColorButton_colorChanged( const QColor &newColor );
62+
void mDrawHorizontalGrid_toggled( bool state );
63+
void mDrawVerticalGrid_toggled( bool state );
64+
void mShowGridGroupCheckBox_toggled( bool state );
65+
void mShowOnlyVisibleFeaturesCheckBox_stateChanged( int state );
66+
void mFeatureFilterCheckBox_stateChanged( int state );
67+
void mFeatureFilterEdit_editingFinished();
68+
void mFeatureFilterButton_clicked();
69+
void mHeaderHAlignmentComboBox_currentIndexChanged( int index );
70+
void mHeaderModeComboBox_currentIndexChanged( int index );
71+
void mWrapStringLineEdit_editingFinished();
72+
void changeLayer( QgsMapLayer *layer );
73+
void mAddFramePushButton_clicked();
74+
void mResizeModeComboBox_currentIndexChanged( int index );
75+
void mSourceComboBox_currentIndexChanged( int index );
76+
void mRelationsComboBox_currentIndexChanged( int index );
77+
void mEmptyModeComboBox_currentIndexChanged( int index );
78+
void mDrawEmptyCheckBox_toggled( bool checked );
79+
void mEmptyMessageLineEdit_editingFinished();
80+
void mIntersectAtlasCheckBox_stateChanged( int state );
81+
void mUniqueOnlyCheckBox_stateChanged( int state );
82+
void mEmptyFrameCheckBox_toggled( bool checked );
83+
void mHideEmptyBgCheckBox_toggled( bool checked );
84+
void mWrapBehaviorComboBox_currentIndexChanged( int index );
85+
void mAdvancedCustomisationButton_clicked();
86+
87+
//! Inserts a new maximum number of features into the spin box (without the spinbox emitting a signal)
88+
void setMaximumNumberOfFeatures( int n );
89+
90+
//! Sets the GUI elements to the values of mComposerTable
91+
void updateGuiElements();
92+
93+
void atlasToggled();
94+
95+
void updateRelationsCombo();
96+
97+
};
98+
99+
#endif // QGSLAYOUTATTRIBUTETABLEWIDGET_H
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/***************************************************************************
2+
qgslayouttablebackgroundcolorsdialog.cpp
3+
----------------------------------------
4+
begin : November 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgslayouttablebackgroundcolorsdialog.h"
19+
#include "qgslayouttable.h"
20+
#include "qgslayout.h"
21+
#include "qgssettings.h"
22+
23+
#include <QCheckBox>
24+
#include <QPushButton>
25+
26+
QgsLayoutTableBackgroundColorsDialog::QgsLayoutTableBackgroundColorsDialog( QgsLayoutTable *table, QWidget *parent, Qt::WindowFlags flags )
27+
: QDialog( parent, flags )
28+
, mTable( table )
29+
{
30+
setupUi( this );
31+
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsLayoutTableBackgroundColorsDialog::buttonBox_accepted );
32+
connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsLayoutTableBackgroundColorsDialog::buttonBox_rejected );
33+
34+
mCheckBoxMap.insert( QgsLayoutTable::OddColumns, mOddColumnsCheckBox );
35+
mCheckBoxMap.insert( QgsLayoutTable::EvenColumns, mEvenColumnsCheckBox );
36+
mCheckBoxMap.insert( QgsLayoutTable::OddRows, mOddRowsCheckBox );
37+
mCheckBoxMap.insert( QgsLayoutTable::EvenRows, mEvenRowsCheckBox );
38+
mCheckBoxMap.insert( QgsLayoutTable::FirstColumn, mFirstColumnCheckBox );
39+
mCheckBoxMap.insert( QgsLayoutTable::LastColumn, mLastColumnCheckBox );
40+
mCheckBoxMap.insert( QgsLayoutTable::HeaderRow, mHeaderRowCheckBox );
41+
mCheckBoxMap.insert( QgsLayoutTable::FirstRow, mFirstRowCheckBox );
42+
mCheckBoxMap.insert( QgsLayoutTable::LastRow, mLastRowCheckBox );
43+
44+
mColorButtonMap.insert( QgsLayoutTable::OddColumns, mOddColumnsColorButton );
45+
mColorButtonMap.insert( QgsLayoutTable::EvenColumns, mEvenColumnsColorButton );
46+
mColorButtonMap.insert( QgsLayoutTable::OddRows, mOddRowsColorButton );
47+
mColorButtonMap.insert( QgsLayoutTable::EvenRows, mEvenRowsColorButton );
48+
mColorButtonMap.insert( QgsLayoutTable::FirstColumn, mFirstColumnColorButton );
49+
mColorButtonMap.insert( QgsLayoutTable::LastColumn, mLastColumnColorButton );
50+
mColorButtonMap.insert( QgsLayoutTable::HeaderRow, mHeaderRowColorButton );
51+
mColorButtonMap.insert( QgsLayoutTable::FirstRow, mFirstRowColorButton );
52+
mColorButtonMap.insert( QgsLayoutTable::LastRow, mLastRowColorButton );
53+
54+
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsLayoutTableBackgroundColorsDialog::apply );
55+
56+
QgsSettings settings;
57+
restoreGeometry( settings.value( QStringLiteral( "Windows/ComposerTableBackgroundColorsDialog/geometry" ) ).toByteArray() );
58+
59+
setGuiElementValues();
60+
}
61+
62+
QgsLayoutTableBackgroundColorsDialog::~QgsLayoutTableBackgroundColorsDialog()
63+
{
64+
QgsSettings settings;
65+
settings.setValue( QStringLiteral( "Windows/ComposerTableBackgroundColorsDialog/geometry" ), saveGeometry() );
66+
}
67+
68+
void QgsLayoutTableBackgroundColorsDialog::apply()
69+
{
70+
if ( !mTable )
71+
return;
72+
73+
mTable->beginCommand( tr( "Change Table Background" ), QgsLayoutMultiFrame::UndoTableCellStyle );
74+
for ( auto checkBoxIt = mCheckBoxMap.constBegin(); checkBoxIt != mCheckBoxMap.constEnd(); ++checkBoxIt )
75+
{
76+
QgsLayoutTableStyle style;
77+
style.enabled = checkBoxIt.value()->isChecked();
78+
if ( QgsColorButton *button = mColorButtonMap.value( checkBoxIt.key() ) )
79+
style.cellBackgroundColor = button->color();
80+
81+
mTable->setCellStyle( checkBoxIt.key(), style );
82+
}
83+
84+
mTable->setBackgroundColor( mDefaultColorButton->color() );
85+
mTable->endCommand();
86+
mTable->update();
87+
}
88+
89+
void QgsLayoutTableBackgroundColorsDialog::buttonBox_accepted()
90+
{
91+
apply();
92+
accept();
93+
}
94+
95+
void QgsLayoutTableBackgroundColorsDialog::buttonBox_rejected()
96+
{
97+
reject();
98+
}
99+
100+
void QgsLayoutTableBackgroundColorsDialog::setGuiElementValues()
101+
{
102+
if ( !mTable )
103+
return;
104+
105+
for ( auto it = mCheckBoxMap.constBegin(); it != mCheckBoxMap.constEnd(); ++it )
106+
{
107+
it.value()->setChecked( mTable->cellStyle( it.key() )->enabled );
108+
QgsColorButton *button = mColorButtonMap.value( it.key() );
109+
if ( !button )
110+
continue;
111+
button->setEnabled( mTable->cellStyle( it.key() )->enabled );
112+
button->setColor( mTable->cellStyle( it.key() )->cellBackgroundColor );
113+
button->setAllowOpacity( true );
114+
button->setColorDialogTitle( tr( "Select Background Color" ) );
115+
}
116+
117+
mDefaultColorButton->setColor( mTable->backgroundColor() );
118+
mDefaultColorButton->setAllowOpacity( true );
119+
mDefaultColorButton->setColorDialogTitle( tr( "Select Background Color" ) );
120+
mDefaultColorButton->setShowNoColor( true );
121+
mDefaultColorButton->setNoColorString( tr( "No background" ) );
122+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/***************************************************************************
2+
qgslayouttablebackgroundcolorsdialog.h
3+
----------------------------------------
4+
begin : November 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSLAYOUTTABLEBACKGROUNDCOLORSDIALOG_H
19+
#define QGSLAYOUTTABLEBACKGROUNDCOLORSDIALOG_H
20+
21+
#include <QDialog>
22+
#include "ui_qgslayouttablebackgroundstyles.h"
23+
#include "qgslayouttable.h"
24+
25+
class QCheckBox;
26+
class QgsColorButton;
27+
28+
/**
29+
* A dialog for customisation of the cell background colors for a QgsLayoutTable
30+
* \since QGIS 3.0
31+
*/
32+
class QgsLayoutTableBackgroundColorsDialog: public QDialog, private Ui::QgsLayoutTableBackgroundDialog
33+
{
34+
Q_OBJECT
35+
public:
36+
37+
/**
38+
* Constructor for QgsLayoutTableBackgroundColorsDialog
39+
* \param table associated layout table
40+
* \param parent parent widget
41+
* \param flags window flags
42+
*/
43+
QgsLayoutTableBackgroundColorsDialog( QgsLayoutTable *table, QWidget *parent = nullptr, Qt::WindowFlags flags = 0 );
44+
45+
~QgsLayoutTableBackgroundColorsDialog();
46+
47+
private slots:
48+
49+
void apply();
50+
51+
void buttonBox_accepted();
52+
void buttonBox_rejected();
53+
54+
private:
55+
56+
QgsLayoutTable *mTable = nullptr;
57+
QMap< QgsLayoutTable::CellStyleGroup, QCheckBox * > mCheckBoxMap;
58+
QMap< QgsLayoutTable::CellStyleGroup, QgsColorButton * > mColorButtonMap;
59+
60+
61+
//! Sets the GUI elements to the values of the table
62+
void setGuiElementValues();
63+
64+
65+
};
66+
67+
#endif // QGSLAYOUTTABLEBACKGROUNDCOLORSDIALOG_H

‎src/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ SET(QGIS_CORE_MOC_HDRS
764764
layout/qgslayoutpagecollection.h
765765
layout/qgslayoutobject.h
766766
layout/qgslayouttable.h
767+
layout/qgslayouttablecolumn.h
767768
layout/qgslayoutundostack.h
768769

769770
symbology/qgscptcityarchive.h
@@ -1028,7 +1029,6 @@ SET(QGIS_CORE_HDRS
10281029
layout/qgslayoutserializableobject.h
10291030
layout/qgslayoutsize.h
10301031
layout/qgslayoutsnapper.h
1031-
layout/qgslayouttablecolumn.h
10321032
layout/qgslayoutundocommand.h
10331033
layout/qgslayoututils.h
10341034

‎src/core/layout/qgslayoutmultiframe.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class CORE_EXPORT QgsLayoutMultiFrame: public QgsLayoutObject, public QgsLayoutU
6767
UndoHtmlBreakDistance, //!< HTML page break distance
6868
UndoHtmlSource, //!< HTML source
6969
UndoHtmlStylesheet, //!< HTML stylesheet
70+
UndoTableCellStyle, //!< Table cell style
71+
UndoTableMaximumFeatures, //!< Maximum features in table
72+
UndoTableMargin, //!< Table margins
73+
UndoTableHeaderFontColor, //!< Table header font color
74+
UndoTableContentFontColor, //!< Table content font color
75+
UndoTableGridStrokeWidth, //!< Table grid stroke width
76+
UndoTableGridColor, //!< Table grid color
77+
UndoTableBackgroundColor, //!< Table background color
7078
UndoNone = -1, //!< No command suppression
7179
};
7280

‎src/core/layout/qgslayouttablecolumn.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
* have an effect for QgsLayoutItemAttributeTables, and have no effect for QgsLayoutItemTextTables.
3434
* \since QGIS 3.0
3535
*/
36-
class CORE_EXPORT QgsLayoutTableColumn
36+
class CORE_EXPORT QgsLayoutTableColumn : public QObject
3737
{
38+
Q_OBJECT
39+
3840
public:
3941

4042
/**
Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsLayoutAttributeSelectionDialogBase</class>
4+
<widget class="QDialog" name="QgsLayoutAttributeSelectionDialogBase">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>517</width>
10+
<height>729</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Select Attributes</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout_2">
17+
<item row="0" column="0">
18+
<widget class="QSplitter" name="splitter">
19+
<property name="orientation">
20+
<enum>Qt::Vertical</enum>
21+
</property>
22+
<widget class="QGroupBox" name="mAttributesGroupBox">
23+
<property name="title">
24+
<string>Columns</string>
25+
</property>
26+
<layout class="QGridLayout" name="gridLayout">
27+
<item row="1" column="0">
28+
<layout class="QHBoxLayout" name="horizontalLayout_2">
29+
<item>
30+
<widget class="QPushButton" name="mColumnUpPushButton">
31+
<property name="text">
32+
<string/>
33+
</property>
34+
<property name="icon">
35+
<iconset resource="../../../images/images.qrc">
36+
<normaloff>:/images/themes/default/mActionArrowUp.svg</normaloff>:/images/themes/default/mActionArrowUp.svg</iconset>
37+
</property>
38+
</widget>
39+
</item>
40+
<item>
41+
<widget class="QPushButton" name="mColumnDownPushButton">
42+
<property name="text">
43+
<string/>
44+
</property>
45+
<property name="icon">
46+
<iconset resource="../../../images/images.qrc">
47+
<normaloff>:/images/themes/default/mActionArrowDown.svg</normaloff>:/images/themes/default/mActionArrowDown.svg</iconset>
48+
</property>
49+
</widget>
50+
</item>
51+
<item>
52+
<widget class="QPushButton" name="mAddColumnPushButton">
53+
<property name="text">
54+
<string/>
55+
</property>
56+
<property name="icon">
57+
<iconset resource="../../../images/images.qrc">
58+
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
59+
</property>
60+
</widget>
61+
</item>
62+
<item>
63+
<widget class="QPushButton" name="mRemoveColumnPushButton">
64+
<property name="text">
65+
<string/>
66+
</property>
67+
<property name="icon">
68+
<iconset resource="../../../images/images.qrc">
69+
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
70+
</property>
71+
</widget>
72+
</item>
73+
<item>
74+
<widget class="QPushButton" name="mResetColumnsPushButton">
75+
<property name="text">
76+
<string>Reset</string>
77+
</property>
78+
</widget>
79+
</item>
80+
<item>
81+
<widget class="QPushButton" name="mClearColumnsPushButton">
82+
<property name="text">
83+
<string>Clear</string>
84+
</property>
85+
</widget>
86+
</item>
87+
</layout>
88+
</item>
89+
<item row="1" column="1">
90+
<spacer name="horizontalSpacer">
91+
<property name="orientation">
92+
<enum>Qt::Horizontal</enum>
93+
</property>
94+
<property name="sizeHint" stdset="0">
95+
<size>
96+
<width>77</width>
97+
<height>20</height>
98+
</size>
99+
</property>
100+
</spacer>
101+
</item>
102+
<item row="0" column="0" colspan="2">
103+
<widget class="QTableView" name="mColumnsTableView">
104+
<property name="editTriggers">
105+
<set>QAbstractItemView::AllEditTriggers</set>
106+
</property>
107+
<property name="showDropIndicator" stdset="0">
108+
<bool>false</bool>
109+
</property>
110+
<property name="dragEnabled">
111+
<bool>false</bool>
112+
</property>
113+
<property name="dragDropOverwriteMode">
114+
<bool>false</bool>
115+
</property>
116+
<property name="dragDropMode">
117+
<enum>QAbstractItemView::NoDragDrop</enum>
118+
</property>
119+
<property name="defaultDropAction">
120+
<enum>Qt::IgnoreAction</enum>
121+
</property>
122+
<property name="selectionMode">
123+
<enum>QAbstractItemView::MultiSelection</enum>
124+
</property>
125+
<property name="selectionBehavior">
126+
<enum>QAbstractItemView::SelectRows</enum>
127+
</property>
128+
<property name="wordWrap">
129+
<bool>false</bool>
130+
</property>
131+
<property name="cornerButtonEnabled">
132+
<bool>false</bool>
133+
</property>
134+
</widget>
135+
</item>
136+
</layout>
137+
</widget>
138+
<widget class="QGroupBox" name="mSortingGroupBox">
139+
<property name="title">
140+
<string>Sorting</string>
141+
</property>
142+
<layout class="QGridLayout" name="gridLayout_3">
143+
<item row="0" column="0">
144+
<layout class="QHBoxLayout" name="horizontalLayout_3">
145+
<item>
146+
<widget class="QComboBox" name="mSortColumnComboBox">
147+
<property name="minimumSize">
148+
<size>
149+
<width>180</width>
150+
<height>0</height>
151+
</size>
152+
</property>
153+
</widget>
154+
</item>
155+
<item>
156+
<widget class="QComboBox" name="mOrderComboBox">
157+
<property name="minimumSize">
158+
<size>
159+
<width>100</width>
160+
<height>0</height>
161+
</size>
162+
</property>
163+
</widget>
164+
</item>
165+
<item>
166+
<widget class="QPushButton" name="mAddSortColumnPushButton">
167+
<property name="maximumSize">
168+
<size>
169+
<width>16777215</width>
170+
<height>16777215</height>
171+
</size>
172+
</property>
173+
<property name="text">
174+
<string/>
175+
</property>
176+
<property name="icon">
177+
<iconset resource="../../../images/images.qrc">
178+
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
179+
</property>
180+
</widget>
181+
</item>
182+
</layout>
183+
</item>
184+
<item row="2" column="0">
185+
<layout class="QHBoxLayout" name="horizontalLayout">
186+
<item>
187+
<widget class="QPushButton" name="mSortColumnUpPushButton">
188+
<property name="text">
189+
<string/>
190+
</property>
191+
<property name="icon">
192+
<iconset resource="../../../images/images.qrc">
193+
<normaloff>:/images/themes/default/mActionArrowUp.svg</normaloff>:/images/themes/default/mActionArrowUp.svg</iconset>
194+
</property>
195+
</widget>
196+
</item>
197+
<item>
198+
<widget class="QPushButton" name="mSortColumnDownPushButton">
199+
<property name="text">
200+
<string/>
201+
</property>
202+
<property name="icon">
203+
<iconset resource="../../../images/images.qrc">
204+
<normaloff>:/images/themes/default/mActionArrowDown.svg</normaloff>:/images/themes/default/mActionArrowDown.svg</iconset>
205+
</property>
206+
</widget>
207+
</item>
208+
<item>
209+
<widget class="QPushButton" name="mRemoveSortColumnPushButton">
210+
<property name="text">
211+
<string/>
212+
</property>
213+
<property name="icon">
214+
<iconset resource="../../../images/images.qrc">
215+
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
216+
</property>
217+
</widget>
218+
</item>
219+
<item>
220+
<spacer name="horizontalSpacer_2">
221+
<property name="orientation">
222+
<enum>Qt::Horizontal</enum>
223+
</property>
224+
<property name="sizeHint" stdset="0">
225+
<size>
226+
<width>40</width>
227+
<height>20</height>
228+
</size>
229+
</property>
230+
</spacer>
231+
</item>
232+
</layout>
233+
</item>
234+
<item row="1" column="0">
235+
<widget class="QTableView" name="mSortColumnTableView">
236+
<property name="editTriggers">
237+
<set>QAbstractItemView::AllEditTriggers</set>
238+
</property>
239+
<property name="selectionMode">
240+
<enum>QAbstractItemView::SingleSelection</enum>
241+
</property>
242+
<property name="selectionBehavior">
243+
<enum>QAbstractItemView::SelectRows</enum>
244+
</property>
245+
</widget>
246+
</item>
247+
</layout>
248+
</widget>
249+
</widget>
250+
</item>
251+
<item row="1" column="0">
252+
<widget class="QDialogButtonBox" name="buttonBox">
253+
<property name="orientation">
254+
<enum>Qt::Horizontal</enum>
255+
</property>
256+
<property name="standardButtons">
257+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
258+
</property>
259+
</widget>
260+
</item>
261+
</layout>
262+
</widget>
263+
<tabstops>
264+
<tabstop>mColumnsTableView</tabstop>
265+
<tabstop>mColumnUpPushButton</tabstop>
266+
<tabstop>mColumnDownPushButton</tabstop>
267+
<tabstop>mAddColumnPushButton</tabstop>
268+
<tabstop>mRemoveColumnPushButton</tabstop>
269+
<tabstop>mResetColumnsPushButton</tabstop>
270+
<tabstop>mSortColumnComboBox</tabstop>
271+
<tabstop>mOrderComboBox</tabstop>
272+
<tabstop>mAddSortColumnPushButton</tabstop>
273+
<tabstop>mSortColumnTableView</tabstop>
274+
<tabstop>mSortColumnUpPushButton</tabstop>
275+
<tabstop>mSortColumnDownPushButton</tabstop>
276+
<tabstop>mRemoveSortColumnPushButton</tabstop>
277+
<tabstop>buttonBox</tabstop>
278+
</tabstops>
279+
<resources>
280+
<include location="../../../images/images.qrc"/>
281+
<include location="../../../images/images.qrc"/>
282+
<include location="../../../images/images.qrc"/>
283+
<include location="../../../images/images.qrc"/>
284+
<include location="../../../images/images.qrc"/>
285+
<include location="../../../images/images.qrc"/>
286+
<include location="../../../images/images.qrc"/>
287+
<include location="../../../images/images.qrc"/>
288+
<include location="../../../images/images.qrc"/>
289+
<include location="../../../images/images.qrc"/>
290+
<include location="../../../images/images.qrc"/>
291+
<include location="../../../images/images.qrc"/>
292+
<include location="../../../images/images.qrc"/>
293+
<include location="../../../images/images.qrc"/>
294+
<include location="../../../images/images.qrc"/>
295+
<include location="../../../images/images.qrc"/>
296+
<include location="../../../images/images.qrc"/>
297+
<include location="../../../images/images.qrc"/>
298+
<include location="../../../images/images.qrc"/>
299+
<include location="../../../images/images.qrc"/>
300+
<include location="../../../images/images.qrc"/>
301+
<include location="../../../images/images.qrc"/>
302+
<include location="../../../images/images.qrc"/>
303+
<include location="../../../images/images.qrc"/>
304+
<include location="../../../images/images.qrc"/>
305+
<include location="../../../images/images.qrc"/>
306+
<include location="../../../images/images.qrc"/>
307+
</resources>
308+
<connections>
309+
<connection>
310+
<sender>buttonBox</sender>
311+
<signal>accepted()</signal>
312+
<receiver>QgsLayoutAttributeSelectionDialogBase</receiver>
313+
<slot>accept()</slot>
314+
<hints>
315+
<hint type="sourcelabel">
316+
<x>248</x>
317+
<y>254</y>
318+
</hint>
319+
<hint type="destinationlabel">
320+
<x>157</x>
321+
<y>274</y>
322+
</hint>
323+
</hints>
324+
</connection>
325+
<connection>
326+
<sender>buttonBox</sender>
327+
<signal>rejected()</signal>
328+
<receiver>QgsLayoutAttributeSelectionDialogBase</receiver>
329+
<slot>reject()</slot>
330+
<hints>
331+
<hint type="sourcelabel">
332+
<x>316</x>
333+
<y>260</y>
334+
</hint>
335+
<hint type="destinationlabel">
336+
<x>286</x>
337+
<y>274</y>
338+
</hint>
339+
</hints>
340+
</connection>
341+
</connections>
342+
</ui>

‎src/ui/layout/qgslayoutattributetablewidgetbase.ui

Lines changed: 910 additions & 0 deletions
Large diffs are not rendered by default.

‎src/ui/layout/qgslayouttablebackgroundstyles.ui

Lines changed: 547 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.