22
22
#include < QGridLayout>
23
23
#include < QLabel>
24
24
#include < QLineEdit>
25
+ #include < QPushButton>
26
+ #include < QScrollArea>
25
27
26
28
QgsAttributeSelectionDialog::QgsAttributeSelectionDialog ( const QgsVectorLayer* vLayer, const QSet<int >& enabledAttributes, const QMap<int , QString>& aliasMap,
27
29
QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer )
28
30
{
29
31
if ( vLayer )
30
32
{
31
- mGridLayout = new QGridLayout ( this );
33
+ QScrollArea* attributeScrollArea = new QScrollArea ( this );
34
+ QWidget* attributeWidget = new QWidget ();
35
+
36
+ mAttributeGridLayout = new QGridLayout ( attributeWidget );
32
37
QLabel* attributeLabel = new QLabel ( QString ( " <b>" ) + tr ( " Attribute" ) + QString ( " </b>" ), this );
33
38
attributeLabel->setTextFormat ( Qt::RichText );
34
- mGridLayout ->addWidget ( attributeLabel, 0 , 0 );
39
+ mAttributeGridLayout ->addWidget ( attributeLabel, 0 , 0 );
35
40
QLabel* aliasLabel = new QLabel ( QString ( " <b>" ) + tr ( " Alias" ) + QString ( " </b>" ), this );
36
41
aliasLabel->setTextFormat ( Qt::RichText );
37
- mGridLayout ->addWidget ( aliasLabel, 0 , 1 );
42
+ mAttributeGridLayout ->addWidget ( aliasLabel, 0 , 1 );
38
43
39
44
QgsFieldMap fieldMap = vLayer->pendingFields ();
40
45
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin ();
@@ -50,22 +55,37 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer*
50
55
{
51
56
attributeCheckBox->setCheckState ( Qt::Unchecked );
52
57
}
53
- mGridLayout ->addWidget ( attributeCheckBox, layoutRowCounter, 0 );
58
+ mAttributeGridLayout ->addWidget ( attributeCheckBox, layoutRowCounter, 0 );
54
59
55
60
QLineEdit* attributeLineEdit = new QLineEdit ( this );
56
61
QMap<int , QString>::const_iterator aliasIt = aliasMap.find ( fieldIt.key () );
57
62
if ( aliasIt != aliasMap.constEnd () )
58
63
{
59
64
attributeLineEdit->setText ( aliasIt.value () );
60
65
}
61
- mGridLayout ->addWidget ( attributeLineEdit, layoutRowCounter, 1 );
66
+ mAttributeGridLayout ->addWidget ( attributeLineEdit, layoutRowCounter, 1 );
62
67
++layoutRowCounter;
63
68
}
64
69
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
+
65
85
QDialogButtonBox* buttonBox = new QDialogButtonBox ( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
66
86
QObject::connect ( buttonBox, SIGNAL ( accepted () ), this , SLOT ( accept () ) );
67
87
QObject::connect ( buttonBox, SIGNAL ( rejected () ), this , SLOT ( reject () ) );
68
- mGridLayout ->addWidget ( buttonBox, layoutRowCounter, 0 , 3 , 1 );
88
+ verticalLayout ->addWidget ( buttonBox );
69
89
}
70
90
}
71
91
@@ -77,14 +97,14 @@ QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog()
77
97
QSet<int > QgsAttributeSelectionDialog::enabledAttributes () const
78
98
{
79
99
QSet<int > result;
80
- if ( !mGridLayout || !mVectorLayer )
100
+ if ( !mAttributeGridLayout || !mVectorLayer )
81
101
{
82
102
return result;
83
103
}
84
104
85
- for ( int i = 1 ; i < mGridLayout ->rowCount (); ++i )
105
+ for ( int i = 1 ; i < mAttributeGridLayout ->rowCount (); ++i )
86
106
{
87
- QLayoutItem *checkBoxItem = mGridLayout ->itemAtPosition ( i, 0 );
107
+ QLayoutItem *checkBoxItem = mAttributeGridLayout ->itemAtPosition ( i, 0 );
88
108
if ( checkBoxItem )
89
109
{
90
110
QCheckBox *checkBox = qobject_cast< QCheckBox * >( checkBoxItem->widget () );
@@ -101,15 +121,15 @@ QSet<int> QgsAttributeSelectionDialog::enabledAttributes() const
101
121
QMap<int , QString> QgsAttributeSelectionDialog::aliasMap () const
102
122
{
103
123
QMap<int , QString> result;
104
- if ( !mGridLayout || !mVectorLayer )
124
+ if ( !mAttributeGridLayout || !mVectorLayer )
105
125
{
106
126
return result;
107
127
}
108
128
109
- for ( int i = 1 ; i < mGridLayout ->rowCount (); ++i )
129
+ for ( int i = 1 ; i < mAttributeGridLayout ->rowCount (); ++i )
110
130
{
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 );
113
133
if ( lineEditItem && checkBoxItem )
114
134
{
115
135
QLineEdit *lineEdit = qobject_cast<QLineEdit*>( lineEditItem->widget () );
@@ -129,3 +149,37 @@ QMap<int, QString> QgsAttributeSelectionDialog::aliasMap() const
129
149
return result;
130
150
}
131
151
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
+
0 commit comments