Skip to content

Commit

Permalink
set region to input option
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5083 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 23, 2006
1 parent b8c82ab commit f8aa37e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 10 deletions.
75 changes: 68 additions & 7 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -580,9 +580,13 @@ QStringList QgsGrassModuleStandardOptions::checkRegion()
break;
}

QStringList mm = item->currentMap().split("@");
QString map = mm.at(0);
QString mapset = QgsGrass::getDefaultMapset();
if ( mm.size() > 1 ) mapset = mm.at(1);
if ( !QgsGrass::mapRegion ( mapType,
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(), "", item->currentMap(),
QgsGrass::getDefaultLocation(), mapset, map,
&window ) )
{
QMessageBox::warning( 0, "Warning", "Cannot check region "
Expand Down Expand Up @@ -623,13 +627,13 @@ bool QgsGrassModuleStandardOptions::inputRegion ( struct Cell_head *window, bool
continue;
}

// TODO all flag

struct Cell_head mapWindow;

QgsGrassModuleInput *item = dynamic_cast<QgsGrassModuleInput *>
(mItems[i]);

if ( !all && !item->useRegion() ) continue;

int mapType;
switch ( item->type() ) {
case QgsGrassModuleInput::Raster :
Expand All @@ -640,9 +644,13 @@ bool QgsGrassModuleStandardOptions::inputRegion ( struct Cell_head *window, bool
break;
}

QStringList mm = item->currentMap().split("@");
QString map = mm.at(0);
QString mapset = QgsGrass::getDefaultMapset();
if ( mm.size() > 1 ) mapset = mm.at(1);
if ( !QgsGrass::mapRegion ( mapType,
QgsGrass::getDefaultGisdbase(),
QgsGrass::getDefaultLocation(), "", item->currentMap(),
QgsGrass::getDefaultLocation(), mapset, map,
&mapWindow ) )
{
QMessageBox::warning( 0, "Warning", "Cannot set region "
Expand Down Expand Up @@ -676,6 +684,26 @@ bool QgsGrassModuleStandardOptions::inputRegion ( struct Cell_head *window, bool
return true;
}

bool QgsGrassModuleStandardOptions::requestsRegion()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleStandardOptions::requestsRegion()" << std::endl;
#endif

for ( int i = 0; i < mItems.size(); i++ )
{
if ( typeid(*(mItems[i])) != typeid (QgsGrassModuleInput) ) {
continue;
}

QgsGrassModuleInput *item = dynamic_cast<QgsGrassModuleInput *>
(mItems[i]);

if ( item->useRegion() ) return true;
}
return false;
}

bool QgsGrassModuleStandardOptions::usesRegion ()
{
#ifdef QGISDEBUG
Expand Down Expand Up @@ -1559,10 +1587,11 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
QgsGrassModuleStandardOptions *options, QString key,
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
QWidget * parent)
: Q3GroupBox ( 1, Qt::Vertical, parent ),
: QGroupBox ( parent ),
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
mModuleStandardOptions(options),
mUpdate(false), mVectorTypeOption(0), mVectorLayerOption(0)
mUpdate(false), mVectorTypeOption(0), mVectorLayerOption(0),
mRegionButton(0)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleInput::QgsGrassModuleInput" << std::endl;
Expand Down Expand Up @@ -1692,7 +1721,26 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
mUpdate = true;
}

mLayerComboBox = new QComboBox ( this );
QHBoxLayout *l = new QHBoxLayout (this);
mLayerComboBox = new QComboBox ();
mLayerComboBox->setSizePolicy (QSizePolicy::Expanding,
QSizePolicy:: Preferred );
l->addWidget ( mLayerComboBox );

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

mRegionButton = new QPushButton(
QIcon(iconPath+"grass_set_region.png"), "" );

mRegionButton->setToolTip ( "Use region of this map" );
mRegionButton->setCheckable ( true );
mRegionButton->setSizePolicy (QSizePolicy::Minimum,
QSizePolicy:: Preferred );
l->addWidget ( mRegionButton );
}

// Of course, activated(int) is not enough, but there is no signal BEFORE the cobo is opened
//connect ( mLayerComboBox, SIGNAL( activated(int) ), this, SLOT(updateQgisLayers()) );
Expand All @@ -1719,6 +1767,19 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
updateQgisLayers();
}

bool QgsGrassModuleInput::useRegion()
{
std::cerr << "QgsGrassModuleInput::useRegion()" << std::endl;

if ( mType == Raster && mRegionButton &&
mRegionButton->isChecked() )
{
return true;
}

return false;
}

void QgsGrassModuleInput::updateQgisLayers()
{
#ifdef QGISDEBUG
Expand Down
12 changes: 9 additions & 3 deletions src/plugins/grass/qgsgrassmodule.h
Expand Up @@ -197,7 +197,7 @@ class QgsGrassModuleOptions
virtual bool usesRegion() { return false; }

//! One or more input maps were swithched on to be used as region
bool requestsRegion() { return false; }
virtual bool requestsRegion() { return false; }

//! Check region
// return empty list
Expand Down Expand Up @@ -261,7 +261,7 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget
QStringList output(int type);
QStringList checkRegion();
bool usesRegion();
bool requestsRegion() { return false; } // TODO
bool requestsRegion();
bool inputRegion( struct Cell_head *window, bool all );

private:
Expand Down Expand Up @@ -455,7 +455,7 @@ class QgsGrassModuleFlag: public QCheckBox, public QgsGrassModuleItem
/*! \class QgsGrassModuleInput
* \brief Class representing raster or vector module input
*/
class QgsGrassModuleInput: public Q3GroupBox, public QgsGrassModuleItem
class QgsGrassModuleInput: public QGroupBox, public QgsGrassModuleItem
{
Q_OBJECT;

Expand Down Expand Up @@ -487,6 +487,9 @@ class QgsGrassModuleInput: public Q3GroupBox, public QgsGrassModuleItem

QString ready() ;

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

int type() { return mType; }

public slots:
Expand Down Expand Up @@ -519,6 +522,9 @@ public slots:
//! Combobox for QGIS layers
QComboBox *mLayerComboBox;

//! Region button
QPushButton *mRegionButton;

//! Optional map option id, if defined, only the layers from the
// map currently selected in that option are available.
// This is used by nodes layer option for networks.
Expand Down

0 comments on commit f8aa37e

Please sign in to comment.