25#include <QRegularExpressionValidator>
28#include "moc_qgsnewnamedialog.cpp"
30QgsNewNameDialog::QgsNewNameDialog(
const QString &source,
const QString &initial,
const QStringList &extensions,
const QStringList &existing, Qt::CaseSensitivity cs, QWidget *parent, Qt::WindowFlags flags )
31 :
QgsDialog( parent, flags, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
36 setWindowTitle( tr(
"New Name" ) );
38 layout()->setSizeConstraint( QLayout::SetMinimumSize );
42 const QString nameDesc =
mExtensions.isEmpty() ? tr(
"name" ) : tr(
"base name" );
43 if ( source.isEmpty() )
45 hintString = tr(
"Enter new %1" ).arg( nameDesc );
49 hintString = tr(
"Enter new %1 for %2" ).arg( nameDesc, source );
54 mLineEdit =
new QLineEdit( initial,
this );
61 mNamesLabel =
new QLabel( QStringLiteral(
" " ),
this );
62 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
69 mErrorLabel =
new QLabel( QStringLiteral(
" " ),
this );
70 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
110 if ( !expression.isEmpty() )
112 mRegularExpression = QRegularExpression( QRegularExpression::anchoredPattern( expression ) );
113 QRegularExpressionValidator *validator =
new QRegularExpressionValidator(
mRegularExpression,
this );
132 QCompleter *completer =
new QCompleter(
mExiting,
this );
133 completer->setCaseSensitivity( Qt::CaseInsensitive );
134 completer->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
140 return "<b>" + text +
"</b>";
145 QString namesString = tr(
"Full names" ) +
": ";
151 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
153 okButton->setEnabled(
true );
155 const QString newName =
name();
167 namesString +=
' ' + newNames.join( QLatin1String(
", " ) );
173 if ( !conflicts.isEmpty() )
176 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QLatin1String(
", " ) ) );
180 okButton->setText( tr(
"Overwrite" ) );
184 okButton->setEnabled(
false );
198 const auto constExtensions = extensions;
199 for (
const QString &ext : constExtensions )
203 if ( list.isEmpty() )
214 const auto constNewNames = newNames;
215 for (
const QString &newName : constNewNames )
217 const auto constExistingNames = existingNames;
218 for (
const QString &existingName : constExistingNames )
220 if ( existingName.compare( newName, cs ) == 0 )
222 list << existingName;
232 const QStringList conflicts =
matching( newNames, existing, cs );
233 return !conflicts.isEmpty();
QDialogButtonBox * buttonBox()
Returns the button box.
QgsDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Close, Qt::Orientation orientation=Qt::Horizontal)
Constructor for QgsDialog.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.