QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgslayouttablebackgroundcolorsdialog.cpp"
20#include "qgslayouttable.h"
21#include "qgslayout.h"
22#include "qgssettings.h"
23#include "qgshelp.h"
24#include "qgsgui.h"
25
26#include <QCheckBox>
27#include <QPushButton>
28
30 : QDialog( parent, flags )
31 , mTable( table )
32{
33 setupUi( this );
35
36 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsLayoutTableBackgroundColorsDialog::buttonBox_accepted );
37 connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsLayoutTableBackgroundColorsDialog::buttonBox_rejected );
38 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutTableBackgroundColorsDialog::showHelp );
39
40 mCheckBoxMap.insert( QgsLayoutTable::OddColumns, mOddColumnsCheckBox );
41 mCheckBoxMap.insert( QgsLayoutTable::EvenColumns, mEvenColumnsCheckBox );
42 mCheckBoxMap.insert( QgsLayoutTable::OddRows, mOddRowsCheckBox );
43 mCheckBoxMap.insert( QgsLayoutTable::EvenRows, mEvenRowsCheckBox );
44 mCheckBoxMap.insert( QgsLayoutTable::FirstColumn, mFirstColumnCheckBox );
45 mCheckBoxMap.insert( QgsLayoutTable::LastColumn, mLastColumnCheckBox );
46 mCheckBoxMap.insert( QgsLayoutTable::HeaderRow, mHeaderRowCheckBox );
47 mCheckBoxMap.insert( QgsLayoutTable::FirstRow, mFirstRowCheckBox );
48 mCheckBoxMap.insert( QgsLayoutTable::LastRow, mLastRowCheckBox );
49
50 mColorButtonMap.insert( QgsLayoutTable::OddColumns, mOddColumnsColorButton );
51 mColorButtonMap.insert( QgsLayoutTable::EvenColumns, mEvenColumnsColorButton );
52 mColorButtonMap.insert( QgsLayoutTable::OddRows, mOddRowsColorButton );
53 mColorButtonMap.insert( QgsLayoutTable::EvenRows, mEvenRowsColorButton );
54 mColorButtonMap.insert( QgsLayoutTable::FirstColumn, mFirstColumnColorButton );
55 mColorButtonMap.insert( QgsLayoutTable::LastColumn, mLastColumnColorButton );
56 mColorButtonMap.insert( QgsLayoutTable::HeaderRow, mHeaderRowColorButton );
57 mColorButtonMap.insert( QgsLayoutTable::FirstRow, mFirstRowColorButton );
58 mColorButtonMap.insert( QgsLayoutTable::LastRow, mLastRowColorButton );
59
60 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsLayoutTableBackgroundColorsDialog::apply );
61
62 setGuiElementValues();
63}
64
65void QgsLayoutTableBackgroundColorsDialog::apply()
66{
67 if ( !mTable )
68 return;
69
70 mTable->beginCommand( tr( "Change Table Background" ), QgsLayoutMultiFrame::UndoTableCellStyle );
71 for ( auto checkBoxIt = mCheckBoxMap.constBegin(); checkBoxIt != mCheckBoxMap.constEnd(); ++checkBoxIt )
72 {
74 style.enabled = checkBoxIt.value()->isChecked();
75 if ( QgsColorButton *button = mColorButtonMap.value( checkBoxIt.key() ) )
76 style.cellBackgroundColor = button->color();
77
78 mTable->setCellStyle( checkBoxIt.key(), style );
79 }
80
81 mTable->setBackgroundColor( mDefaultColorButton->color() );
82 mTable->endCommand();
83 mTable->update();
84}
85
86void QgsLayoutTableBackgroundColorsDialog::buttonBox_accepted()
87{
88 apply();
89 accept();
90}
91
92void QgsLayoutTableBackgroundColorsDialog::buttonBox_rejected()
93{
94 reject();
95}
96
97void QgsLayoutTableBackgroundColorsDialog::showHelp()
98{
99 QgsHelp::openHelp( QStringLiteral( "print_composer/composer_items/composer_attribute_table.html#appearance" ) );
100}
101
102void QgsLayoutTableBackgroundColorsDialog::setGuiElementValues()
103{
104 if ( !mTable )
105 return;
106
107 for ( auto it = mCheckBoxMap.constBegin(); it != mCheckBoxMap.constEnd(); ++it )
108 {
109 it.value()->setChecked( mTable->cellStyle( it.key() )->enabled );
110 QgsColorButton *button = mColorButtonMap.value( it.key() );
111 if ( !button )
112 continue;
113 button->setEnabled( mTable->cellStyle( it.key() )->enabled );
114 button->setColor( mTable->cellStyle( it.key() )->cellBackgroundColor );
115 button->setAllowOpacity( true );
116 button->setColorDialogTitle( tr( "Select Background Color" ) );
117 }
118
119 mDefaultColorButton->setColor( mTable->backgroundColor() );
120 mDefaultColorButton->setAllowOpacity( true );
121 mDefaultColorButton->setColorDialogTitle( tr( "Select Background Color" ) );
122 mDefaultColorButton->setShowNoColor( true );
123 mDefaultColorButton->setNoColorString( tr( "No Background" ) );
124}
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:209
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
void endCommand()
Completes the current item command and push it onto the layout's undo stack.
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
void update()
Forces a redraw of all child frames.
@ 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.
A class to display a table in the print layout, and allow the table to span over multiple frames.
QColor backgroundColor() const
Returns the color used for the background of the table.
void setBackgroundColor(const QColor &color)
Sets the color used for background of table.
@ 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.
const QgsLayoutTableStyle * cellStyle(CellStyleGroup group) const
Returns the cell style for a cell group.