diff --git a/simplestringlisteditor.cpp b/simplestringlisteditor.cpp index 75d4e65bc..e57cf2907 100644 --- a/simplestringlisteditor.cpp +++ b/simplestringlisteditor.cpp @@ -166,6 +166,15 @@ QStringList SimpleStringListEditor::stringList() const { return result; } +bool SimpleStringListEditor::containsString( const QString & str ) { + for ( QListBoxItem * item = mListBox->firstItem() ; + item ; item = item->next() ) { + if ( item->text() == str ) + return true; + } + return false; +} + void SimpleStringListEditor::setButtonText( ButtonCode button, const QString & text ) { switch ( button ) { @@ -207,7 +216,7 @@ void SimpleStringListEditor::slotAdd() { &ok, this ); // let the user verify the string before adding emit aboutToAdd( newEntry ); - if ( ok && !newEntry.isEmpty() ) { + if ( ok && !newEntry.isEmpty() && !containsString( newEntry )) { mListBox->insertItem( newEntry ); emit changed(); } diff --git a/simplestringlisteditor.h b/simplestringlisteditor.h index fc9c0367f..2870fb11a 100644 --- a/simplestringlisteditor.h +++ b/simplestringlisteditor.h @@ -91,6 +91,7 @@ protected slots: void slotSelectionChanged(); protected: + bool containsString( const QString & str ); QListBox *mListBox; QPushButton *mAddButton; QPushButton *mRemoveButton;