diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 7c21b36076ea..2a7f3a3654e8 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -174,6 +174,7 @@ SET (QGIS_APP_MOC_HDRS qgsundowidget.h qgsquerybuilder.h + composer/qgsattributeselectiondialog.h composer/qgscomposer.h composer/qgscomposerarrowwidget.h composer/qgscomposeritemwidget.h diff --git a/src/app/composer/qgsattributeselectiondialog.cpp b/src/app/composer/qgsattributeselectiondialog.cpp index f21c60b27de7..5ede02b06666 100644 --- a/src/app/composer/qgsattributeselectiondialog.cpp +++ b/src/app/composer/qgsattributeselectiondialog.cpp @@ -22,19 +22,24 @@ #include #include #include +#include +#include QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer* vLayer, const QSet& enabledAttributes, const QMap& aliasMap, QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer ) { if ( vLayer ) { - mGridLayout = new QGridLayout( this ); + QScrollArea* attributeScrollArea = new QScrollArea( this ); + QWidget* attributeWidget = new QWidget(); + + mAttributeGridLayout = new QGridLayout( attributeWidget ); QLabel* attributeLabel = new QLabel( QString( "" ) + tr( "Attribute" ) + QString( "" ), this ); attributeLabel->setTextFormat( Qt::RichText ); - mGridLayout->addWidget( attributeLabel, 0, 0 ); + mAttributeGridLayout->addWidget( attributeLabel, 0, 0 ); QLabel* aliasLabel = new QLabel( QString( "" ) + tr( "Alias" ) + QString( "" ), this ); aliasLabel->setTextFormat( Qt::RichText ); - mGridLayout->addWidget( aliasLabel, 0, 1 ); + mAttributeGridLayout->addWidget( aliasLabel, 0, 1 ); QgsFieldMap fieldMap = vLayer->pendingFields(); QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin(); @@ -50,7 +55,7 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer* { attributeCheckBox->setCheckState( Qt::Unchecked ); } - mGridLayout->addWidget( attributeCheckBox, layoutRowCounter, 0 ); + mAttributeGridLayout->addWidget( attributeCheckBox, layoutRowCounter, 0 ); QLineEdit* attributeLineEdit = new QLineEdit( this ); QMap::const_iterator aliasIt = aliasMap.find( fieldIt.key() ); @@ -58,14 +63,29 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer* { attributeLineEdit->setText( aliasIt.value() ); } - mGridLayout->addWidget( attributeLineEdit, layoutRowCounter, 1 ); + mAttributeGridLayout->addWidget( attributeLineEdit, layoutRowCounter, 1 ); ++layoutRowCounter; } + attributeScrollArea->setWidget( attributeWidget ); + + QVBoxLayout* verticalLayout = new QVBoxLayout( this ); + verticalLayout->addWidget( attributeScrollArea ); + + QHBoxLayout* selectClearLayout = new QHBoxLayout( this ); + QPushButton* mSelectAllButton = new QPushButton( tr( "Select all" ), this ); + QObject::connect( mSelectAllButton, SIGNAL( clicked() ), this, SLOT( selectAllAttributes() ) ); + QPushButton* mClearButton = new QPushButton( tr( "Clear" ), this ); + QObject::connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clearAttributes() ) ); + selectClearLayout->addWidget( mSelectAllButton ); + selectClearLayout->addWidget( mClearButton ); + verticalLayout->addLayout( selectClearLayout ); + + QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this ); QObject::connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) ); QObject::connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) ); - mGridLayout->addWidget( buttonBox, layoutRowCounter, 0, 3, 1 ); + verticalLayout->addWidget( buttonBox ); } } @@ -77,14 +97,14 @@ QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog() QSet QgsAttributeSelectionDialog::enabledAttributes() const { QSet result; - if ( !mGridLayout || !mVectorLayer ) + if ( !mAttributeGridLayout || !mVectorLayer ) { return result; } - for ( int i = 1; i < mGridLayout->rowCount(); ++i ) + for ( int i = 1; i < mAttributeGridLayout->rowCount(); ++i ) { - QLayoutItem *checkBoxItem = mGridLayout->itemAtPosition( i, 0 ); + QLayoutItem *checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 ); if ( checkBoxItem ) { QCheckBox *checkBox = qobject_cast< QCheckBox * >( checkBoxItem->widget() ); @@ -101,15 +121,15 @@ QSet QgsAttributeSelectionDialog::enabledAttributes() const QMap QgsAttributeSelectionDialog::aliasMap() const { QMap result; - if ( !mGridLayout || !mVectorLayer ) + if ( !mAttributeGridLayout || !mVectorLayer ) { return result; } - for ( int i = 1; i < mGridLayout->rowCount(); ++i ) + for ( int i = 1; i < mAttributeGridLayout->rowCount(); ++i ) { - QLayoutItem* lineEditItem = mGridLayout->itemAtPosition( i, 1 ); - QLayoutItem* checkBoxItem = mGridLayout->itemAtPosition( i, 0 ); + QLayoutItem* lineEditItem = mAttributeGridLayout->itemAtPosition( i, 1 ); + QLayoutItem* checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 ); if ( lineEditItem && checkBoxItem ) { QLineEdit *lineEdit = qobject_cast( lineEditItem->widget() ); @@ -129,3 +149,37 @@ QMap QgsAttributeSelectionDialog::aliasMap() const return result; } +void QgsAttributeSelectionDialog::selectAllAttributes() +{ + setAllEnabled( true ); +} + +void QgsAttributeSelectionDialog::clearAttributes() +{ + setAllEnabled( false ); +} + +void QgsAttributeSelectionDialog::setAllEnabled( bool enabled ) +{ + if ( mAttributeGridLayout ) + { + int nRows = mAttributeGridLayout->rowCount(); + for ( int i = 0; i < nRows; ++i ) + { + QLayoutItem* checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 ); + if ( checkBoxItem ) + { + QWidget* checkBoxWidget = checkBoxItem->widget(); + if ( checkBoxWidget ) + { + QCheckBox* checkBox = dynamic_cast( checkBoxWidget ); + if ( checkBox ) + { + checkBox->setCheckState( enabled ? Qt::Checked : Qt::Unchecked ); + } + } + } + } + } +} + diff --git a/src/app/composer/qgsattributeselectiondialog.h b/src/app/composer/qgsattributeselectiondialog.h index 7fd582c736f2..ecf9ecf10677 100644 --- a/src/app/composer/qgsattributeselectiondialog.h +++ b/src/app/composer/qgsattributeselectiondialog.h @@ -24,22 +24,33 @@ class QGridLayout; class QgsVectorLayer; +class QPushButton; /**A dialog to select what attributes to display (in the table item) and with the possibility to set different aliases*/ class QgsAttributeSelectionDialog: public QDialog { - public: - QgsAttributeSelectionDialog(const QgsVectorLayer* vLayer, const QSet& enabledAttributes, const QMap& aliasMap, QWidget * parent = 0, Qt::WindowFlags f = 0); - ~QgsAttributeSelectionDialog(); - - /**Returns indices of selected attributes*/ - QSet enabledAttributes() const; - /**Returns alias map (alias might be different than for vector layer)*/ - QMap aliasMap() const; - - private: - const QgsVectorLayer* mVectorLayer; - QGridLayout* mGridLayout; + Q_OBJECT + public: + QgsAttributeSelectionDialog( const QgsVectorLayer* vLayer, const QSet& enabledAttributes, const QMap& aliasMap, QWidget * parent = 0, Qt::WindowFlags f = 0 ); + ~QgsAttributeSelectionDialog(); + + /**Returns indices of selected attributes*/ + QSet enabledAttributes() const; + /**Returns alias map (alias might be different than for vector layer)*/ + QMap aliasMap() const; + + private slots: + void selectAllAttributes(); + void clearAttributes(); + + private: + const QgsVectorLayer* mVectorLayer; + QGridLayout* mAttributeGridLayout; + QPushButton* mSelectAllButton; + QPushButton* mClearButton; + + /**Enables / disables all check boxes in one go*/ + void setAllEnabled( bool enabled ); }; #endif // QGSATTRIBUTESELECTIONDIALOG_H