25#include <QRegularExpressionValidator>
29#include "moc_qgsnewnamedialog.cpp"
31using namespace Qt::StringLiterals;
33QgsNewNameDialog::QgsNewNameDialog(
const QString &source,
const QString &initial,
const QStringList &extensions,
const QStringList &existing, Qt::CaseSensitivity cs, QWidget *parent, Qt::WindowFlags flags )
34 :
QgsDialog( parent, flags, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
39 setWindowTitle( tr(
"New Name" ) );
41 layout()->setSizeConstraint( QLayout::SetMinimumSize );
45 const QString nameDesc =
mExtensions.isEmpty() ? tr(
"name" ) : tr(
"base name" );
46 if ( source.isEmpty() )
48 hintString = tr(
"Enter new %1" ).arg( nameDesc );
52 hintString = tr(
"Enter new %1 for %2" ).arg( nameDesc, source );
57 mLineEdit =
new QLineEdit( initial,
this );
65 mNamesLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
73 mErrorLabel->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
113 if ( !expression.isEmpty() )
115 mRegularExpression = QRegularExpression( QRegularExpression::anchoredPattern( expression ) );
116 QRegularExpressionValidator *validator =
new QRegularExpressionValidator(
mRegularExpression,
this );
135 QCompleter *completer =
new QCompleter(
mExiting,
this );
136 completer->setCaseSensitivity( Qt::CaseInsensitive );
137 completer->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
143 return "<b>" + text +
"</b>";
148 QString namesString = tr(
"Full names" ) +
": ";
154 QPushButton *okButton =
buttonBox()->button( QDialogButtonBox::Ok );
156 okButton->setEnabled(
true );
158 const QString newName =
name();
170 namesString +=
' ' + newNames.join(
", "_L1 );
176 if ( !conflicts.isEmpty() )
179 : tr(
"%n Name(s) %1 exists",
nullptr, conflicts.size() ).arg( conflicts.join(
", "_L1 ) );
183 okButton->setText( tr(
"Overwrite" ) );
187 okButton->setEnabled(
false );
201 const auto constExtensions = extensions;
202 for (
const QString &ext : constExtensions )
206 if ( list.isEmpty() )
217 const auto constNewNames = newNames;
218 for (
const QString &newName : constNewNames )
220 const auto constExistingNames = existingNames;
221 for (
const QString &existingName : constExistingNames )
223 if ( existingName.compare( newName, cs ) == 0 )
225 list << existingName;
235 const QStringList conflicts =
matching( newNames, existing, cs );
236 return !conflicts.isEmpty();
QDialogButtonBox * buttonBox()
Returns the button box.
QgsDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Close, Qt::Orientation orientation=Qt::Horizontal)
Constructor for QgsDialog.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.