@@ -207,12 +207,82 @@ QList<QDomNode> QgsGrassModuleParam::nodesByType( QDomElement descDomElement, ST
207
207
return nodes;
208
208
}
209
209
210
+ /* **************** QgsGrassModuleGroupBoxItem *********************/
211
+
212
+ QgsGrassModuleGroupBoxItem::QgsGrassModuleGroupBoxItem ( QgsGrassModule *module , QString key,
213
+ QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
214
+ bool direct, QWidget * parent )
215
+ : QGroupBox( parent )
216
+ , QgsGrassModuleParam( module , key, qdesc, gdesc, gnode, direct )
217
+ {
218
+ adjustTitle ();
219
+ setToolTip ( mToolTip );
220
+ }
221
+
222
+ QgsGrassModuleGroupBoxItem::~QgsGrassModuleGroupBoxItem () {}
223
+
224
+ void QgsGrassModuleGroupBoxItem::resizeEvent ( QResizeEvent * event )
225
+ {
226
+ Q_UNUSED ( event );
227
+ adjustTitle ();
228
+ setToolTip ( mToolTip );
229
+ }
230
+
231
+ void QgsGrassModuleGroupBoxItem::adjustTitle ()
232
+ {
233
+ QString tit = fontMetrics ().elidedText ( mTitle , Qt::ElideRight, width () - 20 );
234
+
235
+ setTitle ( tit );
236
+ }
237
+
238
+ /* **************** QgsGrassModuleMultiParam *********************/
239
+
240
+ QgsGrassModuleMultiParam::QgsGrassModuleMultiParam ( QgsGrassModule *module , QString key,
241
+ QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
242
+ bool direct, QWidget * parent )
243
+ : QgsGrassModuleGroupBoxItem( module , key, qdesc, gdesc, gnode, direct, parent )
244
+ , mLayout(0 )
245
+ , mParamsLayout(0 )
246
+ , mButtonsLayout(0 )
247
+ {
248
+ adjustTitle ();
249
+ setToolTip ( mToolTip );
250
+
251
+ // variable number of line edits
252
+ // add/delete buttons for multiple options
253
+ mLayout = new QHBoxLayout ( this );
254
+ mParamsLayout = new QVBoxLayout ();
255
+
256
+ mLayout ->insertLayout ( -1 , mParamsLayout );
257
+
258
+ }
259
+
260
+ QgsGrassModuleMultiParam::~QgsGrassModuleMultiParam () {}
261
+
262
+ void QgsGrassModuleMultiParam::showAddRemoveButtons ()
263
+ {
264
+ mButtonsLayout = new QVBoxLayout ();
265
+ mLayout ->insertLayout ( -1 , mButtonsLayout );
266
+
267
+ // TODO: how to keep both buttons on the top?
268
+ QPushButton *addButton = new QPushButton ( " +" , this );
269
+ connect ( addButton, SIGNAL ( clicked () ), this , SLOT ( addRow () ) );
270
+ mButtonsLayout ->addWidget ( addButton, 0 , Qt::AlignTop );
271
+
272
+ QPushButton *removeButton = new QPushButton ( " -" , this );
273
+ connect ( removeButton, SIGNAL ( clicked () ), this , SLOT ( removeRow () ) );
274
+ mButtonsLayout ->addWidget ( removeButton, 0 , Qt::AlignTop );
275
+
276
+ // Don't enable this, it makes the group box expanding
277
+ // mButtonsLayout->addStretch();
278
+ }
279
+
210
280
/* ********************* QgsGrassModuleOption *************************/
211
281
212
282
QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module , QString key,
213
283
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
214
284
bool direct, QWidget * parent )
215
- : QgsGrassModuleGroupBoxItem ( module , key, qdesc, gdesc, gnode, direct, parent )
285
+ : QgsGrassModuleMultiParam ( module , key, qdesc, gdesc, gnode, direct, parent )
216
286
, mControlType( NoControl )
217
287
, mValueType( String )
218
288
, mOutputType( None )
@@ -222,16 +292,15 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
222
292
, mComboBox( 0 )
223
293
, mIsOutput( false )
224
294
, mValidator( 0 )
225
- , mLayout( 0 )
226
295
, mUsesRegion( false )
227
296
{
228
297
QgsDebugMsg ( " entered" );
229
298
setSizePolicy ( QSizePolicy::MinimumExpanding, QSizePolicy::Minimum );
230
299
231
300
if ( mHidden )
301
+ {
232
302
hide ();
233
-
234
- mLayout = new QVBoxLayout ();
303
+ }
235
304
236
305
// Is it output?
237
306
QDomNode promptNode = gnode.namedItem ( " gisprompt" );
@@ -271,9 +340,10 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
271
340
272
341
if ( !valuesNode.isNull () && valuesNode.childNodes ().count () > 1 )
273
342
{
274
- setLayout ( mLayout );
275
343
// predefined values -> ComboBox or CheckBox
276
344
345
+ // TODO: add add/removeRow support for ComboBox?
346
+
277
347
// one or many?
278
348
if ( gelem.attribute ( " multiple" ) == " yes" )
279
349
{
@@ -283,7 +353,7 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
283
353
{
284
354
mControlType = ComboBox;
285
355
mComboBox = new QComboBox ( this );
286
- mLayout ->addWidget ( mComboBox );
356
+ paramsLayout () ->addWidget ( mComboBox );
287
357
}
288
358
289
359
// List of values to be excluded
@@ -331,7 +401,7 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
331
401
{
332
402
QgsGrassModuleCheckBox *cb = new QgsGrassModuleCheckBox ( desc, this );
333
403
mCheckBoxes .push_back ( cb );
334
- mLayout ->addWidget ( cb );
404
+ paramsLayout () ->addWidget ( cb );
335
405
}
336
406
337
407
mValues .push_back ( val );
@@ -417,37 +487,16 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
417
487
// QString itemDesc = nodeItem.firstChild().toText().data();
418
488
QgsDebugMsg ( " keydesc item = " + itemDesc );
419
489
420
- addLineEdit ();
490
+ addRow ();
421
491
}
422
-
423
- setLayout ( mLayout );
424
- }
425
- else if ( gelem.attribute ( " multiple" ) == " yes" )
426
- {
427
- // variable number of line edits
428
- // add/delete buttons for multiple options
429
- QHBoxLayout *l = new QHBoxLayout ( this );
430
- QVBoxLayout *vl = new QVBoxLayout ();
431
- l->insertLayout ( -1 , mLayout );
432
- l->insertLayout ( -1 , vl );
433
-
434
- // TODO: how to keep both buttons on the top?
435
- QPushButton *b = new QPushButton ( " +" , this );
436
- connect ( b, SIGNAL ( clicked () ), this , SLOT ( addLineEdit () ) );
437
- vl->addWidget ( b, 0 , Qt::AlignTop );
438
-
439
- b = new QPushButton ( " -" , this );
440
- connect ( b, SIGNAL ( clicked () ), this , SLOT ( removeLineEdit () ) );
441
- vl->addWidget ( b, 0 , Qt::AlignTop );
442
-
443
- // Don't enable this, it makes the group box expanding
444
- // vl->addStretch();
445
492
}
446
493
else
447
494
{
448
- // only one line edit
449
- addLineEdit ();
450
- setLayout ( mLayout );
495
+ addRow ();
496
+ if ( gelem.attribute ( " multiple" ) == " yes" )
497
+ {
498
+ showAddRemoveButtons ();
499
+ }
451
500
}
452
501
}
453
502
}
@@ -470,13 +519,13 @@ QgsGrassModuleOption::QgsGrassModuleOption( QgsGrassModule *module, QString key,
470
519
QgsDebugMsg ( QString ( " mUsesRegion = %1" ).arg ( mUsesRegion ) );
471
520
}
472
521
473
- void QgsGrassModuleOption::addLineEdit ()
522
+ void QgsGrassModuleOption::addRow ()
474
523
{
475
524
QgsDebugMsg ( " entered" );
476
525
477
526
// TODO make the widget growing with new lines. HOW???!!!
478
527
QLineEdit *lineEdit = new QLineEdit ( this );
479
- mLineEdits . push_back ( lineEdit ) ;
528
+ mLineEdits << lineEdit ;
480
529
lineEdit->setText ( mAnswer );
481
530
482
531
if ( mValueType == Integer )
@@ -523,18 +572,30 @@ void QgsGrassModuleOption::addLineEdit()
523
572
{
524
573
QHBoxLayout *l = new QHBoxLayout ();
525
574
l->addWidget ( lineEdit );
526
- lineEdit->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy:: Preferred );
575
+ lineEdit->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Preferred );
527
576
QPushButton *button = new QPushButton ( tr ( " Browse" ) );
528
577
l->addWidget ( button );
529
- mLayout ->addItem ( l );
578
+ paramsLayout () ->addItem ( l );
530
579
connect ( button, SIGNAL ( clicked ( bool ) ), this , SLOT ( browse ( bool ) ) );
531
580
}
532
581
else
533
582
{
534
- mLayout ->addWidget ( lineEdit );
583
+ paramsLayout () ->addWidget ( lineEdit );
535
584
}
536
585
}
537
586
587
+ void QgsGrassModuleOption::removeRow ()
588
+ {
589
+ QgsDebugMsg ( " entered" );
590
+
591
+ if ( mLineEdits .size () < 2 )
592
+ {
593
+ return ;
594
+ }
595
+ delete mLineEdits .at ( mLineEdits .size () - 1 );
596
+ mLineEdits .removeLast ();
597
+ }
598
+
538
599
void QgsGrassModuleOption::browse ( bool checked )
539
600
{
540
601
Q_UNUSED ( checked );
@@ -554,16 +615,6 @@ void QgsGrassModuleOption::browse( bool checked )
554
615
}
555
616
}
556
617
557
- void QgsGrassModuleOption::removeLineEdit ()
558
- {
559
- QgsDebugMsg ( " entered" );
560
-
561
- if ( mLineEdits .size () < 2 )
562
- return ;
563
- delete mLineEdits .at ( mLineEdits .size () - 1 );
564
- mLineEdits .pop_back ();
565
- }
566
-
567
618
QString QgsGrassModuleOption::outputExists ()
568
619
{
569
620
QgsDebugMsg ( " entered" );
@@ -761,35 +812,6 @@ QgsGrassModuleFlag::~QgsGrassModuleFlag()
761
812
{
762
813
}
763
814
764
- /* **************** QgsGrassModuleGroupBoxItem *********************/
765
-
766
- QgsGrassModuleGroupBoxItem::QgsGrassModuleGroupBoxItem ( QgsGrassModule *module , QString key,
767
- QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
768
- bool direct, QWidget * parent )
769
- : QGroupBox( parent )
770
- , QgsGrassModuleParam( module , key, qdesc, gdesc, gnode, direct )
771
- {
772
- adjustTitle ();
773
-
774
- setToolTip ( mToolTip );
775
- }
776
-
777
- QgsGrassModuleGroupBoxItem::~QgsGrassModuleGroupBoxItem () {}
778
-
779
- void QgsGrassModuleGroupBoxItem::resizeEvent ( QResizeEvent * event )
780
- {
781
- Q_UNUSED ( event );
782
- adjustTitle ();
783
- setToolTip ( mToolTip );
784
- }
785
-
786
- void QgsGrassModuleGroupBoxItem::adjustTitle ()
787
- {
788
- QString tit = fontMetrics ().elidedText ( mTitle , Qt::ElideRight, width () - 20 );
789
-
790
- setTitle ( tit );
791
- }
792
-
793
815
/* **************** QgsGrassModuleGdalInput *********************/
794
816
795
817
QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
@@ -1095,7 +1117,7 @@ QgsGrassModuleVectorField::QgsGrassModuleVectorField(
1095
1117
QgsGrassModule *module , QgsGrassModuleStandardOptions *options,
1096
1118
QString key, QDomElement &qdesc,
1097
1119
QDomElement &gdesc, QDomNode &gnode, bool direct, QWidget * parent )
1098
- : QgsGrassModuleGroupBoxItem ( module , key, qdesc, gdesc, gnode, direct, parent )
1120
+ : QgsGrassModuleMultiParam ( module , key, qdesc, gdesc, gnode, direct, parent )
1099
1121
, mModuleStandardOptions( options ), mLayerInput( 0 )
1100
1122
{
1101
1123
if ( mTitle .isEmpty () )
@@ -1105,8 +1127,7 @@ QgsGrassModuleVectorField::QgsGrassModuleVectorField(
1105
1127
adjustTitle ();
1106
1128
1107
1129
QDomNode promptNode = gnode.namedItem ( " gisprompt" );
1108
- QDomElement promptElem = promptNode.toElement ();
1109
- QString element = promptElem.attribute ( " element" );
1130
+ QDomElement gelem = gnode.toElement ();
1110
1131
1111
1132
mType = qdesc.attribute ( " type" );
1112
1133
@@ -1126,36 +1147,65 @@ QgsGrassModuleVectorField::QgsGrassModuleVectorField(
1126
1147
}
1127
1148
}
1128
1149
1129
- QHBoxLayout *l = new QHBoxLayout ( this );
1130
- mFieldComboBox = new QComboBox ();
1131
- l->addWidget ( mFieldComboBox );
1150
+ addRow ();
1151
+ if ( gelem.attribute ( " multiple" ) == " yes" )
1152
+ {
1153
+ showAddRemoveButtons ();
1154
+ }
1132
1155
1133
1156
// Fill in layer current fields
1134
1157
updateFields ();
1135
1158
}
1136
1159
1137
- void QgsGrassModuleVectorField::updateFields ()
1160
+ void QgsGrassModuleVectorField::addRow ()
1138
1161
{
1139
1162
QgsDebugMsg ( " entered" );
1163
+ QComboBox *comboBox = new QComboBox ();
1164
+ comboBox->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Fixed );
1165
+ paramsLayout ()->addWidget ( comboBox );
1166
+ mComboBoxList << comboBox;
1167
+ updateFields ();
1168
+ }
1140
1169
1141
- QString current = mFieldComboBox ->currentText ();
1142
- mFieldComboBox ->clear ();
1143
-
1144
- // QgsMapCanvas *canvas = mModule->qgisIface()->mapCanvas();
1170
+ void QgsGrassModuleVectorField::removeRow ()
1171
+ {
1172
+ QgsDebugMsg ( " entered" );
1145
1173
1146
- if ( mLayerInput == 0 )
1174
+ if ( mComboBoxList .size () < 2 )
1175
+ {
1147
1176
return ;
1177
+ }
1178
+ delete mComboBoxList .at ( mComboBoxList .size () - 1 );
1179
+ mComboBoxList .removeLast ();
1180
+ }
1148
1181
1149
- QgsFields fields = mLayerInput ->currentFields ();
1182
+ void QgsGrassModuleVectorField::updateFields ()
1183
+ {
1184
+ QgsDebugMsg ( " entered" );
1150
1185
1151
- for ( int i = 0 ; i < fields. size (); i++ )
1186
+ Q_FOREACH ( QComboBox *comboBox, mComboBoxList )
1152
1187
{
1153
- if ( mType .contains ( fields.at ( i ).typeName () ) )
1188
+ QString current = comboBox->currentText ();
1189
+ comboBox->clear ();
1190
+
1191
+ if ( mLayerInput == 0 )
1192
+ {
1193
+ continue ;
1194
+ }
1195
+ QgsFields fields = mLayerInput ->currentFields ();
1196
+
1197
+ int index = 0 ;
1198
+ for ( int i = 0 ; i < fields.size (); i++ )
1154
1199
{
1155
- mFieldComboBox ->addItem ( fields.at ( i ).name () );
1156
- if ( fields.at ( i ).name () == current )
1200
+ if ( mType .contains ( fields.at ( i ).typeName () ) )
1157
1201
{
1158
- mFieldComboBox ->setItemText ( mFieldComboBox ->currentIndex (), current );
1202
+ comboBox->addItem ( fields.at ( i ).name () );
1203
+ QgsDebugMsg ( " current = " + current + " field = " + fields.at ( i ).name () );
1204
+ if ( fields.at ( i ).name () == current )
1205
+ {
1206
+ comboBox->setCurrentIndex ( index );
1207
+ }
1208
+ index++;
1159
1209
}
1160
1210
}
1161
1211
}
@@ -1165,10 +1215,19 @@ QStringList QgsGrassModuleVectorField::options()
1165
1215
{
1166
1216
QStringList list;
1167
1217
1168
- if ( !mFieldComboBox ->currentText ().isEmpty () )
1218
+ QStringList valueList;
1219
+ Q_FOREACH ( QComboBox *comboBox, mComboBoxList )
1169
1220
{
1170
- QString opt ( mKey + " =" + mFieldComboBox ->currentText () );
1171
- list.push_back ( opt );
1221
+ if ( !comboBox->currentText ().isEmpty () )
1222
+ {
1223
+ valueList << comboBox->currentText ();
1224
+ }
1225
+ }
1226
+
1227
+ if ( !valueList.isEmpty () )
1228
+ {
1229
+ QString opt = mKey + " =" + valueList.join (" ," );
1230
+ list << opt;
1172
1231
}
1173
1232
1174
1233
return list;
0 commit comments