Skip to content
Permalink
Browse files

Layout new name dialog

Make the new layout dialog use the qgsnewnamedialog class
Add/enable help button to open user manual chapters
  • Loading branch information
DelazJ committed Jun 19, 2020
1 parent 8472957 commit f2f7236fc8cc35d450ada7c96c3a7b0f0e74cf7e
@@ -106,7 +106,7 @@ Returns a DOM element representing the state of the manager.
%Docstring
Duplicates an existing ``layout`` from the manager. The new
layout will automatically be stored in the manager.
Returns new the layout if duplication was successful.
Returns the new layout if duplication was successful.
%End

QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;
@@ -80,6 +80,25 @@ Returns whether users are permitted to overwrite existing names.
.. seealso:: :py:func:`setOverwriteEnabled`

.. versionadded:: 2.12
%End

void setAllowEmptyName( bool allowed );
%Docstring
Sets whether users are permitted to leave the widget empty.
If ``True``, the dialog will accept an empty name value.

.. seealso:: :py:func:`allowEmptyName`

.. versionadded:: 3.14
%End

bool allowEmptyName() const;
%Docstring
Returns ``True`` if the widget can be left empty (no name filled).

.. seealso:: :py:func:`setAllowEmptyName`

.. versionadded:: 3.14
%End

void setConflictingNameWarning( const QString &string );
@@ -9189,18 +9189,20 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
{
parent = this;
}
bool ok = false;
bool titleValid = false;
QString newTitle = QString( currentTitle );

QString typeString;
QString helpPage;
switch ( type )
{
case QgsMasterLayoutInterface::PrintLayout:
typeString = tr( "print layout" );
helpPage = QStringLiteral( "print_composer/index.html" );
break;
case QgsMasterLayoutInterface::Report:
typeString = tr( "report" );
helpPage = QStringLiteral( "print_composer/create_reports.html" );
break;
}

@@ -9214,24 +9216,32 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
QStringList layoutNames;
const QList< QgsMasterLayoutInterface * > layouts = QgsProject::instance()->layoutManager()->layouts();
layoutNames.reserve( layouts.size() + 1 );
layoutNames << newTitle;
for ( QgsMasterLayoutInterface *l : layouts )
{
layoutNames << l->name();
}
while ( !titleValid )
{
newTitle = QInputDialog::getText( parent,
tr( "Create %1 Title" ).arg( typeString ),
titleMsg,
QLineEdit::Normal,
newTitle,
&ok );
if ( !ok )

QgsNewNameDialog dlg( typeString, newTitle, QStringList(), layoutNames, QRegExp(), Qt::CaseSensitive, parent );
dlg.setWindowTitle( tr( "Create %1 Title" ).arg( typeString ) );
dlg.setHintString( titleMsg );
dlg.setOverwriteEnabled( false );
dlg.setAllowEmptyName( true );
dlg.setConflictingNameWarning( tr( "Title already exists!" ) );

dlg.buttonBox()->addButton( QDialogButtonBox::Help );
connect( dlg.buttonBox(), &QDialogButtonBox::helpRequested, this, [ = ]
{
QgsHelp::openHelp( helpPage );
} );

if ( dlg.exec() != QDialog::Accepted )
{
return false;
}

newTitle = dlg.name();
if ( newTitle.isEmpty() )
{
if ( !acceptEmpty )
@@ -113,7 +113,7 @@ class CORE_EXPORT QgsLayoutManager : public QObject
/**
* Duplicates an existing \a layout from the manager. The new
* layout will automatically be stored in the manager.
* Returns new the layout if duplication was successful.
* Returns the new layout if duplication was successful.
*/
QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );

@@ -103,6 +103,12 @@ void QgsNewNameDialog::setOverwriteEnabled( bool enabled )
nameChanged(); //update UI
}

void QgsNewNameDialog::setAllowEmptyName( bool allowed )
{
mAllowEmptyName = allowed;
nameChanged(); //update UI
}

void QgsNewNameDialog::setConflictingNameWarning( const QString &string )
{
mConflictingNameWarning = string;
@@ -132,7 +138,7 @@ void QgsNewNameDialog::nameChanged()
if ( newName.length() == 0 || ( !mRegexp.isEmpty() && !mRegexp.exactMatch( newName ) ) )
{
//mErrorLabel->setText( highlightText( tr( "Enter new name" ) );
okButton->setEnabled( false );
okButton->setEnabled( mAllowEmptyName );
return;
}

@@ -83,6 +83,21 @@ class GUI_EXPORT QgsNewNameDialog : public QgsDialog
*/
bool overwriteEnabled() const { return mOverwriteEnabled; }

/**
* Sets whether users are permitted to leave the widget empty.
* If TRUE, the dialog will accept an empty name value.
* \see allowEmptyName()
* \since QGIS 3.14
*/
void setAllowEmptyName( bool allowed );

/**
* Returns TRUE if the widget can be left empty (no name filled).
* \see setAllowEmptyName()
* \since QGIS 3.14
*/
bool allowEmptyName() const { return mAllowEmptyName; }

/**
* Sets the string used for warning users if a conflicting name exists.
* \param string warning string. If empty a default warning string will be used.
@@ -141,6 +156,7 @@ class GUI_EXPORT QgsNewNameDialog : public QgsDialog
QString mOkString;
QRegExp mRegexp;
bool mOverwriteEnabled = true;
bool mAllowEmptyName = false;
QString mConflictingNameWarning;

QString highlightText( const QString &text );

0 comments on commit f2f7236

Please sign in to comment.
You can’t perform that action at this time.