|
| 1 | +/*************************************************************************** |
| 2 | + qgscomposertablebackgroundcolorsdialog.cpp |
| 3 | + ------------------------------------------ |
| 4 | + begin : August 2015 |
| 5 | + copyright : (C) 2015 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 "qgscomposertablebackgroundcolorsdialog.h" |
| 19 | +#include "qgscomposertablev2.h" |
| 20 | +#include "qgscomposition.h" |
| 21 | +#include <QSettings> |
| 22 | +#include <QCheckBox> |
| 23 | +#include <QPushButton> |
| 24 | + |
| 25 | +QgsComposerTableBackgroundColorsDialog::QgsComposerTableBackgroundColorsDialog( QgsComposerTableV2* table, QWidget* parent, Qt::WindowFlags flags ) |
| 26 | + : QDialog( parent, flags ) |
| 27 | + , mComposerTable( table ) |
| 28 | +{ |
| 29 | + setupUi( this ); |
| 30 | + |
| 31 | + mCheckBoxMap.insert( QgsComposerTableV2::OddColumns, mOddColumnsCheckBox ); |
| 32 | + mCheckBoxMap.insert( QgsComposerTableV2::EvenColumns, mEvenColumnsCheckBox ); |
| 33 | + mCheckBoxMap.insert( QgsComposerTableV2::OddRows, mOddRowsCheckBox ); |
| 34 | + mCheckBoxMap.insert( QgsComposerTableV2::EvenRows, mEvenRowsCheckBox ); |
| 35 | + mCheckBoxMap.insert( QgsComposerTableV2::FirstColumn, mFirstColumnCheckBox ); |
| 36 | + mCheckBoxMap.insert( QgsComposerTableV2::LastColumn, mLastColumnCheckBox ); |
| 37 | + mCheckBoxMap.insert( QgsComposerTableV2::HeaderRow, mHeaderRowCheckBox ); |
| 38 | + mCheckBoxMap.insert( QgsComposerTableV2::FirstRow, mFirstRowCheckBox ); |
| 39 | + mCheckBoxMap.insert( QgsComposerTableV2::LastRow, mLastRowCheckBox ); |
| 40 | + |
| 41 | + mColorButtonMap.insert( QgsComposerTableV2::OddColumns, mOddColumnsColorButton ); |
| 42 | + mColorButtonMap.insert( QgsComposerTableV2::EvenColumns, mEvenColumnsColorButton ); |
| 43 | + mColorButtonMap.insert( QgsComposerTableV2::OddRows, mOddRowsColorButton ); |
| 44 | + mColorButtonMap.insert( QgsComposerTableV2::EvenRows, mEvenRowsColorButton ); |
| 45 | + mColorButtonMap.insert( QgsComposerTableV2::FirstColumn, mFirstColumnColorButton ); |
| 46 | + mColorButtonMap.insert( QgsComposerTableV2::LastColumn, mLastColumnColorButton ); |
| 47 | + mColorButtonMap.insert( QgsComposerTableV2::HeaderRow, mHeaderRowColorButton ); |
| 48 | + mColorButtonMap.insert( QgsComposerTableV2::FirstRow, mFirstRowColorButton ); |
| 49 | + mColorButtonMap.insert( QgsComposerTableV2::LastRow, mLastRowColorButton ); |
| 50 | + |
| 51 | + connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); |
| 52 | + |
| 53 | + QSettings settings; |
| 54 | + restoreGeometry( settings.value( "/Windows/ComposerTableBackgroundColorsDialog/geometry" ).toByteArray() ); |
| 55 | + |
| 56 | + setGuiElementValues(); |
| 57 | +} |
| 58 | + |
| 59 | +QgsComposerTableBackgroundColorsDialog::~QgsComposerTableBackgroundColorsDialog() |
| 60 | +{ |
| 61 | + QSettings settings; |
| 62 | + settings.setValue( "/Windows/ComposerTableBackgroundColorsDialog/geometry", saveGeometry() ); |
| 63 | +} |
| 64 | + |
| 65 | +void QgsComposerTableBackgroundColorsDialog::apply() |
| 66 | +{ |
| 67 | + if ( !mComposerTable ) |
| 68 | + return; |
| 69 | + |
| 70 | + QgsComposition* composition = mComposerTable->composition(); |
| 71 | + if ( composition ) |
| 72 | + { |
| 73 | + composition->beginMultiFrameCommand( mComposerTable, tr( "Table background customisation" ), QgsComposerMultiFrameMergeCommand::TableCellStyle ); |
| 74 | + } |
| 75 | + |
| 76 | + Q_FOREACH ( QgsComposerTableV2::CellStyleGroup styleGroup, mCheckBoxMap.keys() ) |
| 77 | + { |
| 78 | + QgsComposerTableStyle style; |
| 79 | + style.enabled = mCheckBoxMap.value( styleGroup )->isChecked(); |
| 80 | + style.cellBackgroundColor = mColorButtonMap.value( styleGroup )->color(); |
| 81 | + |
| 82 | + mComposerTable->setCellStyle( styleGroup, style ); |
| 83 | + } |
| 84 | + |
| 85 | + mComposerTable->setBackgroundColor( mDefaultColorButton->color() ); |
| 86 | + |
| 87 | + if ( composition ) |
| 88 | + { |
| 89 | + composition->endMultiFrameCommand(); |
| 90 | + } |
| 91 | + |
| 92 | + mComposerTable->update(); |
| 93 | +} |
| 94 | + |
| 95 | +void QgsComposerTableBackgroundColorsDialog::on_buttonBox_accepted() |
| 96 | +{ |
| 97 | + apply(); |
| 98 | + accept(); |
| 99 | +} |
| 100 | + |
| 101 | +void QgsComposerTableBackgroundColorsDialog::on_buttonBox_rejected() |
| 102 | +{ |
| 103 | + reject(); |
| 104 | +} |
| 105 | + |
| 106 | +void QgsComposerTableBackgroundColorsDialog::setGuiElementValues() |
| 107 | +{ |
| 108 | + if ( !mComposerTable ) |
| 109 | + return; |
| 110 | + |
| 111 | + Q_FOREACH ( QgsComposerTableV2::CellStyleGroup styleGroup, mCheckBoxMap.keys() ) |
| 112 | + { |
| 113 | + mCheckBoxMap.value( styleGroup )->setChecked( mComposerTable->cellStyle( styleGroup )->enabled ); |
| 114 | + mColorButtonMap.value( styleGroup )->setEnabled( mComposerTable->cellStyle( styleGroup )->enabled ); |
| 115 | + mColorButtonMap.value( styleGroup )->setColor( mComposerTable->cellStyle( styleGroup )->cellBackgroundColor ); |
| 116 | + mColorButtonMap.value( styleGroup )->setAllowAlpha( true ); |
| 117 | + mColorButtonMap.value( styleGroup )->setColorDialogTitle( tr( "Select background color" ) ); |
| 118 | + } |
| 119 | + |
| 120 | + mDefaultColorButton->setColor( mComposerTable->backgroundColor() ); |
| 121 | + mDefaultColorButton->setAllowAlpha( true ); |
| 122 | + mDefaultColorButton->setColorDialogTitle( tr( "Select background color" ) ); |
| 123 | + mDefaultColorButton->setShowNoColor( true ); |
| 124 | + mDefaultColorButton->setNoColorString( tr( "No background" ) ); |
| 125 | +} |
0 commit comments