20#include <QRegularExpressionValidator>
25#include "moc_qgsnewnamedialog.cpp"
27QgsNewNameDialog::QgsNewNameDialog(
const QString &source,
const QString &initial,
const QStringList &extensions,
const QStringList &existing, Qt::CaseSensitivity cs, QWidget *parent, Qt::WindowFlags flags )
28 :
QgsDialog( parent, flags, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
29 , mExiting( existing )
30 , mExtensions( extensions )
31 , mCaseSensitivity( cs )
33 setWindowTitle( tr(
"New Name" ) );
35 layout()->setSizeConstraint( QLayout::SetMinimumSize );
39 const QString nameDesc =
mExtensions.isEmpty() ? tr(
"name" ) : tr(
"base name" );
40 if ( source.isEmpty() )
42 hintString = tr(
"Enter new %1" ).arg( nameDesc );
46 hintString = tr(
"Enter new %1 for %2" ).arg( nameDesc, source );
51 mLineEdit =
new QLineEdit( initial,
this );
58 mNamesLabel =
new QLabel( QStringLiteral(
" " ),
this );
59 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
66 mErrorLabel =
new QLabel( QStringLiteral(
" " ),
this );
67 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
107 if ( !expression.isEmpty() )
109 mRegularExpression = QRegularExpression( QRegularExpression::anchoredPattern( expression ) );
110 QRegularExpressionValidator *validator =
new QRegularExpressionValidator(
mRegularExpression,
this );
123 return "<b>" + text +
"</b>";
128 QString namesString = tr(
"Full names" ) +
": ";
134 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
136 okButton->setEnabled(
true );
138 const QString newName =
name();
150 namesString +=
' ' + newNames.join( QLatin1String(
", " ) );
156 if ( !conflicts.isEmpty() )
159 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join( QLatin1String(
", " ) ) );
163 okButton->setText( tr(
"Overwrite" ) );
167 okButton->setEnabled(
false );
181 const auto constExtensions = extensions;
182 for (
const QString &ext : constExtensions )
186 if ( list.isEmpty() )
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;
212bool QgsNewNameDialog::exists(
const QString &name,
const QStringList &extensions,
const QStringList &existing, Qt::CaseSensitivity cs )
215 const QStringList conflicts =
matching( newNames, existing, cs );
216 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.