Skip to content
Permalink
Browse files

[GRASS] new names fixes

  • Loading branch information
blazek committed Jun 25, 2015
1 parent 26588b5 commit fe8263bfda6002a72dfe30f45870d8ad194f5dec
@@ -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 );
@@ -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 );
@@ -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
@@ -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()
{
@@ -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" );
}

@@ -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 );
@@ -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;
@@ -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 );
@@ -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;
@@ -480,6 +481,7 @@ bool QgsGrassVectorImport::import()
iterator = mProvider->getFeatures();
}
QgsDebugMsg( "send features" );
int count = 0;
while ( iterator.nextFeature( feature ) )
{
if ( !feature.isValid() )
@@ -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
@@ -113,7 +113,7 @@ QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem* parent, QString dirPath, QS

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

QVector<QgsDataItem*> items;

@@ -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 )

0 comments on commit fe8263b

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