20#include <QRegularExpressionValidator>
27 const QString &initial,
28 const QStringList &extensions,
29 const QStringList &existing,
30 Qt::CaseSensitivity cs,
32 Qt::WindowFlags flags )
33 :
QgsDialog( parent, flags, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
34 , mExiting( existing )
35 , mExtensions( extensions )
36 , mCaseSensitivity( cs )
38 setWindowTitle( tr(
"New Name" ) );
40 layout()->setSizeConstraint( QLayout::SetMinimumSize );
44 const QString nameDesc =
mExtensions.isEmpty() ? tr(
"name" ) : tr(
"base name" );
45 if ( source.isEmpty() )
47 hintString = tr(
"Enter new %1" ).arg( nameDesc );
51 hintString = tr(
"Enter new %1 for %2" ).arg( nameDesc, source );
56 mLineEdit =
new QLineEdit( initial,
this );
63 mNamesLabel =
new QLabel( QStringLiteral(
" " ),
this );
64 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
71 mErrorLabel =
new QLabel( QStringLiteral(
" " ),
this );
72 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
112 if ( !expression.isEmpty() )
114 mRegularExpression = QRegularExpression( QRegularExpression::anchoredPattern( expression ) );
115 QRegularExpressionValidator *validator =
new QRegularExpressionValidator(
mRegularExpression,
this );
128 return "<b>" + text +
"</b>";
133 QString namesString = tr(
"Full names" ) +
": ";
139 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
141 okButton->setEnabled(
true );
143 const QString newName =
name();
155 namesString +=
' ' + newNames.join( QLatin1String(
", " ) );
161 if ( !conflicts.isEmpty() )
164 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QLatin1String(
", " ) ) );
168 okButton->setText( tr(
"Overwrite" ) );
172 okButton->setEnabled(
false );
186 const auto constExtensions = extensions;
187 for (
const QString &ext : constExtensions )
192 if ( list.isEmpty() )
200 Qt::CaseSensitivity cs )
204 const auto constNewNames = newNames;
205 for (
const QString &newName : constNewNames )
207 const auto constExistingNames = existingNames;
208 for (
const QString &existingName : constExistingNames )
210 if ( existingName.compare( newName, cs ) == 0 )
212 list << existingName;
220 const QStringList &existing, Qt::CaseSensitivity cs )
223 const QStringList conflicts =
matching( newNames, existing, cs );
224 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.