73
73
#include " qgsmapcanvas.h"
74
74
#include " qgsmaplayer.h"
75
75
#include " qgsvectorlayer.h"
76
+ #include < qgsrasterlayer.h>
76
77
#include " qgsdataprovider.h"
77
78
#include " qgsfield.h"
78
79
#include " qgsfeature.h"
@@ -89,6 +90,7 @@ extern "C" {
89
90
#include " qgsgrassmodule.h"
90
91
#include " qgsgrassmapcalc.h"
91
92
#include " qgsgrasstools.h"
93
+ #include " qgsgrassselect.h"
92
94
93
95
bool QgsGrassModule::mExecPathInited = 0 ;
94
96
QStringList QgsGrassModule::mExecPath ;
@@ -124,9 +126,7 @@ bool QgsGrassModule::inExecPath ( QString file )
124
126
125
127
QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
126
128
QString path, QWidget * parent, const char * name, Qt::WFlags f )
127
- // :QgsGrassModuleBase ( parent, name, f )
128
- // tim removed params during qt4 ui port - FIXME
129
- :QgsGrassModuleBase ( )
129
+ :QgsGrassModuleBase ( ), mSuccess(false )
130
130
{
131
131
#ifdef QGISDEBUG
132
132
std::cerr << " QgsGrassModule()" << std::endl;
@@ -214,6 +214,14 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
214
214
mOptions = new QgsGrassModuleStandardOptions ( mTools , this ,
215
215
mQgisApp , mIface , mXName , qDocElem, mTabWidget ->page (0 ) );
216
216
}
217
+
218
+ // Hide display if there is no output
219
+ if ( mOptions ->output (QgsGrassModuleOption::Vector).size () == 0
220
+ && mOptions ->output (QgsGrassModuleOption::Raster).size () == 0 )
221
+ {
222
+ mViewButton ->hide ();
223
+ }
224
+ mViewButton ->setEnabled (false );
217
225
218
226
// Create manual if available
219
227
QString gisBase = getenv (" GISBASE" );
@@ -477,6 +485,36 @@ QStringList QgsGrassModuleStandardOptions::checkOutput()
477
485
return list;
478
486
}
479
487
488
+ QStringList QgsGrassModuleStandardOptions::output (int type )
489
+ {
490
+ #ifdef QGISDEBUG
491
+ std::cerr << " QgsGrassModuleStandardOptions::output()" << std::endl;
492
+ #endif
493
+ QStringList list;
494
+
495
+ for ( int i = 0 ; i < mItems .size (); i++ )
496
+ {
497
+ if ( typeid (*(mItems [i])) != typeid (QgsGrassModuleOption) ) {
498
+ continue ;
499
+ }
500
+ QgsGrassModuleOption *opt =
501
+ dynamic_cast <QgsGrassModuleOption *> ( mItems [i] );
502
+
503
+ std::cerr << " opt->key() = " << opt->key ().ascii () << std::endl;
504
+
505
+ if ( opt->isOutput () )
506
+ {
507
+ if ( opt->outputType () == type )
508
+ {
509
+ QString out = opt->value ();
510
+ list.append ( out );
511
+ }
512
+ }
513
+ }
514
+
515
+ return list;
516
+ }
517
+
480
518
QStringList QgsGrassModuleStandardOptions::ready ()
481
519
{
482
520
#ifdef QGISDEBUG
@@ -700,6 +738,14 @@ void QgsGrassModule::run()
700
738
command.append ( " --o" );
701
739
}
702
740
}
741
+
742
+ // Remember output maps
743
+ mOutputVector = mOptions ->output (QgsGrassModuleOption::Vector);
744
+ std::cerr << " mOutputVector.size() = " << mOutputVector .size () << std::endl;
745
+ mOutputRaster = mOptions ->output (QgsGrassModuleOption::Raster);
746
+ std::cerr << " mOutputRaster.size() = " << mOutputRaster .size () << std::endl;
747
+ mSuccess = false ;
748
+ mViewButton ->setEnabled (false );
703
749
704
750
QStringList list = mOptions ->arguments ();
705
751
@@ -742,6 +788,8 @@ void QgsGrassModule::finished()
742
788
if ( mProcess .exitStatus () == 0 ) {
743
789
mOutputTextBrowser ->append ( " <B>Successfully finished</B>" );
744
790
mProgressBar ->setProgress ( 100 , 100 );
791
+ mSuccess = true ;
792
+ mViewButton ->setEnabled (true );
745
793
} else {
746
794
mOutputTextBrowser ->append ( " <B>Finished with error</B>" );
747
795
}
@@ -814,6 +862,50 @@ void QgsGrassModule::close()
814
862
delete this ;
815
863
}
816
864
865
+ void QgsGrassModule::viewOutput ()
866
+ {
867
+ #ifdef QGISDEBUG
868
+ std::cerr << " QgsGrassModule::viewOutput()" << std::endl;
869
+ #endif
870
+
871
+ if ( !mSuccess ) return ;
872
+
873
+ for (int i = 0 ; i < mOutputVector .size (); i++ )
874
+ {
875
+ QString map = mOutputVector .at (i);
876
+
877
+ QStringList layers = QgsGrassSelect::vectorLayers (
878
+ QgsGrass::getDefaultGisdbase (),
879
+ QgsGrass::getDefaultLocation (),
880
+ QgsGrass::getDefaultMapset (), map );
881
+
882
+ // TODO common method for add all layers
883
+ for ( int j = 0 ; j < layers.count (); j++ )
884
+ {
885
+ QString uri = QgsGrass::getDefaultGisdbase () + " /"
886
+ + QgsGrass::getDefaultLocation () + " /"
887
+ + QgsGrass::getDefaultMapset () + " /"
888
+ + map + " /" + layers[i];
889
+
890
+ // TODO vector layer name
891
+ mIface ->addVectorLayer ( uri, layers[i], " grass" );
892
+ }
893
+ }
894
+
895
+ for (int i = 0 ; i < mOutputRaster .size (); i++ )
896
+ {
897
+ QString map = mOutputRaster .at (i);
898
+
899
+ QString uri = QgsGrass::getDefaultGisdbase () + " /"
900
+ + QgsGrass::getDefaultLocation () + " /"
901
+ + QgsGrass::getDefaultMapset ()
902
+ + " /cellhd/" + map;
903
+
904
+ QgsRasterLayer *layer = new QgsRasterLayer ( uri, map );
905
+ mIface ->addRasterLayer (layer);
906
+ }
907
+ }
908
+
817
909
QgisIface *QgsGrassModule::qgisIface () { return mIface ; }
818
910
QgisApp *QgsGrassModule::qgisApp () { return mQgisApp ; }
819
911
@@ -854,7 +946,7 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
854
946
QWidget * parent)
855
947
: QGroupBox ( parent ),
856
948
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
857
- mIsOutput(false ), mValueType(String), mHaveLimits(false )
949
+ mIsOutput(false ), mValueType(String), mHaveLimits(false ), mOutputType(None)
858
950
{
859
951
#ifdef QGISDEBUG
860
952
std::cerr << " QgsGrassModuleOption::QgsGrassModuleOption" << std::endl;
@@ -880,10 +972,20 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
880
972
QDomElement promptElem = promptNode.toElement ();
881
973
QString element = promptElem.attribute (" element" );
882
974
QString age = promptElem.attribute (" age" );
975
+
883
976
if ( age == " new" )
884
977
{
885
978
mOutputElement = element;
886
979
mIsOutput = true ;
980
+
981
+ if ( element == " vector" )
982
+ {
983
+ mOutputType = Vector;
984
+ }
985
+ else if ( element == " cell" )
986
+ {
987
+ mOutputType = Raster;
988
+ }
887
989
}
888
990
}
889
991
@@ -1086,38 +1188,46 @@ QString QgsGrassModuleOption::outputExists()
1086
1188
return QString ();
1087
1189
}
1088
1190
1191
+ QString QgsGrassModuleOption::value ()
1192
+ {
1193
+ QString value;
1194
+
1195
+ if ( mControlType == LineEdit ) {
1196
+ for ( int i = 0 ; i < mLineEdits .size (); i++ )
1197
+ {
1198
+ QLineEdit *lineEdit = mLineEdits .at (i);
1199
+ if ( lineEdit->text ().trimmed ().length () > 0 )
1200
+ {
1201
+ if ( value.length () > 0 ) value.append (" ," );
1202
+ value.append ( lineEdit->text ().trimmed () );
1203
+ }
1204
+ }
1205
+ }
1206
+ else if ( mControlType == ComboBox )
1207
+ {
1208
+ value = mValues [mComboBox ->currentItem ()];
1209
+ }
1210
+ else if ( mControlType == CheckBoxes )
1211
+ {
1212
+ int cnt = 0 ;
1213
+ for ( int i = 0 ; i < mCheckBoxes .size (); i++ ) {
1214
+ if ( mCheckBoxes [i]->isChecked () ) {
1215
+ if ( cnt > 0 ) value.append ( " ," );
1216
+ value.append ( mValues [i] );
1217
+ }
1218
+ }
1219
+ }
1220
+ return value;
1221
+ }
1222
+
1089
1223
QStringList QgsGrassModuleOption::options ()
1090
1224
{
1091
1225
QStringList list;
1092
1226
1093
1227
if ( mHidden ) {
1094
1228
list.push_back ( mKey + " =" + mAnswer );
1095
1229
} else {
1096
- if ( mControlType == LineEdit ) {
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 );
1108
- } else if ( mControlType == ComboBox ) {
1109
- list.push_back ( mKey + " =" + mValues [mComboBox ->currentItem ()] );
1110
- } else if ( mControlType == CheckBoxes ) {
1111
- QString opt = mKey + " =" ;
1112
- int cnt = 0 ;
1113
- for ( int i = 0 ; i < mCheckBoxes .size (); i++ ) {
1114
- if ( mCheckBoxes [i]->isChecked () ) {
1115
- if ( cnt > 0 ) opt.append ( " ," );
1116
- opt.append ( mValues [i] );
1117
- }
1118
- }
1119
- list.push_back ( opt );
1120
- }
1230
+ list.push_back ( mKey + " =" + value () );
1121
1231
}
1122
1232
return list;
1123
1233
}
0 commit comments