Skip to content

Commit fe8263b

Browse files
committedJun 25, 2015
[GRASS] new names fixes
1 parent 26588b5 commit fe8263b

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed
 

‎src/gui/qgsnewnamedialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ QgsNewNameDialog::QgsNewNameDialog( const QString& source, const QString& initia
3232
, mExtensions( extensions )
3333
, mCaseSensitivity( cs )
3434
, mNamesLabel( 0 )
35+
, mRegexp( regexp )
3536
{
3637
setWindowTitle( tr( "New name" ) );
3738
QDialog::layout()->setSizeConstraint( QLayout::SetMinimumSize );
@@ -97,7 +98,7 @@ void QgsNewNameDialog::nameChanged()
9798

9899
QString newName = name();
99100

100-
if ( newName.length() == 0 )
101+
if ( newName.length() == 0 || ( !mRegexp.isEmpty() && !mRegexp.exactMatch( newName ) ) )
101102
{
102103
//mErrorLabel->setText( highlightText( tr( "Enter new name" ) );
103104
okButton->setEnabled( false );

‎src/gui/qgsnewnamedialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class GUI_EXPORT QgsNewNameDialog : public QgsDialog
7171
QLabel *mNamesLabel; // list of names with extensions
7272
QLabel *mErrorLabel;
7373
QString mOkString;
74+
QRegExp mRegexp;
7475
QString highlightText( const QString& text );
7576
static QStringList fullNames( const QString& name, const QStringList& extensions );
7677
// get list of existing names

‎src/providers/grass/qgis.v.in.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static struct Map_info *finalMap = 0;
7171
static struct Map_info *tmpMap = 0;
7272
static QString finalName;
7373
static QString tmpName;
74+
dbDriver *driver = 0;
7475

7576
void closeMaps()
7677
{
@@ -84,6 +85,12 @@ void closeMaps()
8485
Vect_close( finalMap );
8586
Vect_delete( finalName.toUtf8().data() );
8687
}
88+
if ( driver )
89+
{
90+
// we should rollback transaction but there is not db_rollback_transaction()
91+
// With SQLite it takes very long time with large datasets to close db
92+
db_close_database_shutdown_driver( driver );
93+
}
8794
G_warning( "import canceled -> maps deleted" );
8895
}
8996

@@ -189,7 +196,7 @@ int main( int argc, char **argv )
189196
G_fatal_error( "Cannot add link" );
190197
}
191198

192-
dbDriver *driver = db_start_driver_open_database( fieldInfo->driver, fieldInfo->database );
199+
driver = db_start_driver_open_database( fieldInfo->driver, fieldInfo->database );
193200
if ( !driver )
194201
{
195202
G_fatal_error( "Cannot open database %s by driver %s", fieldInfo->database, fieldInfo->driver );

‎src/providers/grass/qgsgrassimport.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ bool QgsGrassRasterImport::import()
221221
QString name = mGrassObject.name();
222222
if ( provider->bandCount() > 1 )
223223
{
224-
name += QString( "_%1" ).arg( band );
224+
// raster.<band> to keep in sync with r.in.gdal
225+
name += QString( ".%1" ).arg( band );
225226
}
226227
arguments.append( "output=" + name ); // get list of all output names
227228
QTemporaryFile gisrcFile;
@@ -344,9 +345,9 @@ bool QgsGrassRasterImport::import()
344345
QgsGrass::setMapset( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset() );
345346
struct Ref ref;
346347
I_get_group_ref( name.toUtf8().data(), &ref );
347-
QString redName = name + QString( "_%1" ).arg( redBand );
348-
QString greenName = name + QString( "_%1" ).arg( greenBand );
349-
QString blueName = name + QString( "_%1" ).arg( blueBand );
348+
QString redName = name + QString( ".%1" ).arg( redBand );
349+
QString greenName = name + QString( ".%1" ).arg( greenBand );
350+
QString blueName = name + QString( ".%1" ).arg( blueBand );
350351
I_add_file_to_group_ref( redName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
351352
I_add_file_to_group_ref( greenName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
352353
I_add_file_to_group_ref( blueName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
@@ -376,7 +377,7 @@ QStringList QgsGrassRasterImport::extensions( QgsRasterDataProvider* provider )
376377
{
377378
for ( int band = 1; band <= provider->bandCount(); band++ )
378379
{
379-
list << QString( "_%1" ).arg( band );
380+
list << QString( ".%1" ).arg( band );
380381
}
381382
}
382383
return list;
@@ -480,6 +481,7 @@ bool QgsGrassVectorImport::import()
480481
iterator = mProvider->getFeatures();
481482
}
482483
QgsDebugMsg( "send features" );
484+
int count = 0;
483485
while ( iterator.nextFeature( feature ) )
484486
{
485487
if ( !feature.isValid() )
@@ -507,6 +509,12 @@ bool QgsGrassVectorImport::import()
507509
bool result;
508510
outStream >> result;
509511
#endif
512+
count++;
513+
// get some feedback for large datasets
514+
if ( count % 10000 == 0 )
515+
{
516+
QgsDebugMsg( QString( "%1 features written" ).arg( count ) );
517+
}
510518
}
511519
feature = QgsFeature(); // indicate end by invalid feature
512520
outStream << false; // not canceled

‎src/providers/grass/qgsgrassprovidermodule.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem* parent, QString dirPath, QS
113113

114114
QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
115115
{
116-
QgsDebugMsg( "Entered xxx" );
116+
QgsDebugMsg( "Entered" );
117117

118118
QVector<QgsDataItem*> items;
119119

@@ -390,7 +390,8 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData * data, Qt::DropAction )
390390

391391
// TODO: add a method in QgsGrass to convert a name to GRASS valid name
392392
QString destName = srcName.replace( " ", "_" );
393-
if ( QgsNewNameDialog::exists( destName, extensions, existingNames, caseSensitivity ) )
393+
if ( QgsNewNameDialog::exists( destName, extensions, existingNames, caseSensitivity )
394+
|| !regExp.exactMatch( destName ) )
394395
{
395396
QgsNewNameDialog dialog( srcName, destName, extensions, existingNames, regExp, caseSensitivity );
396397
if ( dialog.exec() != QDialog::Accepted )

0 commit comments

Comments
 (0)
Please sign in to comment.