19 #include <QPushButton>
20 #include <QRegExpValidator>
21 #include <QSizePolicy>
27 const QStringList &extensions,
const QStringList &existing,
28 const QRegExp ®exp, Qt::CaseSensitivity cs,
29 QWidget *parent, Qt::WindowFlags flags )
30 :
QgsDialog( parent, flags, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
31 , mExiting( existing )
32 , mExtensions( extensions )
33 , mCaseSensitivity( cs )
36 setWindowTitle( tr(
"New Name" ) );
38 layout()->setSizeConstraint( QLayout::SetMinimumSize );
42 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 );
55 if ( !regexp.isEmpty() )
57 QRegExpValidator *validator =
new QRegExpValidator( regexp,
this );
62 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
63 mLineEdit->setMinimumWidth(
mLineEdit->fontMetrics().width( QStringLiteral(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) ) );
71 mNamesLabel =
new QLabel( QStringLiteral(
" " ),
this );
72 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
79 mErrorLabel =
new QLabel( QStringLiteral(
" " ),
this );
80 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
120 return "<b>" + text +
"</b>";
126 QString namesString = tr(
"Full names" ) +
": ";
132 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
134 okButton->setEnabled(
true );
136 QString newName =
name();
138 if ( newName.length() == 0 || ( !
mRegexp.isEmpty() && !
mRegexp.exactMatch( newName ) ) )
148 namesString +=
' ' + newNames.join( QLatin1String(
", " ) );
154 if ( !conflicts.isEmpty() )
157 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QLatin1String(
", " ) ) );
161 okButton->setText( tr(
"Overwrite" ) );
165 okButton->setEnabled(
false );
179 const auto constExtensions = extensions;
180 for (
const QString &ext : constExtensions )
185 if ( list.isEmpty() )
193 Qt::CaseSensitivity cs )
197 const auto constNewNames = newNames;
198 for (
const QString &newName : constNewNames )
200 const auto constExistingNames = existingNames;
201 for (
const QString &existingName : constExistingNames )
203 if ( existingName.compare( newName, cs ) == 0 )
205 list << existingName;
213 const QStringList &existing, Qt::CaseSensitivity cs )
216 QStringList conflicts =
matching( newNames, existing, cs );
217 return !conflicts.isEmpty();