Skip to content

Commit

Permalink
set validator in grass element dialog, use this dialog for new vector
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5091 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 24, 2006
1 parent 3f239c9 commit 5c48dae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 43 deletions.
45 changes: 5 additions & 40 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/grass/qgsgrassutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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" );
Expand Down

0 comments on commit 5c48dae

Please sign in to comment.