20#include <QRegularExpressionValidator>
25#include "moc_qgsnewnamedialog.cpp"
28 const QString &initial,
29 const QStringList &extensions,
30 const QStringList &existing,
31 Qt::CaseSensitivity cs,
33 Qt::WindowFlags flags )
34 :
QgsDialog( parent, flags, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
35 , mExiting( existing )
36 , mExtensions( extensions )
37 , mCaseSensitivity( cs )
39 setWindowTitle( tr(
"New Name" ) );
41 layout()->setSizeConstraint( QLayout::SetMinimumSize );
45 const QString nameDesc =
mExtensions.isEmpty() ? tr(
"name" ) : tr(
"base name" );
46 if ( source.isEmpty() )
48 hintString = tr(
"Enter new %1" ).arg( nameDesc );
52 hintString = tr(
"Enter new %1 for %2" ).arg( nameDesc, source );
57 mLineEdit =
new QLineEdit( initial,
this );
64 mNamesLabel =
new QLabel( QStringLiteral(
" " ),
this );
65 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
72 mErrorLabel =
new QLabel( QStringLiteral(
" " ),
this );
73 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
113 if ( !expression.isEmpty() )
115 mRegularExpression = QRegularExpression( QRegularExpression::anchoredPattern( expression ) );
116 QRegularExpressionValidator *validator =
new QRegularExpressionValidator(
mRegularExpression,
this );
129 return "<b>" + text +
"</b>";
134 QString namesString = tr(
"Full names" ) +
": ";
140 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
142 okButton->setEnabled(
true );
144 const QString newName =
name();
156 namesString +=
' ' + newNames.join( QLatin1String(
", " ) );
162 if ( !conflicts.isEmpty() )
165 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QLatin1String(
", " ) ) );
169 okButton->setText( tr(
"Overwrite" ) );
173 okButton->setEnabled(
false );
187 const auto constExtensions = extensions;
188 for (
const QString &ext : constExtensions )
193 if ( list.isEmpty() )
201 Qt::CaseSensitivity cs )
205 const auto constNewNames = newNames;
206 for (
const QString &newName : constNewNames )
208 const auto constExistingNames = existingNames;
209 for (
const QString &existingName : constExistingNames )
211 if ( existingName.compare( newName, cs ) == 0 )
213 list << existingName;
221 const QStringList &existing, Qt::CaseSensitivity cs )
224 const QStringList conflicts =
matching( newNames, existing, cs );
225 return !conflicts.isEmpty();
A generic dialog with layout and button box.
QDialogButtonBox * buttonBox()
Returns the button box.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.