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 );
60 mLineEdit->setMinimumWidth(
mLineEdit->fontMetrics().width( QStringLiteral(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) ) );
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 );
107 return "<b>" + text +
"</b>";
113 QString namesString = tr(
"Full names" ) +
": ";
119 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
121 okButton->setEnabled(
true );
123 QString newName =
name();
125 if ( newName.length() == 0 || ( !
mRegexp.isEmpty() && !
mRegexp.exactMatch( newName ) ) )
128 okButton->setEnabled(
false );
135 namesString +=
' ' + newNames.join( QStringLiteral(
", " ) );
141 if ( !conflicts.isEmpty() )
144 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QStringLiteral(
", " ) ) );
148 okButton->setText( tr(
"Overwrite" ) );
152 okButton->setEnabled(
false );
166 Q_FOREACH (
const QString &ext, extensions )
171 if ( list.isEmpty() )
179 Qt::CaseSensitivity cs )
183 Q_FOREACH (
const QString &newName, newNames )
185 Q_FOREACH (
const QString &existingName, existingNames )
187 if ( existingName.compare( newName, cs ) == 0 )
189 list << existingName;
197 const QStringList &existing, Qt::CaseSensitivity cs )
199 QStringList newNames =
fullNames( name, extensions );
200 QStringList conflicts =
matching( newNames, existing, cs );
201 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.