Skip to content

Commit db6f814

Browse files
author
mhugent
committedJan 28, 2010
Added scrool area, 'select all' and 'clear' buttons to attribute dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk@12843 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7e272d2 commit db6f814

File tree

3 files changed

+91
-25
lines changed

3 files changed

+91
-25
lines changed
 

‎src/app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ SET (QGIS_APP_MOC_HDRS
174174
qgsundowidget.h
175175
qgsquerybuilder.h
176176

177+
composer/qgsattributeselectiondialog.h
177178
composer/qgscomposer.h
178179
composer/qgscomposerarrowwidget.h
179180
composer/qgscomposeritemwidget.h

‎src/app/composer/qgsattributeselectiondialog.cpp

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
#include <QGridLayout>
2323
#include <QLabel>
2424
#include <QLineEdit>
25+
#include <QPushButton>
26+
#include <QScrollArea>
2527

2628
QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer* vLayer, const QSet<int>& enabledAttributes, const QMap<int, QString>& aliasMap,
2729
QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer )
2830
{
2931
if ( vLayer )
3032
{
31-
mGridLayout = new QGridLayout( this );
33+
QScrollArea* attributeScrollArea = new QScrollArea( this );
34+
QWidget* attributeWidget = new QWidget();
35+
36+
mAttributeGridLayout = new QGridLayout( attributeWidget );
3237
QLabel* attributeLabel = new QLabel( QString( "<b>" ) + tr( "Attribute" ) + QString( "</b>" ), this );
3338
attributeLabel->setTextFormat( Qt::RichText );
34-
mGridLayout->addWidget( attributeLabel, 0, 0 );
39+
mAttributeGridLayout->addWidget( attributeLabel, 0, 0 );
3540
QLabel* aliasLabel = new QLabel( QString( "<b>" ) + tr( "Alias" ) + QString( "</b>" ), this );
3641
aliasLabel->setTextFormat( Qt::RichText );
37-
mGridLayout->addWidget( aliasLabel, 0, 1 );
42+
mAttributeGridLayout->addWidget( aliasLabel, 0, 1 );
3843

3944
QgsFieldMap fieldMap = vLayer->pendingFields();
4045
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin();
@@ -50,22 +55,37 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer*
5055
{
5156
attributeCheckBox->setCheckState( Qt::Unchecked );
5257
}
53-
mGridLayout->addWidget( attributeCheckBox, layoutRowCounter, 0 );
58+
mAttributeGridLayout->addWidget( attributeCheckBox, layoutRowCounter, 0 );
5459

5560
QLineEdit* attributeLineEdit = new QLineEdit( this );
5661
QMap<int, QString>::const_iterator aliasIt = aliasMap.find( fieldIt.key() );
5762
if ( aliasIt != aliasMap.constEnd() )
5863
{
5964
attributeLineEdit->setText( aliasIt.value() );
6065
}
61-
mGridLayout->addWidget( attributeLineEdit, layoutRowCounter, 1 );
66+
mAttributeGridLayout->addWidget( attributeLineEdit, layoutRowCounter, 1 );
6267
++layoutRowCounter;
6368
}
6469

70+
attributeScrollArea->setWidget( attributeWidget );
71+
72+
QVBoxLayout* verticalLayout = new QVBoxLayout( this );
73+
verticalLayout->addWidget( attributeScrollArea );
74+
75+
QHBoxLayout* selectClearLayout = new QHBoxLayout( this );
76+
QPushButton* mSelectAllButton = new QPushButton( tr( "Select all" ), this );
77+
QObject::connect( mSelectAllButton, SIGNAL( clicked() ), this, SLOT( selectAllAttributes() ) );
78+
QPushButton* mClearButton = new QPushButton( tr( "Clear" ), this );
79+
QObject::connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clearAttributes() ) );
80+
selectClearLayout->addWidget( mSelectAllButton );
81+
selectClearLayout->addWidget( mClearButton );
82+
verticalLayout->addLayout( selectClearLayout );
83+
84+
6585
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
6686
QObject::connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
6787
QObject::connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
68-
mGridLayout->addWidget( buttonBox, layoutRowCounter, 0, 3, 1 );
88+
verticalLayout->addWidget( buttonBox );
6989
}
7090
}
7191

@@ -77,14 +97,14 @@ QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog()
7797
QSet<int> QgsAttributeSelectionDialog::enabledAttributes() const
7898
{
7999
QSet<int> result;
80-
if ( !mGridLayout || !mVectorLayer )
100+
if ( !mAttributeGridLayout || !mVectorLayer )
81101
{
82102
return result;
83103
}
84104

85-
for ( int i = 1; i < mGridLayout->rowCount(); ++i )
105+
for ( int i = 1; i < mAttributeGridLayout->rowCount(); ++i )
86106
{
87-
QLayoutItem *checkBoxItem = mGridLayout->itemAtPosition( i, 0 );
107+
QLayoutItem *checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 );
88108
if ( checkBoxItem )
89109
{
90110
QCheckBox *checkBox = qobject_cast< QCheckBox * >( checkBoxItem->widget() );
@@ -101,15 +121,15 @@ QSet<int> QgsAttributeSelectionDialog::enabledAttributes() const
101121
QMap<int, QString> QgsAttributeSelectionDialog::aliasMap() const
102122
{
103123
QMap<int, QString> result;
104-
if ( !mGridLayout || !mVectorLayer )
124+
if ( !mAttributeGridLayout || !mVectorLayer )
105125
{
106126
return result;
107127
}
108128

109-
for ( int i = 1; i < mGridLayout->rowCount(); ++i )
129+
for ( int i = 1; i < mAttributeGridLayout->rowCount(); ++i )
110130
{
111-
QLayoutItem* lineEditItem = mGridLayout->itemAtPosition( i, 1 );
112-
QLayoutItem* checkBoxItem = mGridLayout->itemAtPosition( i, 0 );
131+
QLayoutItem* lineEditItem = mAttributeGridLayout->itemAtPosition( i, 1 );
132+
QLayoutItem* checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 );
113133
if ( lineEditItem && checkBoxItem )
114134
{
115135
QLineEdit *lineEdit = qobject_cast<QLineEdit*>( lineEditItem->widget() );
@@ -129,3 +149,37 @@ QMap<int, QString> QgsAttributeSelectionDialog::aliasMap() const
129149
return result;
130150
}
131151

152+
void QgsAttributeSelectionDialog::selectAllAttributes()
153+
{
154+
setAllEnabled( true );
155+
}
156+
157+
void QgsAttributeSelectionDialog::clearAttributes()
158+
{
159+
setAllEnabled( false );
160+
}
161+
162+
void QgsAttributeSelectionDialog::setAllEnabled( bool enabled )
163+
{
164+
if ( mAttributeGridLayout )
165+
{
166+
int nRows = mAttributeGridLayout->rowCount();
167+
for ( int i = 0; i < nRows; ++i )
168+
{
169+
QLayoutItem* checkBoxItem = mAttributeGridLayout->itemAtPosition( i, 0 );
170+
if ( checkBoxItem )
171+
{
172+
QWidget* checkBoxWidget = checkBoxItem->widget();
173+
if ( checkBoxWidget )
174+
{
175+
QCheckBox* checkBox = dynamic_cast<QCheckBox*>( checkBoxWidget );
176+
if ( checkBox )
177+
{
178+
checkBox->setCheckState( enabled ? Qt::Checked : Qt::Unchecked );
179+
}
180+
}
181+
}
182+
}
183+
}
184+
}
185+

‎src/app/composer/qgsattributeselectiondialog.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,33 @@
2424

2525
class QGridLayout;
2626
class QgsVectorLayer;
27+
class QPushButton;
2728

2829
/**A dialog to select what attributes to display (in the table item) and with the possibility to set different aliases*/
2930
class QgsAttributeSelectionDialog: public QDialog
3031
{
31-
public:
32-
QgsAttributeSelectionDialog(const QgsVectorLayer* vLayer, const QSet<int>& enabledAttributes, const QMap<int, QString>& aliasMap, QWidget * parent = 0, Qt::WindowFlags f = 0);
33-
~QgsAttributeSelectionDialog();
34-
35-
/**Returns indices of selected attributes*/
36-
QSet<int> enabledAttributes() const;
37-
/**Returns alias map (alias might be different than for vector layer)*/
38-
QMap<int, QString> aliasMap() const;
39-
40-
private:
41-
const QgsVectorLayer* mVectorLayer;
42-
QGridLayout* mGridLayout;
32+
Q_OBJECT
33+
public:
34+
QgsAttributeSelectionDialog( const QgsVectorLayer* vLayer, const QSet<int>& enabledAttributes, const QMap<int, QString>& aliasMap, QWidget * parent = 0, Qt::WindowFlags f = 0 );
35+
~QgsAttributeSelectionDialog();
36+
37+
/**Returns indices of selected attributes*/
38+
QSet<int> enabledAttributes() const;
39+
/**Returns alias map (alias might be different than for vector layer)*/
40+
QMap<int, QString> aliasMap() const;
41+
42+
private slots:
43+
void selectAllAttributes();
44+
void clearAttributes();
45+
46+
private:
47+
const QgsVectorLayer* mVectorLayer;
48+
QGridLayout* mAttributeGridLayout;
49+
QPushButton* mSelectAllButton;
50+
QPushButton* mClearButton;
51+
52+
/**Enables / disables all check boxes in one go*/
53+
void setAllEnabled( bool enabled );
4354
};
4455

4556
#endif // QGSATTRIBUTESELECTIONDIALOG_H

0 commit comments

Comments
 (0)
Please sign in to comment.