@@ -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
9295QgsNewSpatialiteLayerDialog::~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
168172void 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
185187void 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
194194void 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
0 commit comments