Skip to content

Commit

Permalink
Remove Apply button from new spatialite layer dialog,
Browse files Browse the repository at this point in the history
activate add and remove attribute buttons only when appropriate
  • Loading branch information
brushtyler committed Jan 13, 2012
1 parent b186f83 commit ca6cd81
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
33 changes: 21 additions & 12 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -66,12 +66,8 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
}
settings.endGroup();

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( false );

connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );

buttonBox->button( QDialogButtonBox::Ok )->setDefault( true );
mOkButton = buttonBox->button( QDialogButtonBox::Ok );
mOkButton->setEnabled( false );

// Set the SRID box to a default of WGS84
QgsCoordinateReferenceSystem srs;
Expand All @@ -81,6 +77,12 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W
leSRID->setText( srs.authid() + " - " + srs.description() );

pbnFindSRID->setEnabled( mDatabaseComboBox->count() );

connect( mNameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( nameChanged( QString ) ) );
connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );

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

QgsNewSpatialiteLayerDialog::~QgsNewSpatialiteLayerDialog()
Expand Down Expand Up @@ -154,8 +156,7 @@ void QgsNewSpatialiteLayerDialog::on_leLayerName_textChanged( QString text )
{
Q_UNUSED( text );
bool created = leLayerName->text().length() > 0 && mAttributeView->topLevelItemCount() > 0 && createDb();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( created );
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( created );
mOkButton->setEnabled( created );
}

void QgsNewSpatialiteLayerDialog::on_mAddAttributeButton_clicked()
Expand All @@ -169,8 +170,7 @@ void QgsNewSpatialiteLayerDialog::on_mAddAttributeButton_clicked()
if ( mAttributeView->topLevelItemCount() > 0 && leLayerName->text().length() > 0 )
{
bool created = createDb();
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( created );
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( created );
mOkButton->setEnabled( created );
}
mNameEdit->clear();
}
Expand All @@ -181,8 +181,7 @@ void QgsNewSpatialiteLayerDialog::on_mRemoveAttributeButton_clicked()
delete mAttributeView->currentItem();
if ( mAttributeView->topLevelItemCount() == 0 )
{
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( false );
mOkButton->setEnabled( false );
}
}

Expand Down Expand Up @@ -251,6 +250,16 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked()
delete mySelector;
}

void QgsNewSpatialiteLayerDialog::nameChanged( QString name )
{
mAddAttributeButton->setDisabled( name.isEmpty() || mAttributeView->findItems( name, Qt::MatchExactly ).size() > 0 );
}

void QgsNewSpatialiteLayerDialog::selectionChanged()
{
mRemoveAttributeButton->setDisabled( mAttributeView->selectedItems().size() == 0 );
}

bool QgsNewSpatialiteLayerDialog::createDb()
{
QString dbPath = mDatabaseComboBox->currentText();
Expand Down
7 changes: 5 additions & 2 deletions src/app/qgsnewspatialitelayerdialog.h
Expand Up @@ -44,23 +44,26 @@ class QgsNewSpatialiteLayerDialog: public QDialog, private Ui::QgsNewSpatialiteL
void on_pbnFindSRID_clicked();
void on_leLayerName_textChanged( QString text );
void on_toolButtonNewDatabase_clicked();
void nameChanged( QString );
void selectionChanged();

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

bool apply();

private:
/**Returns the selected geometry type*/
QString selectedType() const;

/** Create a new database */
bool createDb();

bool apply();

static QString quotedIdentifier( QString id );
static QString quotedValue( QString value );

QPushButton *mOkButton;
int mCrsId;
};

Expand Down
20 changes: 2 additions & 18 deletions src/ui/qgsnewspatialitelayerdialogbase.ui
Expand Up @@ -45,7 +45,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>410</width>
<width>430</width>
<height>574</height>
</rect>
</property>
Expand Down Expand Up @@ -421,7 +421,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
Expand Down Expand Up @@ -449,22 +449,6 @@
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QgsNewSpatialiteLayerDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>364</x>
<y>585</y>
</hint>
<hint type="destinationlabel">
<x>387</x>
<y>304</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
Expand Down

0 comments on commit ca6cd81

Please sign in to comment.