QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsnewnamedialog.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnewnamedialog.h
3  -------------------
4  begin : May, 2015
5  copyright : (C) 2015 Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSNEWNAMEDIALOG_H
18 #define QGSNEWNAMEDIALOG_H
19 
20 class QLabel;
21 class QLineEdit;
22 
23 #include "qgsdialog.h"
24 #include "qgis_gui.h"
25 #include <QRegularExpression>
26 
33 class GUI_EXPORT QgsNewNameDialog : public QgsDialog
34 {
35  Q_OBJECT
36  public:
37 
50  QgsNewNameDialog( const QString &source = QString(), const QString &initial = QString(),
51  const QStringList &extensions = QStringList(), const QStringList &existing = QStringList(),
52  Qt::CaseSensitivity cs = Qt::CaseSensitive,
53  QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = QgsGuiUtils::ModalDialogFlags );
54 
62  void setHintString( const QString &hintString );
63 
70  QString hintString() const;
71 
79  void setOverwriteEnabled( bool enabled );
80 
86  bool overwriteEnabled() const { return mOverwriteEnabled; }
87 
94  void setAllowEmptyName( bool allowed );
95 
101  bool allowEmptyName() const { return mAllowEmptyName; }
102 
109  void setConflictingNameWarning( const QString &string );
110 
116  QString conflictingNameWarning() const { return mConflictingNameWarning; }
117 
123  void setRegularExpression( const QString &expression );
124 
130  QString name() const;
131 
140  static bool exists( const QString &name, const QStringList &extensions,
141  const QStringList &existing, Qt::CaseSensitivity cs = Qt::CaseSensitive );
142  signals:
143 
144  // TODO QGIS 4.0 - rename to nameChanged
145 
150  void newNameChanged();
151 
152  public slots:
153  // TODO QGIS 4.0 - rename to onNameChanged
154  void nameChanged();
155 
156  protected:
157  QStringList mExiting;
158  QStringList mExtensions;
159  Qt::CaseSensitivity mCaseSensitivity = Qt::CaseSensitive;
160  QLabel *mHintLabel = nullptr;
161  QLineEdit *mLineEdit = nullptr;
163  QLabel *mNamesLabel = nullptr;
164  QLabel *mErrorLabel = nullptr;
165  QString mOkString;
166  QRegularExpression mRegularExpression;
167  bool mOverwriteEnabled = true;
168  bool mAllowEmptyName = false;
170 
171  QString highlightText( const QString &text );
172  static QStringList fullNames( const QString &name, const QStringList &extensions );
173  // get list of existing names
174  static QStringList matching( const QStringList &newNames, const QStringList &existingNames,
175  Qt::CaseSensitivity cs = Qt::CaseSensitive );
176 };
177 
178 #endif // QGSNEWNAMEDIALOG_H
QgsDialog
A generic dialog with layout and button box.
Definition: qgsdialog.h:33
QgsNewNameDialog::allowEmptyName
bool allowEmptyName() const
Returns true if the widget can be left empty (no name filled).
Definition: qgsnewnamedialog.h:101
QgsNewNameDialog::mOkString
QString mOkString
Definition: qgsnewnamedialog.h:165
QgsNewNameDialog::mExiting
QStringList mExiting
Definition: qgsnewnamedialog.h:157
QgsNewNameDialog::mRegularExpression
QRegularExpression mRegularExpression
Definition: qgsnewnamedialog.h:166
QgsNewNameDialog
New name, for example new layer name dialog. If existing names are provided, the dialog warns users i...
Definition: qgsnewnamedialog.h:33
QgsNewNameDialog::mConflictingNameWarning
QString mConflictingNameWarning
Definition: qgsnewnamedialog.h:169
qgsdialog.h
QgsNewNameDialog::overwriteEnabled
bool overwriteEnabled() const
Returns whether users are permitted to overwrite existing names.
Definition: qgsnewnamedialog.h:86
QgsNewNameDialog::conflictingNameWarning
QString conflictingNameWarning() const
Returns the string used for warning users if a conflicting name exists.
Definition: qgsnewnamedialog.h:116
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsNewNameDialog::mExtensions
QStringList mExtensions
Definition: qgsnewnamedialog.h:158