Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
check if output exists
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4865 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Feb 15, 2006
1 parent db2f379 commit 1255f1c
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 2 deletions.
90 changes: 89 additions & 1 deletion src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -611,9 +611,25 @@ void QgsGrassModule::run()

if ( mProcess.isRunning() ) {
}

mProcess.clearArguments();
mProcess.addArgument( mXName );
command = mXName;

// Check if output exists
QStringList outputExists = mOptions->checkOutput();
if ( outputExists.size() > 0 )
{
int ret = QMessageBox::question ( 0, "Warning",
"Output " + outputExists.join(",")
+ " exists! Overwrite?",
QMessageBox::Yes, QMessageBox::No );

if ( ret == QMessageBox::No ) return;

mProcess.addArgument( "--o" );
command.append ( " --o" );
}

QStringList list = mOptions->arguments();

Expand Down Expand Up @@ -764,7 +780,8 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
QDomElement &qdesc, QDomElement &gdesc, QDomNode &gnode,
QWidget * parent)
: Q3GroupBox ( 1, Qt::Vertical, parent ),
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode )
QgsGrassModuleItem ( module, key, qdesc, gdesc, gnode ),
mIsOutput(false)
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleOption::QgsGrassModuleOption" << std::endl;
Expand All @@ -781,6 +798,19 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
}

setTitle ( " " + tit + " " );

// Is it output?
QDomNode promptNode = gnode.namedItem ( "gisprompt" );
if ( !promptNode.isNull() ) {
QDomElement promptElem = promptNode.toElement();
QString element = promptElem.attribute("element");
QString age = promptElem.attribute("age");
if ( age == "new" )
{
mOutputElement = element;
mIsOutput = true;
}
}

// String without options
if ( !mHidden )
Expand Down Expand Up @@ -859,6 +889,34 @@ QgsGrassModuleOption::QgsGrassModuleOption ( QgsGrassModule *module, QString key
}
}

QString QgsGrassModuleOption::outputExists()
{
std::cerr << "QgsGrassModuleOption::outputExists()" << std::endl;

if ( !mIsOutput ) return QString();

QString value = mLineEdit->text().trimmed();
std::cerr << "mKey = " << mKey.ascii() << std::endl;
std::cerr << "value = " << value.ascii() << std::endl;
std::cerr << "mOutputElement = " << mOutputElement.ascii() << std::endl;

if ( value.length() == 0 ) return QString();

QString path = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset() + "/"
+ mOutputElement + "/" + value;

QFileInfo fi(path);

if ( fi.exists() )
{
return (mLineEdit->text());
}

return QString();
}

QStringList QgsGrassModuleOption::options()
{
QStringList list;
Expand Down Expand Up @@ -1088,6 +1146,36 @@ QgsGrassModuleInput::QgsGrassModuleInput ( QgsGrassModule *module,
updateQgisLayers();
}

QStringList QgsGrassModuleStandardOptions::checkOutput()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModuleStandardOptions::checkOutput()" << std::endl;
#endif
QStringList list;

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

std::cerr << "opt->key() = " << opt->key().ascii() << std::endl;

if ( opt->isOutput() )
{
QString out = opt->outputExists();
if ( !out.isNull() )
{
list.append ( opt->key()+ ":" + out );
}
}
}

return list;
}

void QgsGrassModuleInput::updateQgisLayers()
{
#ifdef QGISDEBUG
Expand Down
21 changes: 20 additions & 1 deletion src/plugins/grass/qgsgrassmodule.h
Expand Up @@ -163,6 +163,11 @@ class QgsGrassModuleOptions
//! Get module options as list of arguments for QProcess
virtual QStringList arguments();

//! Check if output exists
// return empty list
// return list of existing output maps
virtual QStringList checkOutput() { return QStringList() ; }

protected:
//! QGIS application
QgisApp *mQgisApp;
Expand Down Expand Up @@ -209,6 +214,8 @@ class QgsGrassModuleStandardOptions: public QgsGrassModuleOptions, QWidget
// ! Get item by ID
QgsGrassModuleItem *item(QString id);

QStringList checkOutput();

private:
//! Name of module executable
QString mXName;
Expand Down Expand Up @@ -299,7 +306,13 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem

//! Retruns list of options which will be passed to module
virtual QStringList options();


//! True if this option is output
bool isOutput() { return mIsOutput; }

//! If output, check if current output exists
// Returns emppty string or name of existing output
QString outputExists();

private:
//! Control type
Expand All @@ -316,6 +329,12 @@ class QgsGrassModuleOption: public Q3GroupBox, public QgsGrassModuleItem

//! Line
QLineEdit *mLineEdit;

//! True if this option is GRASS output
bool mIsOutput;

//! Output element
QString mOutputElement;
};
/********************** QgsGrassModuleFlag ************************/
/*! \class QgsGrassModuleFlag
Expand Down

0 comments on commit 1255f1c

Please sign in to comment.