Skip to content

Commit

Permalink
region tag to force region use, especially import/export
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5431 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed May 9, 2006
1 parent 79d00c0 commit c07ef21
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
57 changes: 46 additions & 11 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,31 +809,31 @@ bool QgsGrassModuleStandardOptions::usesRegion ()
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleStandardOptions::usesRegion()" << std::endl;
#endif

for ( int i = 0; i < mItems.size(); i++ )
{
if ( typeid(*(mItems[i])) == typeid (QgsGrassModuleInput) )
{
QgsGrassModuleInput *item =
dynamic_cast<QgsGrassModuleInput *>(mItems[i]);

if ( item->type() == QgsGrassModuleInput::Raster )
if ( item->useRegion() )
return true;
}

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

if ( item->isOutput()
&& item->outputType() == QgsGrassModuleOption::Raster )
{
if ( item->usesRegion() )
return true;
}
}
}

std::cerr << "NO usesRegion()" << std::endl;
return false;
}

Expand Down Expand Up @@ -1583,6 +1583,23 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
}
}
}

mUsesRegion = false;
QString region = qdesc.attribute("region");
if ( region.length() > 0 )
{
if ( region == "yes" )
mUsesRegion = true;
}
else
{
std::cerr << "\n\n\n\n**************************" << std::endl;
std::cerr << "isOutput = " << isOutput() << std::endl;
std::cerr << "mOutputType = " << mOutputType << std::endl;
if ( isOutput() && mOutputType == Raster )
mUsesRegion = true;
}
std::cerr << "mUsesRegion = " << mUsesRegion << std::endl;
}

void QgsGrassModuleOption::addLineEdit()
Expand Down Expand Up @@ -1908,8 +1925,11 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
QSizePolicy:: Preferred );
l->addWidget ( mLayerComboBox );

if ( mType == Raster &&
QgsGrass::versionMajor() >= 6 && QgsGrass::versionMinor() >= 1 )
QString region = qdesc.attribute("region");
if ( mType == Raster
&& QgsGrass::versionMajor() >= 6 && QgsGrass::versionMinor() >= 1
&& region != "no"
)
{
QString iconPath = QgsApplication::themePath() + "/grass/";

Expand Down Expand Up @@ -1943,6 +1963,18 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
connect ( mapInput, SIGNAL(valueChanged()), this, SLOT(updateQgisLayers()) );
}
}

mUsesRegion = false;
if ( region.length() > 0 )
{
if ( region == "yes" )
mUsesRegion = true;
}
else
{
if ( type() == Raster )
mUsesRegion = true;
}

// Fill in QGIS layers
updateQgisLayers();
Expand All @@ -1952,7 +1984,7 @@ bool QgsGrassModuleInput::useRegion()
{
std::cerr << "QgsGrassModuleInput::useRegion()" << std::endl;

if ( mType == Raster && mRegionButton &&
if ( mUsesRegion && mType == Raster && mRegionButton &&
mRegionButton->isChecked() )
{
return true;
Expand Down Expand Up @@ -2344,8 +2376,11 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (

// Connect to canvas
QgsMapCanvas *canvas = mModule->qgisIface()->getMapCanvas();
connect ( canvas, SIGNAL(addedLayer(QgsMapLayer *)), this, SLOT(updateQgisLayers()) );
connect ( canvas, SIGNAL(removedLayer(QString)), this, SLOT(updateQgisLayers()) );

// It seems that addedLayer/removedLayer does not work
//connect ( canvas, SIGNAL(addedLayer(QgsMapLayer *)), this, SLOT(updateQgisLayers()) );
//connect ( canvas, SIGNAL(removedLayer(QString)), this, SLOT(updateQgisLayers()) );
connect ( canvas, SIGNAL(layersChanged()), this, SLOT(updateQgisLayers()) );

// Fill in QGIS layers
updateQgisLayers();
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget

//! List of all flags. Necessary for scripts.
QStringList mFlagNames;

//! Use of region defined in qgm
bool mUsesRegion;
};

/*! \class QgsGrassModuleItem
Expand Down Expand Up @@ -397,6 +400,11 @@ class QgsGrassModuleOption: public QGroupBox, public QgsGrassModuleItem
//! Current value
QString value();

//! Does this options causes use of region?
// Raster input/output uses region by default
// Use of region can be forced by 'region' attribute in qgm
bool usesRegion() { return mUsesRegion; }

public slots:
// Add new line edit for multiple options
void addLineEdit();
Expand Down Expand Up @@ -441,6 +449,9 @@ public slots:

// Layout inside box
QVBoxLayout *mLayout;

//! Uses region
bool mUsesRegion;
};
/********************** QgsGrassModuleFlag ************************/
/*! \class QgsGrassModuleFlag
Expand Down Expand Up @@ -503,6 +514,11 @@ class QgsGrassModuleInput: public QGroupBox, public QgsGrassModuleItem

QString ready() ;

//! Does this options causes use of region?
// Raster input/output uses region by default
// Use of region can be forced by 'region' attribute in qgm
bool usesRegion() { return mUsesRegion; }

//! Should be used region of this input
bool useRegion();

Expand Down Expand Up @@ -563,6 +579,9 @@ public slots:

//! The imput map will be updated -> must be from current mapset
bool mUpdate;

//! Uses region
bool mUsesRegion;
};

/*********************** QgsGrassModuleGdalInput **********************/
Expand Down

0 comments on commit c07ef21

Please sign in to comment.