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 );
67 mNamesLabel =
new QLabel( QStringLiteral(
" " ),
this );
68 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
75 mErrorLabel =
new QLabel( QStringLiteral(
" " ),
this );
76 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
116 return "<b>" + text +
"</b>";
122 QString namesString = tr(
"Full names" ) +
": ";
128 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
130 okButton->setEnabled(
true );
132 QString newName =
name();
134 if ( newName.length() == 0 || ( !
mRegexp.isEmpty() && !
mRegexp.exactMatch( newName ) ) )
144 namesString +=
' ' + newNames.join( QLatin1String(
", " ) );
150 if ( !conflicts.isEmpty() )
153 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QLatin1String(
", " ) ) );
157 okButton->setText( tr(
"Overwrite" ) );
161 okButton->setEnabled(
false );
175 const auto constExtensions = extensions;
176 for (
const QString &ext : constExtensions )
181 if ( list.isEmpty() )
189 Qt::CaseSensitivity cs )
193 const auto constNewNames = newNames;
194 for (
const QString &newName : constNewNames )
196 const auto constExistingNames = existingNames;
197 for (
const QString &existingName : constExistingNames )
199 if ( existingName.compare( newName, cs ) == 0 )
201 list << existingName;
209 const QStringList &existing, Qt::CaseSensitivity cs )
212 QStringList conflicts =
matching( newNames, existing, cs );
213 return !conflicts.isEmpty();
A generic dialog with layout and button box.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
QDialogButtonBox * buttonBox()
Returns the button box.