QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgslayouttablebackgroundcolorsdialog.cpp
Go to the documentation of this file.
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
19
20#include "qgsgui.h"
21#include "qgshelp.h"
22#include "qgslayout.h"
23#include "qgslayouttable.h"
24#include "qgssettings.h"
25
26#include <QCheckBox>
27#include <QPushButton>
28
29#include "moc_qgslayouttablebackgroundcolorsdialog.cpp"
30
32 : QDialog( parent, flags )
33 , mTable( table )
34{
35 setupUi( this );
37
38 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsLayoutTableBackgroundColorsDialog::buttonBox_accepted );
39 connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsLayoutTableBackgroundColorsDialog::buttonBox_rejected );
40 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutTableBackgroundColorsDialog::showHelp );
41
42 mCheckBoxMap.insert( QgsLayoutTable::OddColumns, mOddColumnsCheckBox );
43 mCheckBoxMap.insert( QgsLayoutTable::EvenColumns, mEvenColumnsCheckBox );
44 mCheckBoxMap.insert( QgsLayoutTable::OddRows, mOddRowsCheckBox );
45 mCheckBoxMap.insert( QgsLayoutTable::EvenRows, mEvenRowsCheckBox );
46 mCheckBoxMap.insert( QgsLayoutTable::FirstColumn, mFirstColumnCheckBox );
47 mCheckBoxMap.insert( QgsLayoutTable::LastColumn, mLastColumnCheckBox );
48 mCheckBoxMap.insert( QgsLayoutTable::HeaderRow, mHeaderRowCheckBox );
49 mCheckBoxMap.insert( QgsLayoutTable::FirstRow, mFirstRowCheckBox );
50 mCheckBoxMap.insert( QgsLayoutTable::LastRow, mLastRowCheckBox );
51
52 mColorButtonMap.insert( QgsLayoutTable::OddColumns, mOddColumnsColorButton );
53 mColorButtonMap.insert( QgsLayoutTable::EvenColumns, mEvenColumnsColorButton );
54 mColorButtonMap.insert( QgsLayoutTable::OddRows, mOddRowsColorButton );
55 mColorButtonMap.insert( QgsLayoutTable::EvenRows, mEvenRowsColorButton );
56 mColorButtonMap.insert( QgsLayoutTable::FirstColumn, mFirstColumnColorButton );
57 mColorButtonMap.insert( QgsLayoutTable::LastColumn, mLastColumnColorButton );
58 mColorButtonMap.insert( QgsLayoutTable::HeaderRow, mHeaderRowColorButton );
59 mColorButtonMap.insert( QgsLayoutTable::FirstRow, mFirstRowColorButton );
60 mColorButtonMap.insert( QgsLayoutTable::LastRow, mLastRowColorButton );
61
62 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsLayoutTableBackgroundColorsDialog::apply );
63
64 setGuiElementValues();
65}
66
67void QgsLayoutTableBackgroundColorsDialog::apply()
68{
69 if ( !mTable )
70 return;
71
72 mTable->beginCommand( tr( "Change Table Background" ), QgsLayoutMultiFrame::UndoTableCellStyle );
73 for ( auto checkBoxIt = mCheckBoxMap.constBegin(); checkBoxIt != mCheckBoxMap.constEnd(); ++checkBoxIt )
74 {
76 style.enabled = checkBoxIt.value()->isChecked();
77 if ( QgsColorButton *button = mColorButtonMap.value( checkBoxIt.key() ) )
78 style.cellBackgroundColor = button->color();
79
80 mTable->setCellStyle( checkBoxIt.key(), style );
81 }
82
83 mTable->setBackgroundColor( mDefaultColorButton->color() );
84 mTable->endCommand();
85 mTable->update();
86}
87
88void QgsLayoutTableBackgroundColorsDialog::buttonBox_accepted()
89{
90 apply();
91 accept();
92}
93
94void QgsLayoutTableBackgroundColorsDialog::buttonBox_rejected()
95{
96 reject();
97}
98
99void QgsLayoutTableBackgroundColorsDialog::showHelp()
100{
101 QgsHelp::openHelp( QStringLiteral( "print_composer/composer_items/composer_attribute_table.html#appearance" ) );
102}
103
104void QgsLayoutTableBackgroundColorsDialog::setGuiElementValues()
105{
106 if ( !mTable )
107 return;
108
109 for ( auto it = mCheckBoxMap.constBegin(); it != mCheckBoxMap.constEnd(); ++it )
110 {
111 it.value()->setChecked( mTable->cellStyle( it.key() )->enabled );
112 QgsColorButton *button = mColorButtonMap.value( it.key() );
113 if ( !button )
114 continue;
115 button->setEnabled( mTable->cellStyle( it.key() )->enabled );
116 button->setColor( mTable->cellStyle( it.key() )->cellBackgroundColor );
117 button->setAllowOpacity( true );
118 button->setColorDialogTitle( tr( "Select Background Color" ) );
119 }
120
121 mDefaultColorButton->setColor( mTable->backgroundColor() );
122 mDefaultColorButton->setAllowOpacity( true );
123 mDefaultColorButton->setColorDialogTitle( tr( "Select Background Color" ) );
124 mDefaultColorButton->setShowNoColor( true );
125 mDefaultColorButton->setNoColorString( tr( "No Background" ) );
126}
A cross platform button subclass for selecting colors.
void setColorDialogTitle(const QString &title)
Set the title for the color chooser dialog window.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
void setColor(const QColor &color)
Sets the current color for the button.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:221
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
@ UndoTableCellStyle
Table cell style.
QgsLayoutTableBackgroundColorsDialog(QgsLayoutTable *table, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutTableBackgroundColorsDialog.
Styling option for a layout table cell.
QColor cellBackgroundColor
Cell background color.
bool enabled
Whether the styling option is enabled.
Displays a table in the print layout, and allows the table to span over multiple frames.
@ FirstRow
Style first row only.
@ EvenColumns
Style even numbered columns.
@ EvenRows
Style even numbered rows.
@ HeaderRow
Style header row.
@ OddColumns
Style odd numbered columns.
@ FirstColumn
Style first column only.
@ LastColumn
Style last column only.
@ LastRow
Style last row only.
@ OddRows
Style odd numbered rows.
void setCellStyle(CellStyleGroup group, const QgsLayoutTableStyle &style)
Sets the cell style for a cell group.