Skip to content

Commit f8aa37e

Browse files
author
rblazek
committed
set region to input option
git-svn-id: http://svn.osgeo.org/qgis/trunk@5083 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b8c82ab commit f8aa37e

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

src/plugins/grass/qgsgrassmodule.cpp

+68-7
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,13 @@ QStringList QgsGrassModuleStandardOptions::checkRegion()
580580
break;
581581
}
582582

583+
QStringList mm = item->currentMap().split("@");
584+
QString map = mm.at(0);
585+
QString mapset = QgsGrass::getDefaultMapset();
586+
if ( mm.size() > 1 ) mapset = mm.at(1);
583587
if ( !QgsGrass::mapRegion ( mapType,
584588
QgsGrass::getDefaultGisdbase(),
585-
QgsGrass::getDefaultLocation(), "", item->currentMap(),
589+
QgsGrass::getDefaultLocation(), mapset, map,
586590
&window ) )
587591
{
588592
QMessageBox::warning( 0, "Warning", "Cannot check region "
@@ -623,13 +627,13 @@ bool QgsGrassModuleStandardOptions::inputRegion ( struct Cell_head *window, bool
623627
continue;
624628
}
625629

626-
// TODO all flag
627-
628630
struct Cell_head mapWindow;
629631

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

635+
if ( !all && !item->useRegion() ) continue;
636+
633637
int mapType;
634638
switch ( item->type() ) {
635639
case QgsGrassModuleInput::Raster :
@@ -640,9 +644,13 @@ bool QgsGrassModuleStandardOptions::inputRegion ( struct Cell_head *window, bool
640644
break;
641645
}
642646

647+
QStringList mm = item->currentMap().split("@");
648+
QString map = mm.at(0);
649+
QString mapset = QgsGrass::getDefaultMapset();
650+
if ( mm.size() > 1 ) mapset = mm.at(1);
643651
if ( !QgsGrass::mapRegion ( mapType,
644652
QgsGrass::getDefaultGisdbase(),
645-
QgsGrass::getDefaultLocation(), "", item->currentMap(),
653+
QgsGrass::getDefaultLocation(), mapset, map,
646654
&mapWindow ) )
647655
{
648656
QMessageBox::warning( 0, "Warning", "Cannot set region "
@@ -676,6 +684,26 @@ bool QgsGrassModuleStandardOptions::inputRegion ( struct Cell_head *window, bool
676684
return true;
677685
}
678686

687+
bool QgsGrassModuleStandardOptions::requestsRegion()
688+
{
689+
#ifdef QGISDEBUG
690+
std::cerr << "QgsGrassModuleStandardOptions::requestsRegion()" << std::endl;
691+
#endif
692+
693+
for ( int i = 0; i < mItems.size(); i++ )
694+
{
695+
if ( typeid(*(mItems[i])) != typeid (QgsGrassModuleInput) ) {
696+
continue;
697+
}
698+
699+
QgsGrassModuleInput *item = dynamic_cast<QgsGrassModuleInput *>
700+
(mItems[i]);
701+
702+
if ( item->useRegion() ) return true;
703+
}
704+
return false;
705+
}
706+
679707
bool QgsGrassModuleStandardOptions::usesRegion ()
680708
{
681709
#ifdef QGISDEBUG
@@ -1559,10 +1587,11 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
15591587
QgsGrassModuleStandardOptions *options, QString key,
15601588
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
15611589
QWidget * parent)
1562-
: Q3GroupBox ( 1, Qt::Vertical, parent ),
1590+
: QGroupBox ( parent ),
15631591
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
15641592
mModuleStandardOptions(options),
1565-
mUpdate(false), mVectorTypeOption(0), mVectorLayerOption(0)
1593+
mUpdate(false), mVectorTypeOption(0), mVectorLayerOption(0),
1594+
mRegionButton(0)
15661595
{
15671596
#ifdef QGISDEBUG
15681597
std::cerr << "QgsGrassModuleInput::QgsGrassModuleInput" << std::endl;
@@ -1692,7 +1721,26 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
16921721
mUpdate = true;
16931722
}
16941723

1695-
mLayerComboBox = new QComboBox ( this );
1724+
QHBoxLayout *l = new QHBoxLayout (this);
1725+
mLayerComboBox = new QComboBox ();
1726+
mLayerComboBox->setSizePolicy (QSizePolicy::Expanding,
1727+
QSizePolicy:: Preferred );
1728+
l->addWidget ( mLayerComboBox );
1729+
1730+
if ( mType == Raster &&
1731+
QgsGrass::versionMajor() >= 6 && QgsGrass::versionMinor() >= 1 )
1732+
{
1733+
QString iconPath = QgsApplication::themePath() + "/grass/";
1734+
1735+
mRegionButton = new QPushButton(
1736+
QIcon(iconPath+"grass_set_region.png"), "" );
1737+
1738+
mRegionButton->setToolTip ( "Use region of this map" );
1739+
mRegionButton->setCheckable ( true );
1740+
mRegionButton->setSizePolicy (QSizePolicy::Minimum,
1741+
QSizePolicy:: Preferred );
1742+
l->addWidget ( mRegionButton );
1743+
}
16961744

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

1770+
bool QgsGrassModuleInput::useRegion()
1771+
{
1772+
std::cerr << "QgsGrassModuleInput::useRegion()" << std::endl;
1773+
1774+
if ( mType == Raster && mRegionButton &&
1775+
mRegionButton->isChecked() )
1776+
{
1777+
return true;
1778+
}
1779+
1780+
return false;
1781+
}
1782+
17221783
void QgsGrassModuleInput::updateQgisLayers()
17231784
{
17241785
#ifdef QGISDEBUG

src/plugins/grass/qgsgrassmodule.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class QgsGrassModuleOptions
197197
virtual bool usesRegion() { return false; }
198198

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

202202
//! Check region
203203
// return empty list
@@ -261,7 +261,7 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget
261261
QStringList output(int type);
262262
QStringList checkRegion();
263263
bool usesRegion();
264-
bool requestsRegion() { return false; } // TODO
264+
bool requestsRegion();
265265
bool inputRegion( struct Cell_head *window, bool all );
266266

267267
private:
@@ -455,7 +455,7 @@ class QgsGrassModuleFlag: public QCheckBox, public QgsGrassModuleItem
455455
/*! \class QgsGrassModuleInput
456456
* \brief Class representing raster or vector module input
457457
*/
458-
class QgsGrassModuleInput: public Q3GroupBox, public QgsGrassModuleItem
458+
class QgsGrassModuleInput: public QGroupBox, public QgsGrassModuleItem
459459
{
460460
Q_OBJECT;
461461

@@ -487,6 +487,9 @@ class QgsGrassModuleInput: public Q3GroupBox, public QgsGrassModuleItem
487487

488488
QString ready() ;
489489

490+
//! Should be used region of this input
491+
bool useRegion();
492+
490493
int type() { return mType; }
491494

492495
public slots:
@@ -519,6 +522,9 @@ public slots:
519522
//! Combobox for QGIS layers
520523
QComboBox *mLayerComboBox;
521524

525+
//! Region button
526+
QPushButton *mRegionButton;
527+
522528
//! Optional map option id, if defined, only the layers from the
523529
// map currently selected in that option are available.
524530
// This is used by nodes layer option for networks.

0 commit comments

Comments
 (0)