Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 f2f7236
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/layout/qgslayoutmanager.sip.in
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions python/gui/auto_generated/qgsnewnamedialog.sip.in
Expand Up @@ -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 );
Expand Down
28 changes: 19 additions & 9 deletions src/app/qgisapp.cpp
Expand Up @@ -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;
}

Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutmanager.h
Expand Up @@ -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 );

Expand Down
8 changes: 7 additions & 1 deletion src/gui/qgsnewnamedialog.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
16 changes: 16 additions & 0 deletions src/gui/qgsnewnamedialog.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit f2f7236

Please sign in to comment.