Skip to content
Permalink
Browse files

new spatialite layer: allow tables with only primary key and geometry (

…fixes #14313)
  • Loading branch information
jef-n committed Feb 25, 2016
1 parent 0ba038f commit f9d690516ec7a43bedce4babc80f7115f0478337
Showing with 17 additions and 18 deletions.
  1. +16 −17 src/app/qgsnewspatialitelayerdialog.cpp
  2. +1 −1 src/app/qgsnewspatialitelayerdialog.h
@@ -84,9 +84,12 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W

connect( mNameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( nameChanged( QString ) ) );
connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );
connect( leLayerName, SIGNAL( textChanged( const QString& text ) ), this, SLOT( checkOk() ) );
connect( checkBoxPrimaryKey, SIGNAL( clicked() ), this, SLOT( checkOk() ) );

mAddAttributeButton->setEnabled( false );
mRemoveAttributeButton->setEnabled( false );

}

QgsNewSpatialiteLayerDialog::~QgsNewSpatialiteLayerDialog()
@@ -158,37 +161,34 @@ QString QgsNewSpatialiteLayerDialog::selectedType() const
return "";
}

void QgsNewSpatialiteLayerDialog::on_leLayerName_textChanged( const QString& text )
void QgsNewSpatialiteLayerDialog::checkOk()
{
Q_UNUSED( text );
bool created = leLayerName->text().length() > 0 && mAttributeView->topLevelItemCount() > 0 && createDb();
bool created = !leLayerName->text().isEmpty() &&
( checkBoxPrimaryKey->isChecked() || mAttributeView->topLevelItemCount() > 0 ) &&
createDb();
mOkButton->setEnabled( created );
}

void QgsNewSpatialiteLayerDialog::on_mAddAttributeButton_clicked()
{
if ( mNameEdit->text().length() > 0 )
if ( !mNameEdit->text().isEmpty() )
{
QString myName = mNameEdit->text();
//use userrole to avoid translated type string
QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType ) );
if ( mAttributeView->topLevelItemCount() > 0 && leLayerName->text().length() > 0 )
{
bool created = createDb();
mOkButton->setEnabled( created );
}

checkOk();

mNameEdit->clear();
}
}

void QgsNewSpatialiteLayerDialog::on_mRemoveAttributeButton_clicked()
{
delete mAttributeView->currentItem();
if ( mAttributeView->topLevelItemCount() == 0 )
{
mOkButton->setEnabled( false );
}

checkOk();
}

void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
@@ -347,16 +347,15 @@ bool QgsNewSpatialiteLayerDialog::apply()

if ( checkBoxPrimaryKey->isChecked() )
{
sql += "pkuid integer primary key autoincrement,";
sql += "pkuid integer primary key autoincrement";
delim = ",";
}

QTreeWidgetItemIterator it( mAttributeView );
while ( *it )
{
sql += delim + QString( "%1 %2" ).arg( quotedIdentifier(( *it )->text( 0 ) ), ( *it )->text( 1 ) );

delim = ',';

delim = ",";
++it;
}

@@ -42,10 +42,10 @@ class APP_EXPORT QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNew
void on_mRemoveAttributeButton_clicked();
void on_mTypeBox_currentIndexChanged( int index );
void on_pbnFindSRID_clicked();
void on_leLayerName_textChanged( const QString& text );
void on_toolButtonNewDatabase_clicked();
void nameChanged( const QString& );
void selectionChanged();
void checkOk();

void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void on_buttonBox_accepted();

0 comments on commit f9d6905

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