Skip to content

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed
 

‎src/plugins/grass/qgsgrassmodule.cpp

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -809,31 +809,31 @@ bool QgsGrassModuleStandardOptions::usesRegion ()
809809
#ifdef QGISDEBUG
810810
std::cerr << "QgsGrassModuleStandardOptions::usesRegion()" << std::endl;
811811
#endif
812-
812+
813813
for ( int i = 0; i < mItems.size(); i++ )
814814
{
815815
if ( typeid(*(mItems[i])) == typeid (QgsGrassModuleInput) )
816816
{
817817
QgsGrassModuleInput *item =
818818
dynamic_cast<QgsGrassModuleInput *>(mItems[i]);
819819

820-
if ( item->type() == QgsGrassModuleInput::Raster )
820+
if ( item->useRegion() )
821821
return true;
822822
}
823823

824+
/* It only make sense to check input, right?
825+
* Output has no region yet */
824826
if ( typeid(*(mItems[i])) == typeid (QgsGrassModuleOption) )
825827
{
826828
QgsGrassModuleOption *item =
827829
dynamic_cast<QgsGrassModuleOption *> ( mItems[i] );
828830

829-
if ( item->isOutput()
830-
&& item->outputType() == QgsGrassModuleOption::Raster )
831-
{
831+
if ( item->usesRegion() )
832832
return true;
833-
}
834833
}
835834
}
836835

836+
std::cerr << "NO usesRegion()" << std::endl;
837837
return false;
838838
}
839839

@@ -1583,6 +1583,23 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
15831583
}
15841584
}
15851585
}
1586+
1587+
mUsesRegion = false;
1588+
QString region = qdesc.attribute("region");
1589+
if ( region.length() > 0 )
1590+
{
1591+
if ( region == "yes" )
1592+
mUsesRegion = true;
1593+
}
1594+
else
1595+
{
1596+
std::cerr << "\n\n\n\n**************************" << std::endl;
1597+
std::cerr << "isOutput = " << isOutput() << std::endl;
1598+
std::cerr << "mOutputType = " << mOutputType << std::endl;
1599+
if ( isOutput() && mOutputType == Raster )
1600+
mUsesRegion = true;
1601+
}
1602+
std::cerr << "mUsesRegion = " << mUsesRegion << std::endl;
15861603
}
15871604

15881605
void QgsGrassModuleOption::addLineEdit()
@@ -1908,8 +1925,11 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
19081925
QSizePolicy:: Preferred );
19091926
l->addWidget ( mLayerComboBox );
19101927

1911-
if ( mType == Raster &&
1912-
QgsGrass::versionMajor() >= 6 && QgsGrass::versionMinor() >= 1 )
1928+
QString region = qdesc.attribute("region");
1929+
if ( mType == Raster
1930+
&& QgsGrass::versionMajor() >= 6 && QgsGrass::versionMinor() >= 1
1931+
&& region != "no"
1932+
)
19131933
{
19141934
QString iconPath = QgsApplication::themePath() + "/grass/";
19151935

@@ -1943,6 +1963,18 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
19431963
connect ( mapInput, SIGNAL(valueChanged()), this, SLOT(updateQgisLayers()) );
19441964
}
19451965
}
1966+
1967+
mUsesRegion = false;
1968+
if ( region.length() > 0 )
1969+
{
1970+
if ( region == "yes" )
1971+
mUsesRegion = true;
1972+
}
1973+
else
1974+
{
1975+
if ( type() == Raster )
1976+
mUsesRegion = true;
1977+
}
19461978

19471979
// Fill in QGIS layers
19481980
updateQgisLayers();
@@ -1952,7 +1984,7 @@ bool QgsGrassModuleInput::useRegion()
19521984
{
19531985
std::cerr << "QgsGrassModuleInput::useRegion()" << std::endl;
19541986

1955-
if ( mType == Raster && mRegionButton &&
1987+
if ( mUsesRegion && mType == Raster && mRegionButton &&
19561988
mRegionButton->isChecked() )
19571989
{
19581990
return true;
@@ -2344,8 +2376,11 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
23442376

23452377
// Connect to canvas
23462378
QgsMapCanvas *canvas = mModule->qgisIface()->getMapCanvas();
2347-
connect ( canvas, SIGNAL(addedLayer(QgsMapLayer *)), this, SLOT(updateQgisLayers()) );
2348-
connect ( canvas, SIGNAL(removedLayer(QString)), this, SLOT(updateQgisLayers()) );
2379+
2380+
// It seems that addedLayer/removedLayer does not work
2381+
//connect ( canvas, SIGNAL(addedLayer(QgsMapLayer *)), this, SLOT(updateQgisLayers()) );
2382+
//connect ( canvas, SIGNAL(removedLayer(QString)), this, SLOT(updateQgisLayers()) );
2383+
connect ( canvas, SIGNAL(layersChanged()), this, SLOT(updateQgisLayers()) );
23492384

23502385
// Fill in QGIS layers
23512386
updateQgisLayers();

‎src/plugins/grass/qgsgrassmodule.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget
290290

291291
//! List of all flags. Necessary for scripts.
292292
QStringList mFlagNames;
293+
294+
//! Use of region defined in qgm
295+
bool mUsesRegion;
293296
};
294297

295298
/*! \class QgsGrassModuleItem
@@ -397,6 +400,11 @@ class QgsGrassModuleOption: public QGroupBox, public QgsGrassModuleItem
397400
//! Current value
398401
QString value();
399402

403+
//! Does this options causes use of region?
404+
// Raster input/output uses region by default
405+
// Use of region can be forced by 'region' attribute in qgm
406+
bool usesRegion() { return mUsesRegion; }
407+
400408
public slots:
401409
// Add new line edit for multiple options
402410
void addLineEdit();
@@ -441,6 +449,9 @@ public slots:
441449

442450
// Layout inside box
443451
QVBoxLayout *mLayout;
452+
453+
//! Uses region
454+
bool mUsesRegion;
444455
};
445456
/********************** QgsGrassModuleFlag ************************/
446457
/*! \class QgsGrassModuleFlag
@@ -503,6 +514,11 @@ class QgsGrassModuleInput: public QGroupBox, public QgsGrassModuleItem
503514

504515
QString ready() ;
505516

517+
//! Does this options causes use of region?
518+
// Raster input/output uses region by default
519+
// Use of region can be forced by 'region' attribute in qgm
520+
bool usesRegion() { return mUsesRegion; }
521+
506522
//! Should be used region of this input
507523
bool useRegion();
508524

@@ -563,6 +579,9 @@ public slots:
563579

564580
//! The imput map will be updated -> must be from current mapset
565581
bool mUpdate;
582+
583+
//! Uses region
584+
bool mUsesRegion;
566585
};
567586

568587
/*********************** QgsGrassModuleGdalInput **********************/

0 commit comments

Comments
 (0)
Please sign in to comment.