6
6
email : radim.blazek@gmail.com
7
7
********************************************************************/
8
8
/********************************************************************
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13
13
*******************************************************************/
17
#include <QApplication>
21
#include <QPushButton>
22
#include <QVBoxLayout>
23
#include <QHBoxLayout>
25
#include <QRegExpValidator>
29
#include <grass/gis.h>
30
#include <grass/Vect.h>
33
#include "../../src/providers/grass/qgsgrass.h"
34
15
#include "qgsgrassutils.h"
35
16
#include "qgsgrassselect.h"
19
#include "qgisinterface.h"
20
#include "qgslogger.h"
37
25
QgsGrassUtils::QgsGrassUtils() {}
38
26
QgsGrassUtils::~QgsGrassUtils() {}
40
QString QgsGrassUtils::vectorLayerName( QString map, QString layer,
28
QString QgsGrassUtils::vectorLayerName( QString map, QString layer,
44
if ( nLayers > 1 ) name += " " + layer;
48
void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
49
QString gisbase, QString location, QString mapset, QString map)
51
QStringList layers = QgsGrassSelect::vectorLayers(
52
gisbase, location, mapset, map );
55
for ( int i = 0; i < layers.count(); i++ )
57
QString name = QgsGrassUtils::vectorLayerName (
58
map, layers[i], layers.size() );
60
QString uri = gisbase + "/" + location + "/"
61
+ mapset + "/" + map + "/" + layers[i];
64
std::cerr << "layer = " << layers[i].local8Bit().data() << std::endl;
65
std::cerr << "uri = " << uri.local8Bit().data() << std::endl;
66
std::cerr << "name = " << name.local8Bit().data() << std::endl;
69
iface->addVectorLayer( uri, name, "grass");
73
bool QgsGrassUtils::itemExists ( QString element, QString item )
75
QString path = QgsGrass::getDefaultGisdbase() + "/"
76
+ QgsGrass::getDefaultLocation() + "/"
77
+ QgsGrass::getDefaultMapset() + "/"
78
+ "/" + element + "/" + item;
84
QgsGrassElementDialog::QgsGrassElementDialog() : QObject()
32
if ( nLayers > 1 ) name += " " + layer;
36
void QgsGrassUtils::addVectorLayers( QgisInterface *iface,
37
QString gisbase, QString location, QString mapset, QString map )
39
QStringList layers = QgsGrassSelect::vectorLayers(
40
gisbase, location, mapset, map );
43
for ( int i = 0; i < layers.count(); i++ )
45
QString name = QgsGrassUtils::vectorLayerName(
46
map, layers[i], layers.size() );
48
QString uri = gisbase + "/" + location + "/"
49
+ mapset + "/" + map + "/" + layers[i];
51
QgsDebugMsg( QString( "layer = %1" ).arg( layers[i].toLocal8Bit().constData() ) );
52
QgsDebugMsg( QString( "uri = %1" ).arg( uri.toLocal8Bit().constData() ) );
53
QgsDebugMsg( QString( "name = %1" ).arg( name.toLocal8Bit().constData() ) );
55
iface->addVectorLayer( uri, name, "grass" );
59
bool QgsGrassUtils::itemExists( QString element, QString item )
61
QString path = QgsGrass::getDefaultGisdbase() + "/"
62
+ QgsGrass::getDefaultLocation() + "/"
63
+ QgsGrass::getDefaultMapset() + "/"
64
+ "/" + element + "/" + item;
70
QgsGrassElementDialog::QgsGrassElementDialog() : QObject()
87
74
QgsGrassElementDialog::~QgsGrassElementDialog() {}
89
QString QgsGrassElementDialog::getItem ( QString element,
90
QString title, QString label,
91
QString text, QString source, bool * ok )
76
QString QgsGrassElementDialog::getItem( QString element,
77
QString title, QString label,
78
QString text, QString source, bool * ok )
94
std::cerr << "QgsGrassElementDialog::getItem" << std::endl;
96
if ( ok ) *ok = false;
99
mDialog = new QDialog ();
100
mDialog->setWindowTitle(title);
101
QVBoxLayout *layout = new QVBoxLayout ( mDialog );
102
QHBoxLayout *buttonLayout = new QHBoxLayout ( );
104
mLabel = new QLabel ( label );
105
layout->addWidget( mLabel );
107
mLineEdit = new QLineEdit ( text );
109
if ( element == "vector" )
111
rx.setPattern("[A-Za-z_][A-Za-z0-9_]+");
115
rx.setPattern("[A-Za-z0-9_.]+");
117
QRegExpValidator *val = new QRegExpValidator( rx, this );
118
mLineEdit->setValidator ( val );
120
layout->addWidget( mLineEdit );
122
mErrorLabel = new QLabel ( "X" );
123
layout->addWidget( mErrorLabel );
124
// Intention: keep fixed size - but it does not help
125
mErrorLabel->adjustSize();
126
mErrorLabel->setMinimumHeight ( mErrorLabel->height()+5 );
128
mOkButton = new QPushButton ( );
129
mCancelButton = new QPushButton ( tr("Cancel" ) );
131
layout->insertLayout( -1, buttonLayout );
132
buttonLayout->addWidget( mOkButton );
133
buttonLayout->addWidget( mCancelButton );
135
connect ( mLineEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged() ) );
136
connect ( mOkButton, SIGNAL(clicked()), mDialog, SLOT(accept() ) );
137
connect ( mCancelButton, SIGNAL(clicked()), mDialog, SLOT(reject() ) );
140
if ( ok && mDialog->exec() == QDialog::Accepted )
145
QString name = mLineEdit->text();
80
QgsDebugMsg( "entered." );
81
if ( ok ) *ok = false;
84
mDialog = new QDialog();
85
mDialog->setWindowTitle( title );
86
QVBoxLayout *layout = new QVBoxLayout( mDialog );
87
QHBoxLayout *buttonLayout = new QHBoxLayout( );
89
mLabel = new QLabel( label );
90
layout->addWidget( mLabel );
92
mLineEdit = new QLineEdit( text );
94
if ( element == "vector" )
96
rx.setPattern( "[A-Za-z_][A-Za-z0-9_]+" );
100
rx.setPattern( "[A-Za-z0-9_.]+" );
102
QRegExpValidator *val = new QRegExpValidator( rx, this );
103
mLineEdit->setValidator( val );
105
layout->addWidget( mLineEdit );
107
mErrorLabel = new QLabel( "X" );
108
layout->addWidget( mErrorLabel );
109
// Intention: keep fixed size - but it does not help
110
mErrorLabel->adjustSize();
111
mErrorLabel->setMinimumHeight( mErrorLabel->height() + 5 );
113
mOkButton = new QPushButton( );
114
mCancelButton = new QPushButton( tr( "Cancel" ) );
116
layout->insertLayout( -1, buttonLayout );
117
buttonLayout->addWidget( mOkButton );
118
buttonLayout->addWidget( mCancelButton );
120
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( textChanged() ) );
121
connect( mOkButton, SIGNAL( clicked() ), mDialog, SLOT( accept() ) );
122
connect( mCancelButton, SIGNAL( clicked() ), mDialog, SLOT( reject() ) );
125
if ( ok && mDialog->exec() == QDialog::Accepted )
130
QString name = mLineEdit->text();
151
void QgsGrassElementDialog::textChanged ()
136
void QgsGrassElementDialog::textChanged()
154
std::cerr << "QgsGrassElementDialog::textChanged" << std::endl;
157
QString text = mLineEdit->text().trimmed();
159
mErrorLabel->setText ( " " );
160
mOkButton->setText ( tr("Ok" ) );
161
mOkButton->setEnabled ( true );
163
if ( text.length() == 0 )
165
mErrorLabel->setText ( tr( "<font color='red'>Enter a name!</font>" ) );
166
mOkButton->setEnabled ( false );
138
QgsDebugMsg( "entered." );
140
QString text = mLineEdit->text().trimmed();
142
mErrorLabel->setText( " " );
143
mOkButton->setText( tr( "Ok" ) );
144
mOkButton->setEnabled( true );
146
if ( text.length() == 0 )
148
mErrorLabel->setText( tr( "<font color='red'>Enter a name!</font>" ) );
149
mOkButton->setEnabled( false );
171
if ( !mSource.isNull() && text.toLower() == mSource.toLower() )
154
if ( !mSource.isNull() && text.toLower() == mSource.toLower() )
173
if ( !mSource.isNull() && text == mSource )
156
if ( !mSource.isNull() && text == mSource )
176
mErrorLabel->setText ( tr( "<font color='red'>This is name of the source!</font>" ) );
177
mOkButton->setEnabled ( false );
180
if ( QgsGrassUtils::itemExists( mElement, text ) )
182
mErrorLabel->setText ( tr( "<font color='red'>Exists!</font>" ) );
183
mOkButton->setText ( tr("Overwrite") );
159
mErrorLabel->setText( tr( "<font color='red'>This is name of the source!</font>" ) );
160
mOkButton->setEnabled( false );
163
if ( QgsGrassUtils::itemExists( mElement, text ) )
165
mErrorLabel->setText( tr( "<font color='red'>Exists!</font>" ) );
166
mOkButton->setText( tr( "Overwrite" ) );