26
26
#include < QScrollArea>
27
27
28
28
QgsAttributeSelectionDialog::QgsAttributeSelectionDialog ( const QgsVectorLayer* vLayer, const QSet<int >& enabledAttributes, const QMap<int , QString>& aliasMap,
29
- QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer )
29
+ const QList< QPair< int , bool > >& sortColumns, QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mVectorLayer( vLayer )
30
30
{
31
+ setupUi ( this );
31
32
if ( vLayer )
32
33
{
33
- QScrollArea* attributeScrollArea = new QScrollArea ( this );
34
- QWidget* attributeWidget = new QWidget ();
35
-
36
- mAttributeGridLayout = new QGridLayout ( attributeWidget );
37
- QLabel* attributeLabel = new QLabel ( QString ( " <b>" ) + tr ( " Attribute" ) + QString ( " </b>" ), this );
38
- attributeLabel->setTextFormat ( Qt::RichText );
39
- mAttributeGridLayout ->addWidget ( attributeLabel, 0 , 0 );
40
- QLabel* aliasLabel = new QLabel ( QString ( " <b>" ) + tr ( " Alias" ) + QString ( " </b>" ), this );
41
- aliasLabel->setTextFormat ( Qt::RichText );
42
- mAttributeGridLayout ->addWidget ( aliasLabel, 0 , 1 );
43
-
44
34
QgsFieldMap fieldMap = vLayer->pendingFields ();
45
35
QgsFieldMap::const_iterator fieldIt = fieldMap.constBegin ();
46
36
int layoutRowCounter = 1 ;
47
37
for ( ; fieldIt != fieldMap.constEnd (); ++fieldIt )
48
38
{
39
+ // insert field into sorting combo first
40
+ mSortColumnComboBox ->addItem ( fieldIt.value ().name (), QVariant ( fieldIt.key () ) );
41
+
42
+ // and into enabled / alias list
49
43
QCheckBox* attributeCheckBox = new QCheckBox ( fieldIt.value ().name (), this );
50
44
if ( enabledAttributes.size () < 1 || enabledAttributes.contains ( fieldIt.key () ) )
51
45
{
@@ -55,38 +49,32 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( const QgsVectorLayer*
55
49
{
56
50
attributeCheckBox->setCheckState ( Qt::Unchecked );
57
51
}
58
- mAttributeGridLayout ->addWidget ( attributeCheckBox, layoutRowCounter, 0 );
52
+ mAttributeGridLayout ->addWidget (( QWidget* ) attributeCheckBox, layoutRowCounter, 0 , 1 , 1 );
59
53
60
54
QLineEdit* attributeLineEdit = new QLineEdit ( this );
61
55
QMap<int , QString>::const_iterator aliasIt = aliasMap.find ( fieldIt.key () );
62
56
if ( aliasIt != aliasMap.constEnd () )
63
57
{
64
58
attributeLineEdit->setText ( aliasIt.value () );
65
59
}
66
- mAttributeGridLayout ->addWidget ( attributeLineEdit, layoutRowCounter, 1 );
60
+ mAttributeGridLayout ->addWidget (( QWidget* ) attributeLineEdit, layoutRowCounter, 1 , 1 , 1 );
67
61
++layoutRowCounter;
68
62
}
69
63
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
-
85
- QDialogButtonBox* buttonBox = new QDialogButtonBox ( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
86
- QObject::connect ( buttonBox, SIGNAL ( accepted () ), this , SLOT ( accept () ) );
87
- QObject::connect ( buttonBox, SIGNAL ( rejected () ), this , SLOT ( reject () ) );
88
- verticalLayout->addWidget ( buttonBox );
64
+ // sort columns
65
+ QList< QPair<int , bool > >::const_iterator sortIt = sortColumns.constBegin ();
66
+ for ( ; sortIt != sortColumns.constEnd (); ++sortIt )
67
+ {
68
+ QTreeWidgetItem* item = new QTreeWidgetItem ();
69
+ item->setText ( 0 , fieldMap[sortIt->first ].name () );
70
+ item->setData ( 0 , Qt::UserRole, sortIt->first );
71
+ item->setText ( 1 , sortIt->second ? tr ( " Ascending" ) : tr ( " Descending" ) );
72
+ mSortColumnTreeWidget ->addTopLevelItem ( item );
73
+ }
89
74
}
75
+
76
+ mOrderComboBox ->insertItem ( 0 , tr ( " Ascending" ) );
77
+ mOrderComboBox ->insertItem ( 0 , tr ( " Descending" ) );
90
78
}
91
79
92
80
QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog ()
@@ -149,12 +137,28 @@ QMap<int, QString> QgsAttributeSelectionDialog::aliasMap() const
149
137
return result;
150
138
}
151
139
152
- void QgsAttributeSelectionDialog::selectAllAttributes ()
140
+ QList< QPair<int , bool > > QgsAttributeSelectionDialog::attributeSorting () const
141
+ {
142
+ QList< QPair<int , bool > > sortingList;
143
+
144
+ for ( int i = 0 ; i < mSortColumnTreeWidget ->topLevelItemCount (); ++i )
145
+ {
146
+ QTreeWidgetItem* item = mSortColumnTreeWidget ->topLevelItem ( i );
147
+ if ( item )
148
+ {
149
+ sortingList.push_back ( qMakePair ( item->data ( 0 , Qt::UserRole ).toInt (), item->text ( 1 ) == tr ( " Ascending" ) ) );
150
+ }
151
+ }
152
+
153
+ return sortingList;
154
+ }
155
+
156
+ void QgsAttributeSelectionDialog::on_mSelectAllButton_clicked ()
153
157
{
154
158
setAllEnabled ( true );
155
159
}
156
160
157
- void QgsAttributeSelectionDialog::clearAttributes ()
161
+ void QgsAttributeSelectionDialog::on_mClearButton_clicked ()
158
162
{
159
163
setAllEnabled ( false );
160
164
}
@@ -183,3 +187,48 @@ void QgsAttributeSelectionDialog::setAllEnabled( bool enabled )
183
187
}
184
188
}
185
189
190
+ void QgsAttributeSelectionDialog::on_mAddPushButton_clicked ()
191
+ {
192
+ QTreeWidgetItem* item = new QTreeWidgetItem ();
193
+ item->setText ( 0 , mSortColumnComboBox ->currentText () );
194
+ item->setData ( 0 , Qt::UserRole, mSortColumnComboBox ->itemData ( mSortColumnComboBox ->currentIndex () ) );
195
+ item->setText ( 1 , mOrderComboBox ->currentText () );
196
+ mSortColumnTreeWidget ->addTopLevelItem ( item );
197
+ }
198
+
199
+ void QgsAttributeSelectionDialog::on_mRemovePushButton_clicked ()
200
+ {
201
+ int currentIndex = mSortColumnTreeWidget ->indexOfTopLevelItem ( mSortColumnTreeWidget ->currentItem () );
202
+ if ( currentIndex != -1 )
203
+ {
204
+ delete ( mSortColumnTreeWidget ->takeTopLevelItem ( currentIndex ) );
205
+ }
206
+ }
207
+
208
+ void QgsAttributeSelectionDialog::on_mUpPushButton_clicked ()
209
+ {
210
+ int currentIndex = mSortColumnTreeWidget ->indexOfTopLevelItem ( mSortColumnTreeWidget ->currentItem () );
211
+ if ( currentIndex != -1 )
212
+ {
213
+ if ( currentIndex > 0 )
214
+ {
215
+ QTreeWidgetItem* item = mSortColumnTreeWidget ->takeTopLevelItem ( currentIndex );
216
+ mSortColumnTreeWidget ->insertTopLevelItem ( currentIndex - 1 , item );
217
+ mSortColumnTreeWidget ->setCurrentItem ( item );
218
+ }
219
+ }
220
+ }
221
+
222
+ void QgsAttributeSelectionDialog::on_mDownPushButton_clicked ()
223
+ {
224
+ int currentIndex = mSortColumnTreeWidget ->indexOfTopLevelItem ( mSortColumnTreeWidget ->currentItem () );
225
+ if ( currentIndex != -1 )
226
+ {
227
+ if ( currentIndex < ( mSortColumnTreeWidget ->topLevelItemCount () - 1 ) )
228
+ {
229
+ QTreeWidgetItem* item = mSortColumnTreeWidget ->takeTopLevelItem ( currentIndex );
230
+ mSortColumnTreeWidget ->insertTopLevelItem ( currentIndex + 1 , item );
231
+ mSortColumnTreeWidget ->setCurrentItem ( item );
232
+ }
233
+ }
234
+ }
0 commit comments