Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GRASS] new names fixes
  • Loading branch information
blazek committed Jun 25, 2015
1 parent 26588b5 commit fe8263b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/gui/qgsnewnamedialog.cpp
Expand Up @@ -32,6 +32,7 @@ QgsNewNameDialog::QgsNewNameDialog( const QString& source, const QString& initia
, mExtensions( extensions )
, mCaseSensitivity( cs )
, mNamesLabel( 0 )
, mRegexp( regexp )
{
setWindowTitle( tr( "New name" ) );
QDialog::layout()->setSizeConstraint( QLayout::SetMinimumSize );
Expand Down Expand Up @@ -97,7 +98,7 @@ void QgsNewNameDialog::nameChanged()

QString newName = name();

if ( newName.length() == 0 )
if ( newName.length() == 0 || ( !mRegexp.isEmpty() && !mRegexp.exactMatch( newName ) ) )
{
//mErrorLabel->setText( highlightText( tr( "Enter new name" ) );
okButton->setEnabled( false );
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsnewnamedialog.h
Expand Up @@ -71,6 +71,7 @@ class GUI_EXPORT QgsNewNameDialog : public QgsDialog
QLabel *mNamesLabel; // list of names with extensions
QLabel *mErrorLabel;
QString mOkString;
QRegExp mRegexp;
QString highlightText( const QString& text );
static QStringList fullNames( const QString& name, const QStringList& extensions );
// get list of existing names
Expand Down
9 changes: 8 additions & 1 deletion src/providers/grass/qgis.v.in.cpp
Expand Up @@ -71,6 +71,7 @@ static struct Map_info *finalMap = 0;
static struct Map_info *tmpMap = 0;
static QString finalName;
static QString tmpName;
dbDriver *driver = 0;

void closeMaps()
{
Expand All @@ -84,6 +85,12 @@ void closeMaps()
Vect_close( finalMap );
Vect_delete( finalName.toUtf8().data() );
}
if ( driver )
{
// we should rollback transaction but there is not db_rollback_transaction()
// With SQLite it takes very long time with large datasets to close db
db_close_database_shutdown_driver( driver );
}
G_warning( "import canceled -> maps deleted" );
}

Expand Down Expand Up @@ -189,7 +196,7 @@ int main( int argc, char **argv )
G_fatal_error( "Cannot add link" );
}

dbDriver *driver = db_start_driver_open_database( fieldInfo->driver, fieldInfo->database );
driver = db_start_driver_open_database( fieldInfo->driver, fieldInfo->database );
if ( !driver )
{
G_fatal_error( "Cannot open database %s by driver %s", fieldInfo->database, fieldInfo->driver );
Expand Down
18 changes: 13 additions & 5 deletions src/providers/grass/qgsgrassimport.cpp
Expand Up @@ -221,7 +221,8 @@ bool QgsGrassRasterImport::import()
QString name = mGrassObject.name();
if ( provider->bandCount() > 1 )
{
name += QString( "_%1" ).arg( band );
// raster.<band> to keep in sync with r.in.gdal
name += QString( ".%1" ).arg( band );
}
arguments.append( "output=" + name ); // get list of all output names
QTemporaryFile gisrcFile;
Expand Down Expand Up @@ -344,9 +345,9 @@ bool QgsGrassRasterImport::import()
QgsGrass::setMapset( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset() );
struct Ref ref;
I_get_group_ref( name.toUtf8().data(), &ref );
QString redName = name + QString( "_%1" ).arg( redBand );
QString greenName = name + QString( "_%1" ).arg( greenBand );
QString blueName = name + QString( "_%1" ).arg( blueBand );
QString redName = name + QString( ".%1" ).arg( redBand );
QString greenName = name + QString( ".%1" ).arg( greenBand );
QString blueName = name + QString( ".%1" ).arg( blueBand );
I_add_file_to_group_ref( redName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
I_add_file_to_group_ref( greenName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
I_add_file_to_group_ref( blueName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
Expand Down Expand Up @@ -376,7 +377,7 @@ QStringList QgsGrassRasterImport::extensions( QgsRasterDataProvider* provider )
{
for ( int band = 1; band <= provider->bandCount(); band++ )
{
list << QString( "_%1" ).arg( band );
list << QString( ".%1" ).arg( band );
}
}
return list;
Expand Down Expand Up @@ -480,6 +481,7 @@ bool QgsGrassVectorImport::import()
iterator = mProvider->getFeatures();
}
QgsDebugMsg( "send features" );
int count = 0;
while ( iterator.nextFeature( feature ) )
{
if ( !feature.isValid() )
Expand Down Expand Up @@ -507,6 +509,12 @@ bool QgsGrassVectorImport::import()
bool result;
outStream >> result;
#endif
count++;
// get some feedback for large datasets
if ( count % 10000 == 0 )
{
QgsDebugMsg( QString( "%1 features written" ).arg( count ) );
}
}
feature = QgsFeature(); // indicate end by invalid feature
outStream << false; // not canceled
Expand Down
5 changes: 3 additions & 2 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Expand Up @@ -113,7 +113,7 @@ QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem* parent, QString dirPath, QS

QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
{
QgsDebugMsg( "Entered xxx" );
QgsDebugMsg( "Entered" );

QVector<QgsDataItem*> items;

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

// TODO: add a method in QgsGrass to convert a name to GRASS valid name
QString destName = srcName.replace( " ", "_" );
if ( QgsNewNameDialog::exists( destName, extensions, existingNames, caseSensitivity ) )
if ( QgsNewNameDialog::exists( destName, extensions, existingNames, caseSensitivity )
|| !regExp.exactMatch( destName ) )
{
QgsNewNameDialog dialog( srcName, destName, extensions, existingNames, regExp, caseSensitivity );
if ( dialog.exec() != QDialog::Accepted )
Expand Down

0 comments on commit fe8263b

Please sign in to comment.