Skip to content

Commit a4904a7

Browse files
author
rblazek
committed
reimplemented options methods checkRegion, inputRegion, input
git-svn-id: http://svn.osgeo.org/qgis/trunk@5092 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 580af38 commit a4904a7

File tree

2 files changed

+139
-3
lines changed

2 files changed

+139
-3
lines changed

src/plugins/grass/qgsgrassmapcalc.cpp

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,139 @@ QStringList QgsGrassMapcalc::checkOutput()
512512
return QStringList();
513513
}
514514

515+
QStringList QgsGrassMapcalc::checkRegion()
516+
{
517+
#ifdef QGISDEBUG
518+
std::cerr << "QgsGrassMapcalc::checkRegion()" << std::endl;
519+
#endif
520+
QStringList list;
521+
522+
Q3CanvasItemList l = mCanvas->allItems();
523+
524+
struct Cell_head currentWindow;
525+
if ( !QgsGrass::region ( QgsGrass::getDefaultGisdbase(),
526+
QgsGrass::getDefaultLocation(),
527+
QgsGrass::getDefaultMapset(), &currentWindow ) )
528+
{
529+
QMessageBox::warning( 0, "Warning", "Cannot get current region" );
530+
return list;
531+
}
532+
533+
for ( Q3CanvasItemList::Iterator it=l.fromLast(); it!=l.end(); --it)
534+
{
535+
if (! (*it)->isActive() ) continue;
536+
537+
if ( typeid (**it) != typeid (QgsGrassMapcalcObject) ) continue;
538+
539+
QgsGrassMapcalcObject *obj =
540+
dynamic_cast <QgsGrassMapcalcObject *> (*it);
541+
542+
if ( obj->type() != QgsGrassMapcalcObject::Map ) continue;
543+
544+
struct Cell_head window;
545+
546+
QStringList mm = obj->value().split("@");
547+
if ( mm.size() < 1 ) continue;
548+
549+
QString map = mm.at(0);
550+
QString mapset = QgsGrass::getDefaultMapset();
551+
if ( mm.size() > 1 ) mapset = mm.at(1);
552+
553+
if ( !QgsGrass::mapRegion ( QgsGrass::Raster,
554+
QgsGrass::getDefaultGisdbase(),
555+
QgsGrass::getDefaultLocation(), mapset, map,
556+
&window ) )
557+
{
558+
QMessageBox::warning( 0, "Warning", "Cannot check region "
559+
"of map " + obj->value() );
560+
continue;
561+
}
562+
563+
if ( G_window_overlap ( &currentWindow ,
564+
window.north, window.south, window.east, window.west) == 0 )
565+
{
566+
list.append ( obj->value() );
567+
}
568+
}
569+
return list;
570+
}
571+
572+
bool QgsGrassMapcalc::inputRegion ( struct Cell_head *window, bool all )
573+
{
574+
#ifdef QGISDEBUG
575+
std::cerr << "gsGrassMapcalc::inputRegion" << std::endl;
576+
#endif
577+
578+
if ( !QgsGrass::region ( QgsGrass::getDefaultGisdbase(),
579+
QgsGrass::getDefaultLocation(),
580+
QgsGrass::getDefaultMapset(), window ) )
581+
{
582+
QMessageBox::warning( 0, "Warning", "Cannot get current region" );
583+
return false;
584+
}
585+
586+
Q3CanvasItemList l = mCanvas->allItems();
587+
588+
int count = 0;
589+
for ( Q3CanvasItemList::Iterator it=l.fromLast(); it!=l.end(); --it)
590+
{
591+
if (! (*it)->isActive() ) continue;
592+
593+
if ( typeid (**it) != typeid (QgsGrassMapcalcObject) ) continue;
594+
595+
QgsGrassMapcalcObject *obj =
596+
dynamic_cast <QgsGrassMapcalcObject *> (*it);
597+
598+
if ( obj->type() != QgsGrassMapcalcObject::Map ) continue;
599+
600+
struct Cell_head mapWindow;
601+
602+
QStringList mm = obj->value().split("@");
603+
if ( mm.size() < 1 ) continue;
604+
605+
QString map = mm.at(0);
606+
QString mapset = QgsGrass::getDefaultMapset();
607+
if ( mm.size() > 1 ) mapset = mm.at(1);
608+
609+
if ( !QgsGrass::mapRegion ( QgsGrass::Raster,
610+
QgsGrass::getDefaultGisdbase(),
611+
QgsGrass::getDefaultLocation(), mapset, map,
612+
&mapWindow ) )
613+
{
614+
QMessageBox::warning( 0, "Warning", "Cannot get region "
615+
"of map " + obj->value() );
616+
return false;
617+
}
618+
619+
// TODO: best way to set resolution ?
620+
if ( count == 0)
621+
{
622+
QgsGrass::copyRegionExtent ( &mapWindow, window );
623+
QgsGrass::copyRegionResolution ( &mapWindow, window );
624+
}
625+
else
626+
{
627+
QgsGrass::extendRegion ( &mapWindow, window );
628+
}
629+
count++;
630+
}
631+
632+
return true;
633+
}
634+
635+
QStringList QgsGrassMapcalc::output ( int type )
636+
{
637+
#ifdef QGISDEBUG
638+
std::cerr << "gsGrassMapcalc::output" << std::endl;
639+
#endif
640+
QStringList list;
641+
if ( type == QgsGrassModuleOption::Raster )
642+
{
643+
list.append ( mOutputLineEdit->text() );
644+
}
645+
return list;
646+
}
647+
515648
QgsGrassMapcalc::~QgsGrassMapcalc()
516649
{
517650
}

src/plugins/grass/qgsgrassmapcalc.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,14 @@ class QgsGrassMapcalc: public QMainWindow, private Ui::QgsGrassMapcalcBase,
8585
//! Get module options as list of arguments for QProcess
8686
QStringList arguments();
8787

88-
//! Check if output exists, reimplemented method from
89-
// QgsGrassModuleOptions
88+
// Reimplemented methods
9089
QStringList checkOutput();
91-
9290
QStringList ready() { return QStringList() ; }
91+
bool requestsRegion() { return false; }
92+
bool usesRegion() { return true; }
93+
QStringList checkRegion();
94+
bool inputRegion( struct Cell_head *window, bool all );
95+
QStringList output(int type);
9396

9497
/** \brief recieves contentsMousePressEvent from view */
9598
void contentsMousePressEvent(QMouseEvent*);

0 commit comments

Comments
 (0)