|
| 1 | +/** \ingroup gui |
| 2 | + * New name, for example new layer name dialog. If existing names are provided, |
| 3 | + * the dialog warns users if an entered name already exists. |
| 4 | + * @note added in 2.10 |
| 5 | + */ |
| 6 | +class QgsNewNameDialog : QgsDialog |
| 7 | +{ |
| 8 | +%TypeHeaderCode |
| 9 | +#include <qgsnewnamedialog.h> |
| 10 | +%End |
| 11 | + |
| 12 | + public: |
| 13 | + /** New dialog constructor. |
| 14 | + * @param source original data source name, e.g. original layer name of the layer to be copied |
| 15 | + * @param initial initial name |
| 16 | + * @param extensions base name extensions, e.g. raster base name band extensions or vector layer type extensions |
| 17 | + * @param existing existing names |
| 18 | + * @param regexp regular expression to be used as validator, for example db tables should have "[A-Za-z_][A-Za-z0-9_]+" |
| 19 | + * @param cs case sensitivity for new name to existing names comparison |
| 20 | + * @param parent |
| 21 | + * @param flags |
| 22 | + */ |
| 23 | + QgsNewNameDialog( const QString& source = QString::null, const QString& initial = QString::null, |
| 24 | + const QStringList& extensions = QStringList(), const QStringList& existing = QStringList(), |
| 25 | + const QRegExp& regexp = QRegExp(), Qt::CaseSensitivity cs = Qt::CaseSensitive, |
| 26 | + QWidget *parent /TransferThis/ = 0, Qt::WindowFlags flags = QgisGui::ModalDialogFlags ); |
| 27 | + |
| 28 | + /** Sets the hint string for the dialog (the text shown above the name |
| 29 | + * input box). |
| 30 | + * @param hintString hint text |
| 31 | + * @see hintString() |
| 32 | + * @note added in QGIS 2.12 |
| 33 | + */ |
| 34 | + void setHintString( const QString& hintString ); |
| 35 | + |
| 36 | + /** Returns the hint string for the dialog (the text shown above the name |
| 37 | + * input box). |
| 38 | + * @see setHintString() |
| 39 | + * @note added in QGIS 2.12 |
| 40 | + */ |
| 41 | + QString hintString() const; |
| 42 | + |
| 43 | + /** Sets whether users are permitted to overwrite existing names. If true, then |
| 44 | + * the dialog will reflect that the new name will overwrite an existing name. If false, |
| 45 | + * then the dialog will not accept names which already exist. |
| 46 | + * @note added in QGIS 2.12 |
| 47 | + * @see overwriteEnabled() |
| 48 | + */ |
| 49 | + void setOverwriteEnabled( bool enabled ); |
| 50 | + |
| 51 | + /** Returns whether users are permitted to overwrite existing names. |
| 52 | + * @note added in QGIS 2.12 |
| 53 | + * @see setOverwriteEnabled() |
| 54 | + */ |
| 55 | + bool overwriteEnabled() const; |
| 56 | + |
| 57 | + /** Sets the string used for warning users if a conflicting name exists. |
| 58 | + * @param string warning string. If empty a default warning string will be used. |
| 59 | + * @note added in QGIS 2.12 |
| 60 | + * @see conflictingNameWarning() |
| 61 | + */ |
| 62 | + void setConflictingNameWarning( const QString& string ); |
| 63 | + |
| 64 | + /** Returns the string used for warning users if a conflicting name exists. |
| 65 | + * @note added in QGIS 2.12 |
| 66 | + * @see setConflictingNameWarning() |
| 67 | + */ |
| 68 | + QString conflictingNameWarning() const; |
| 69 | + |
| 70 | + /** Name entered by user. |
| 71 | + * @return new name |
| 72 | + */ |
| 73 | + QString name() const; |
| 74 | + |
| 75 | + /** Test if name or name with at least one extension exists. |
| 76 | + * @param name name or base name |
| 77 | + * @param extensions base name extensions |
| 78 | + * @param existing existing names |
| 79 | + * @param cs case sensitivity for new name to existing names comparison |
| 80 | + * @return true if name exists |
| 81 | + */ |
| 82 | + static bool exists( const QString& name, const QStringList& extensions, |
| 83 | + const QStringList& existing, Qt::CaseSensitivity cs = Qt::CaseSensitive ); |
| 84 | + public slots: |
| 85 | + void nameChanged(); |
| 86 | + |
| 87 | + protected: |
| 88 | + |
| 89 | + QString highlightText( const QString& text ); |
| 90 | + static QStringList fullNames( const QString& name, const QStringList& extensions ); |
| 91 | + // get list of existing names |
| 92 | + static QStringList matching( const QStringList& newNames, const QStringList& existingNames, |
| 93 | + Qt::CaseSensitivity cs = Qt::CaseSensitive ); |
| 94 | +}; |
| 95 | + |
0 commit comments