61
61
#include < qimage.h>
62
62
// Added by qt3to4:
63
63
#include < QVBoxLayout>
64
+ #include < QHBoxLayout>
64
65
#include < QGridLayout>
65
66
#include < QIntValidator>
66
67
#include < QDoubleValidator>
68
+ #include < QPushButton>
69
+ #include < QGroupBox>
67
70
68
71
#include " qgis.h"
69
72
#include " qgsapplication.h"
@@ -405,9 +408,7 @@ QgsGrassModuleStandardOptions::QgsGrassModuleStandardOptions (
405
408
n = n.nextSibling ();
406
409
}
407
410
408
- QSpacerItem *si = new QSpacerItem ( 10 , 10 , QSizePolicy::Minimum, QSizePolicy::Expanding );
409
- layout->addItem ( si );
410
-
411
+ layout->addStretch ();
411
412
}
412
413
413
414
QStringList QgsGrassModuleStandardOptions::arguments ()
@@ -446,6 +447,55 @@ QgsGrassModuleItem *QgsGrassModuleStandardOptions::item ( QString id )
446
447
return 0 ;
447
448
}
448
449
450
+ QStringList QgsGrassModuleStandardOptions::checkOutput ()
451
+ {
452
+ #ifdef QGISDEBUG
453
+ std::cerr << " QgsGrassModuleStandardOptions::checkOutput()" << std::endl;
454
+ #endif
455
+ QStringList list;
456
+
457
+ for ( int i = 0 ; i < mItems .size (); i++ )
458
+ {
459
+ if ( typeid (*(mItems [i])) != typeid (QgsGrassModuleOption) ) {
460
+ continue ;
461
+ }
462
+ QgsGrassModuleOption *opt =
463
+ dynamic_cast <QgsGrassModuleOption *> ( mItems [i] );
464
+
465
+ std::cerr << " opt->key() = " << opt->key ().ascii () << std::endl;
466
+
467
+ if ( opt->isOutput () )
468
+ {
469
+ QString out = opt->outputExists ();
470
+ if ( !out.isNull () )
471
+ {
472
+ list.append ( out );
473
+ }
474
+ }
475
+ }
476
+
477
+ return list;
478
+ }
479
+
480
+ QStringList QgsGrassModuleStandardOptions::ready ()
481
+ {
482
+ #ifdef QGISDEBUG
483
+ std::cerr << " QgsGrassModuleStandardOptions::ready()" << std::endl;
484
+ #endif
485
+ QStringList list;
486
+
487
+ for ( int i = 0 ; i < mItems .size (); i++ )
488
+ {
489
+ QString err = mItems [i]->ready ();
490
+ if ( !err.isNull () )
491
+ {
492
+ list.append ( err );
493
+ }
494
+ }
495
+
496
+ return list;
497
+ }
498
+
449
499
QgsGrassModuleStandardOptions::~QgsGrassModuleStandardOptions ()
450
500
{
451
501
}
@@ -619,6 +669,19 @@ void QgsGrassModule::run()
619
669
mProcess .addArgument ( mXName );
620
670
command = mXName ;
621
671
672
+ // Check if options are ready
673
+ QStringList readyErrors = mOptions ->ready ();
674
+ if ( readyErrors.size () > 0 )
675
+ {
676
+ QString err;
677
+ for ( int i = 0 ; i < readyErrors.size (); i++ )
678
+ {
679
+ err.append ( readyErrors.at (i) + " <br>" );
680
+ }
681
+ QMessageBox::warning ( 0 , " Warning" , err );
682
+ return ;
683
+ }
684
+
622
685
// Check if output exists
623
686
QStringList outputExists = mOptions ->checkOutput ();
624
687
if ( outputExists.size () > 0 )
@@ -789,16 +852,18 @@ QDomNode QgsGrassModule::nodeByKey ( QDomElement elem, QString key )
789
852
QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module , QString key,
790
853
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
791
854
QWidget * parent)
792
- : Q3GroupBox ( 1 , Qt::Vertical, parent ),
855
+ : QGroupBox ( parent ),
793
856
QgsGrassModuleItem ( module , key, qdesc, gdesc, gnode ),
794
- mIsOutput(false ), mValueType(String)
857
+ mIsOutput(false ), mValueType(String), mHaveLimits( false )
795
858
{
796
859
#ifdef QGISDEBUG
797
860
std::cerr << " QgsGrassModuleOption::QgsGrassModuleOption" << std::endl;
798
861
#endif
799
- setSizePolicy ( QSizePolicy::Preferred , QSizePolicy::Minimum );
862
+ setSizePolicy ( QSizePolicy::MinimumExpanding , QSizePolicy::Minimum );
800
863
801
864
if ( mHidden ) hide ();
865
+
866
+ mLayout = new QVBoxLayout ();
802
867
803
868
QString tit;
804
869
if ( mDescription .length () > 40 ) {
@@ -833,6 +898,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
833
898
834
899
if ( !valuesNode.isNull () && valuesNode.childNodes ().count () > 1 )
835
900
{
901
+ setLayout (mLayout );
836
902
// predefined values -> ComboBox or CheckBox
837
903
838
904
// one or many?
@@ -841,6 +907,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
841
907
} else {
842
908
mControlType = ComboBox;
843
909
mComboBox = new QComboBox ( this );
910
+ mLayout ->addWidget ( mComboBox );
844
911
}
845
912
846
913
// List of values to be excluded
@@ -875,6 +942,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
875
942
} else {
876
943
QCheckBox *cb = new QCheckBox ( desc, this );
877
944
mCheckBoxes .push_back ( cb );
945
+ mLayout ->addWidget ( cb );
878
946
}
879
947
880
948
mValues .push_back ( val );
@@ -890,12 +958,17 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
890
958
// Line edit
891
959
mControlType = LineEdit;
892
960
893
- mLineEdit = new QLineEdit ( this );
894
961
QDomNode n = gnode.namedItem ( " default" );
895
962
if ( !n.isNull () ) {
896
963
QDomElement e = n.toElement ();
897
- QString def = e.text ().stripWhiteSpace ();
898
- mLineEdit ->setText ( def );
964
+ mDefault = e.text ().stripWhiteSpace ();
965
+ }
966
+
967
+ if ( gelem.attribute (" type" ) == " integer" )
968
+ {
969
+ mValueType = Integer;
970
+ } else if ( gelem.attribute (" type" ) == " float" ) {
971
+ mValueType = Double;
899
972
}
900
973
901
974
QStringList minMax;
@@ -908,39 +981,90 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
908
981
QDomElement e = n.toElement ();
909
982
QString val = e.text ().stripWhiteSpace ();
910
983
minMax = val.split (" -" );
984
+ if ( minMax.size () == 2 )
985
+ {
986
+ mHaveLimits = true ;
987
+ mMin = minMax.at (0 ).toDouble ();
988
+ mMax = minMax.at (1 ).toDouble ();
989
+ }
911
990
}
912
991
}
913
- if ( gelem.attribute (" type" ) == " integer" )
992
+
993
+ addLineEdit ();
994
+
995
+ // add/delete buttons for multiple options
996
+ if ( gelem.attribute (" multiple" ) == " yes" )
914
997
{
915
- mValueType = Integer;
916
- if ( minMax.size () == 2 ) {
917
- mValidator = new QIntValidator ( minMax.at (0 ).toInt (),
918
- minMax.at (1 ).toInt (), this );
919
- } else {
920
- mValidator = new QIntValidator ( this );
921
- }
922
- mLineEdit ->setValidator ( mValidator );
923
- } else if ( gelem.attribute (" type" ) == " float" ) {
924
- mValueType = Double;
925
- if ( minMax.size () == 2 ) {
926
- mValidator = new QDoubleValidator ( minMax.at (0 ).toDouble (),
927
- minMax.at (1 ).toDouble (), 10 , this );
928
- } else {
929
- mValidator = new QDoubleValidator ( this );
930
- }
931
- mLineEdit ->setValidator ( mValidator );
932
- }
998
+ QHBoxLayout *l = new QHBoxLayout (this );
999
+ QVBoxLayout *vl = new QVBoxLayout ();
1000
+ l->insertLayout ( -1 , mLayout );
1001
+ l->insertLayout ( -1 , vl );
1002
+
1003
+ // TODO: how to keep both buttons on the top?
1004
+ QPushButton *b = new QPushButton ( " +" , this );
1005
+ connect ( b, SIGNAL (clicked ()), this , SLOT (addLineEdit ()) );
1006
+ vl->addWidget ( b, 0 , Qt::AlignTop );
1007
+
1008
+ b = new QPushButton ( " -" , this );
1009
+ connect ( b, SIGNAL (clicked ()), this , SLOT (removeLineEdit ()) );
1010
+ vl->addWidget ( b, 0 , Qt::AlignTop );
1011
+
1012
+ // Dont enable this, it makes the group box expanding
1013
+ // vl->addStretch();
1014
+ }
1015
+ else
1016
+ {
1017
+ setLayout ( mLayout );
1018
+ }
933
1019
}
934
1020
}
935
1021
}
936
1022
1023
+ void QgsGrassModuleOption::addLineEdit ()
1024
+ {
1025
+ std::cerr << " QgsGrassModuleOption::addLineEdit()" << std::endl;
1026
+
1027
+ // TODO make the widget growing with new lines. HOW???!!!
1028
+ QLineEdit *lineEdit = new QLineEdit ( this );
1029
+ mLineEdits .push_back (lineEdit );
1030
+ lineEdit->setText ( mDefault );
1031
+
1032
+ if ( mValueType == Integer )
1033
+ {
1034
+ if ( mHaveLimits ) {
1035
+ mValidator = new QIntValidator ( (int )mMin , (int )mMax , this );
1036
+ } else {
1037
+ mValidator = new QIntValidator ( this );
1038
+ }
1039
+ lineEdit->setValidator ( mValidator );
1040
+ } else if ( mValueType == Double ) {
1041
+ if ( mHaveLimits ) {
1042
+ mValidator = new QDoubleValidator ( mMin , mMax , 10 , this );
1043
+ } else {
1044
+ mValidator = new QDoubleValidator ( this );
1045
+ }
1046
+ lineEdit->setValidator ( mValidator );
1047
+ }
1048
+
1049
+ mLayout ->addWidget ( lineEdit );
1050
+ }
1051
+
1052
+ void QgsGrassModuleOption::removeLineEdit ()
1053
+ {
1054
+ std::cerr << " QgsGrassModuleOption::removeLineEdit()" << std::endl;
1055
+ if ( mLineEdits .size () < 2 ) return ;
1056
+ delete mLineEdits .at (mLineEdits .size ()-1 );
1057
+ mLineEdits .pop_back ();
1058
+ }
1059
+
937
1060
QString QgsGrassModuleOption::outputExists ()
938
1061
{
939
1062
std::cerr << " QgsGrassModuleOption::outputExists()" << std::endl;
940
1063
941
1064
if ( !mIsOutput ) return QString ();
942
1065
943
- QString value = mLineEdit ->text ().trimmed ();
1066
+ QLineEdit *lineEdit = mLineEdits .at (0 );
1067
+ QString value = lineEdit->text ().trimmed ();
944
1068
std::cerr << " mKey = " << mKey .ascii () << std::endl;
945
1069
std::cerr << " value = " << value.ascii () << std::endl;
946
1070
std::cerr << " mOutputElement = " << mOutputElement .ascii () << std::endl;
@@ -956,7 +1080,7 @@ QString QgsGrassModuleOption::outputExists()
956
1080
957
1081
if ( fi.exists () )
958
1082
{
959
- return (mLineEdit ->text ());
1083
+ return (lineEdit ->text ());
960
1084
}
961
1085
962
1086
return QString ();
@@ -970,7 +1094,17 @@ QStringList QgsGrassModuleOption::options()
970
1094
list.push_back ( mKey + " =" + mAnswer );
971
1095
} else {
972
1096
if ( mControlType == LineEdit ) {
973
- list.push_back ( mKey + " =" + mLineEdit ->text () );
1097
+ QString vals;
1098
+ for ( int i = 0 ; i < mLineEdits .size (); i++ )
1099
+ {
1100
+ QLineEdit *lineEdit = mLineEdits .at (i);
1101
+ if ( lineEdit->text ().trimmed ().length () > 0 )
1102
+ {
1103
+ if ( vals.length () > 0 ) vals.append (" ," );
1104
+ vals.append ( lineEdit->text ().trimmed () );
1105
+ }
1106
+ }
1107
+ list.push_back ( mKey + " =" + vals );
974
1108
} else if ( mControlType == ComboBox ) {
975
1109
list.push_back ( mKey + " =" + mValues [mComboBox ->currentItem ()] );
976
1110
} else if ( mControlType == CheckBoxes ) {
@@ -988,6 +1122,24 @@ QStringList QgsGrassModuleOption::options()
988
1122
return list;
989
1123
}
990
1124
1125
+ QString QgsGrassModuleOption::ready ()
1126
+ {
1127
+ #ifdef QGISDEBUG
1128
+ std::cerr << " QgsGrassModuleOption::ready()" << std::endl;
1129
+ #endif
1130
+
1131
+ QString error;
1132
+
1133
+ if ( mControlType == LineEdit )
1134
+ {
1135
+ if ( mLineEdits .at (0 )->text ().trimmed ().length () == 0 )
1136
+ {
1137
+ error.append ( title () + " : missing value" );
1138
+ }
1139
+ }
1140
+ return error;
1141
+ }
1142
+
991
1143
QgsGrassModuleOption::~QgsGrassModuleOption ()
992
1144
{
993
1145
}
@@ -1190,36 +1342,6 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
1190
1342
updateQgisLayers ();
1191
1343
}
1192
1344
1193
- QStringList QgsGrassModuleStandardOptions::checkOutput ()
1194
- {
1195
- #ifdef QGISDEBUG
1196
- std::cerr << " QgsGrassModuleStandardOptions::checkOutput()" << std::endl;
1197
- #endif
1198
- QStringList list;
1199
-
1200
- for ( int i = 0 ; i < mItems .size (); i++ )
1201
- {
1202
- if ( typeid (*(mItems [i])) != typeid (QgsGrassModuleOption) ) {
1203
- continue ;
1204
- }
1205
- QgsGrassModuleOption *opt =
1206
- dynamic_cast <QgsGrassModuleOption *> ( mItems [i] );
1207
-
1208
- std::cerr << " opt->key() = " << opt->key ().ascii () << std::endl;
1209
-
1210
- if ( opt->isOutput () )
1211
- {
1212
- QString out = opt->outputExists ();
1213
- if ( !out.isNull () )
1214
- {
1215
- list.append ( out );
1216
- }
1217
- }
1218
- }
1219
-
1220
- return list;
1221
- }
1222
-
1223
1345
void QgsGrassModuleInput::updateQgisLayers ()
1224
1346
{
1225
1347
#ifdef QGISDEBUG
@@ -1469,6 +1591,22 @@ void QgsGrassModuleInput::changed(int i)
1469
1591
emit valueChanged ();
1470
1592
}
1471
1593
1594
+ QString QgsGrassModuleInput::ready ()
1595
+ {
1596
+ #ifdef QGISDEBUG
1597
+ std::cerr << " QgsGrassModuleInput::ready()" << std::endl;
1598
+ #endif
1599
+
1600
+ QString error;
1601
+
1602
+ std::cerr << " count = " << mLayerComboBox ->count () << std::endl;
1603
+ if ( mLayerComboBox ->count () == 0 )
1604
+ {
1605
+ error.append ( title () + " : no input" );
1606
+ }
1607
+ return error;
1608
+ }
1609
+
1472
1610
QgsGrassModuleInput::~QgsGrassModuleInput ()
1473
1611
{
1474
1612
}
0 commit comments