Skip to content
Permalink
Browse files

copy map

git-svn-id: http://svn.osgeo.org/qgis/trunk@5053 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 17, 2006
1 parent 0e2442f commit 9b9f9c2a521fc9886c3f6ad2d864ecfb915c6767
@@ -73,6 +73,22 @@ QgsGrassBrowser::QgsGrassBrowser ( QgisIface *iface,
tb->addAction ( mActionAddMap );
connect ( mActionAddMap, SIGNAL(triggered()), this, SLOT(addMap()) );

mActionCopyMap = new QAction(
QIcon(myIconPath+"grass_copy_map.png"),
tr("Copy selected map"), this);
mActionCopyMap->setEnabled(false);
ag->addAction ( mActionCopyMap );
tb->addAction ( mActionCopyMap );
connect ( mActionCopyMap, SIGNAL(triggered()), this, SLOT(copyMap()) );

mActionRenameMap = new QAction(
QIcon(myIconPath+"grass_rename_map.png"),
tr("Rename selected map"), this);
mActionRenameMap->setEnabled(false);
ag->addAction ( mActionRenameMap );
tb->addAction ( mActionRenameMap );
connect ( mActionRenameMap, SIGNAL(triggered()), this, SLOT(renameMap()) );

mActionDeleteMap = new QAction(
QIcon(myIconPath+"grass_delete_map.png"),
tr("Delete selected map"), this);
@@ -197,14 +213,80 @@ void QgsGrassBrowser::doubleClicked(const QModelIndex & index)
addMap();
}

void QgsGrassBrowser::copyMap()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::copyMap()" << std::endl;
#endif

QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();

QList<QModelIndex>::const_iterator it = indexes.begin();
for (; it != indexes.end(); ++it)
{
int type = mModel->itemType(*it);
QString mapset = mModel->itemMapset(*it);
QString map = mModel->itemMap(*it);

QString typeName;
QString element;
if ( type == QgsGrassModel::Raster )
{
element = "cell";
typeName = "rast";
}
else if ( type == QgsGrassModel::Vector )
{
element = "vector";
typeName = "vect";
}
else if ( type == QgsGrassModel::Region )
{
element = "windows";
typeName = "region";
}

QgsGrassElementDialog *ed = new QgsGrassElementDialog();
bool ok;
QString newName = ed->getItem ( element, map, &ok );
delete ed;

if ( !ok ) return;

QString module = "g.copy";
#ifdef WIN32
module.append(".exe");
#endif
QProcess process(this);
process.start(module, QStringList( typeName + "=" + map + "@" + mapset + "," + newName ) );
if ( !process.waitForFinished() )
{
QMessageBox::warning( 0, "Warning", "Cannot copy map "
+ map );
}
else
{
refresh();
}
}
}

void QgsGrassBrowser::renameMap()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::renameMap()" << std::endl;
#endif

QMessageBox::warning ( 0, "Warning", "Not yet implemented" );
}

void QgsGrassBrowser::deleteMap()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassBrowser::deleteMap()" << std::endl;
#endif

QModelIndexList indexes = mTree->selectionModel()->selectedIndexes();
bool mapSelected = false;

QList<QModelIndex>::const_iterator it = indexes.begin();
for (; it != indexes.end(); ++it)
@@ -339,6 +421,8 @@ void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QI
#endif

mActionAddMap->setEnabled(false);
mActionCopyMap->setEnabled(false);
mActionRenameMap->setEnabled(false);
mActionDeleteMap->setEnabled(false);
mActionSetRegion->setEnabled(false);

@@ -362,11 +446,13 @@ void QgsGrassBrowser::selectionChanged(const QItemSelection & selected, const QI
if ( type == QgsGrassModel::Raster || type == QgsGrassModel::Vector || type == QgsGrassModel::Region )
{
mActionSetRegion->setEnabled(true);
mActionCopyMap->setEnabled(true);

QString mapset = mModel->itemMapset(*it);
if ( mapset == QgsGrass::getDefaultMapset() )
{
mActionDeleteMap->setEnabled(true);
mActionRenameMap->setEnabled(true);
}
}
}
@@ -44,6 +44,12 @@ public slots:
// Add selected map to canvas
void addMap();

// Copy selected map
void copyMap();

// Rename selected map
void renameMap();

// Delete selected map
void deleteMap();

@@ -85,6 +91,8 @@ public slots:
//! Actions
QAction *mActionAddMap;
QAction *mActionDeleteMap;
QAction *mActionCopyMap;
QAction *mActionRenameMap;
QAction *mActionSetRegion;
QAction *mActionRefresh;
};
@@ -15,6 +15,13 @@
#include <vector>

#include <QApplication>
#include <QDialog>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFileInfo>

//#include "qgis.h"
//#include "qgsapplication.h"
@@ -63,3 +70,72 @@ void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
iface->addVectorLayer( uri, name, "grass");
}
}

bool QgsGrassUtils::itemExists ( QString element, QString item )
{
QString path = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset() + "/"
+ "/" + element + "/" + item;

QFileInfo fi(path);
return fi.exists();
}

QgsGrassElementDialog::QgsGrassElementDialog() : QObject()
{
}
QgsGrassElementDialog::~QgsGrassElementDialog() {}

QString QgsGrassElementDialog::getItem ( QString element,
QString text, bool * ok )
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassElementDialog::getItem" << std::endl;
#endif
*ok = false;
mElement = element;
mDialog = new QDialog ();
QVBoxLayout *layout = new QVBoxLayout ( mDialog );
QHBoxLayout *buttonLayout = new QHBoxLayout ( );

mLineEdit = new QLineEdit ( text );
layout->addWidget( mLineEdit );
mErrorLabel = new QLabel ( );
layout->addWidget( mErrorLabel );

mOkButton = new QPushButton ( "Ok" );
mCancelButton = new QPushButton ( "Cancel" );

layout->insertLayout( -1, buttonLayout );
buttonLayout->addWidget( mOkButton );
buttonLayout->addWidget( mCancelButton );

connect ( mLineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged() ) );
connect ( mOkButton, SIGNAL(clicked()), mDialog, SLOT(accept() ) );
connect ( mCancelButton, SIGNAL(clicked()), mDialog, SLOT(reject() ) );

textChanged ();
if ( mDialog->exec() == QDialog::Accepted )
{
*ok = true;
}

QString name = mLineEdit->text();
delete mDialog;

return name;
}

void QgsGrassElementDialog::textChanged ()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassElementDialog::textChanged" << std::endl;
#endif

mErrorLabel->setText ( "" );
if ( QgsGrassUtils::itemExists( mElement, mLineEdit->text() ) )
{
mErrorLabel->setText ( "Exists!" );
}
}
@@ -16,6 +16,11 @@
#ifndef QGSGRASSUTILS_H
#define QGSGRASSUTILS_H

#include <QObject>
class QDialog;
class QLineEdit;
class QLabel;
class QPushButton;
#include "qgisiface.h"

/*! \class QgsGrassUtils
@@ -38,6 +43,41 @@ class QgsGrassUtils
// Add all vector layers to QGIS view
static void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
QString gisbase, QString location, QString mapset, QString map);

// Check if element exists in current mapset
static bool QgsGrassUtils::itemExists ( QString element, QString item);

};

/*! \class QgsGrassElementDialog
* \brief Get name for new element
*/
class QgsGrassElementDialog: public QObject
{
Q_OBJECT;

public:
//! Constructor
QgsGrassElementDialog();

//! Destructor
~QgsGrassElementDialog();

public:
// Get a name for new GRASS element (map)
QString getItem ( QString element,
QString text, bool * ok );

public slots:
void textChanged();

private:
QString mElement;
QDialog *mDialog;
QLineEdit *mLineEdit;
QLabel *mErrorLabel;
QPushButton *mOkButton;
QPushButton *mCancelButton;
};

#endif // QGSGRASSUTILS_H

0 comments on commit 9b9f9c2

Please sign in to comment.
You can’t perform that action at this time.