Navigation Menu

Skip to content

Commit

Permalink
new spatialite layer: allow tables with only primary key and geometry (
Browse files Browse the repository at this point in the history
…fixes #14313)
  • Loading branch information
jef-n committed Feb 25, 2016
1 parent 0ba038f commit f9d6905
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsnewspatialitelayerdialog.h
Expand Up @@ -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();
Expand Down

0 comments on commit f9d6905

Please sign in to comment.