Skip to content
Permalink
Browse files

set validator in grass element dialog, use this dialog for new vector

git-svn-id: http://svn.osgeo.org/qgis/trunk@5091 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 24, 2006
1 parent 12528c5 commit 580af380ac91d85abecc2bd9de45b8010712b2bb
Showing with 19 additions and 43 deletions.
  1. +5 −40 src/plugins/grass/qgsgrassplugin.cpp
  2. +14 −3 src/plugins/grass/qgsgrassutils.cpp
@@ -61,6 +61,7 @@ extern "C" {
#include "../../src/providers/grass/qgsgrassprovider.h"

//the gui subclass
#include "qgsgrassutils.h"
#include "qgsgrassattributes.h"
#include "qgsgrassselect.h"
#include "qgsgrassedit.h"
@@ -459,47 +460,11 @@ void QgsGrassPlugin::newVector()
bool ok;
QString name;

while (1)
{
name = QInputDialog::getText( "New GRASS vector",
"Enter new GRASS vector name:", QLineEdit::Normal,
name, &ok);

if ( !ok ) return;

// Check if the name is valid
name = name.stripWhiteSpace();

if ( name.isEmpty() ) {
QMessageBox::warning( 0, "Warning", "Enter vector name" );
continue;
}
QgsGrassElementDialog dialog;
name = dialog.getItem ( "vector", "New vector name",
"New vector name", "", "", &ok );

if ( Vect_legal_filename ( (char *) name.ascii() ) != 1 )
{
QMessageBox::warning( 0, "Warning", "The name is not valid. "
"A vector name can contain letters, digits and underscores "
"and it must start with letter." );
continue;
}

// Check if exists
QString head = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset() + "/vector/"
+ name + "/head";

QFile file(head);
if ( file.exists() )
{
int ret = QMessageBox::question ( 0, "Warning", "The vector exists. "
"Overwrite? ", QMessageBox::Yes, QMessageBox::No );

if ( ret == QMessageBox::No ) continue;
}

break;
}
if ( !ok ) return;

// Create new map
QgsGrass::setMapset ( QgsGrass::getDefaultGisdbase(),
@@ -22,9 +22,8 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFileInfo>

//#include "qgis.h"
//#include "qgsapplication.h"
#include <QRegExpValidator>
#include <QRegExp>

extern "C" {
#include <grass/gis.h>
@@ -106,6 +105,18 @@ QString QgsGrassElementDialog::getItem ( QString element,
layout->addWidget( mLabel );

mLineEdit = new QLineEdit ( text );
QRegExp rx;
if ( element == "vector" )
{
rx.setPattern("[A-Za-z_][A-Za-z0-9_]+");
}
else
{
rx.setPattern("[A-Za-z0-9_.]+");
}
QRegExpValidator *val = new QRegExpValidator( rx, this );
mLineEdit->setValidator ( val );

layout->addWidget( mLineEdit );

mErrorLabel = new QLabel ( "X" );

0 comments on commit 580af38

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