Skip to content

Commit f9d6905

Browse files
committed
new spatialite layer: allow tables with only primary key and geometry (fixes #14313)
1 parent 0ba038f commit f9d6905

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/app/qgsnewspatialitelayerdialog.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
8484

8585
connect( mNameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( nameChanged( QString ) ) );
8686
connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );
87+
connect( leLayerName, SIGNAL( textChanged( const QString& text ) ), this, SLOT( checkOk() ) );
88+
connect( checkBoxPrimaryKey, SIGNAL( clicked() ), this, SLOT( checkOk() ) );
8789

8890
mAddAttributeButton->setEnabled( false );
8991
mRemoveAttributeButton->setEnabled( false );
92+
9093
}
9194

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

161-
void QgsNewSpatialiteLayerDialog::on_leLayerName_textChanged( const QString& text )
164+
void QgsNewSpatialiteLayerDialog::checkOk()
162165
{
163-
Q_UNUSED( text );
164-
bool created = leLayerName->text().length() > 0 && mAttributeView->topLevelItemCount() > 0 && createDb();
166+
bool created = !leLayerName->text().isEmpty() &&
167+
( checkBoxPrimaryKey->isChecked() || mAttributeView->topLevelItemCount() > 0 ) &&
168+
createDb();
165169
mOkButton->setEnabled( created );
166170
}
167171

168172
void QgsNewSpatialiteLayerDialog::on_mAddAttributeButton_clicked()
169173
{
170-
if ( mNameEdit->text().length() > 0 )
174+
if ( !mNameEdit->text().isEmpty() )
171175
{
172176
QString myName = mNameEdit->text();
173177
//use userrole to avoid translated type string
174178
QString myType = mTypeBox->itemData( mTypeBox->currentIndex(), Qt::UserRole ).toString();
175179
mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << myName << myType ) );
176-
if ( mAttributeView->topLevelItemCount() > 0 && leLayerName->text().length() > 0 )
177-
{
178-
bool created = createDb();
179-
mOkButton->setEnabled( created );
180-
}
180+
181+
checkOk();
182+
181183
mNameEdit->clear();
182184
}
183185
}
184186

185187
void QgsNewSpatialiteLayerDialog::on_mRemoveAttributeButton_clicked()
186188
{
187189
delete mAttributeView->currentItem();
188-
if ( mAttributeView->topLevelItemCount() == 0 )
189-
{
190-
mOkButton->setEnabled( false );
191-
}
190+
191+
checkOk();
192192
}
193193

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

348348
if ( checkBoxPrimaryKey->isChecked() )
349349
{
350-
sql += "pkuid integer primary key autoincrement,";
350+
sql += "pkuid integer primary key autoincrement";
351+
delim = ",";
351352
}
352353

353354
QTreeWidgetItemIterator it( mAttributeView );
354355
while ( *it )
355356
{
356357
sql += delim + QString( "%1 %2" ).arg( quotedIdentifier(( *it )->text( 0 ) ), ( *it )->text( 1 ) );
357-
358-
delim = ',';
359-
358+
delim = ",";
360359
++it;
361360
}
362361

src/app/qgsnewspatialitelayerdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ class APP_EXPORT QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNew
4242
void on_mRemoveAttributeButton_clicked();
4343
void on_mTypeBox_currentIndexChanged( int index );
4444
void on_pbnFindSRID_clicked();
45-
void on_leLayerName_textChanged( const QString& text );
4645
void on_toolButtonNewDatabase_clicked();
4746
void nameChanged( const QString& );
4847
void selectionChanged();
48+
void checkOk();
4949

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

0 commit comments

Comments
 (0)