Skip to content

Commit f2f7236

Browse files
authoredJun 19, 2020
Layout new name dialog
Make the new layout dialog use the qgsnewnamedialog class Add/enable help button to open user manual chapters
1 parent 8472957 commit f2f7236

File tree

6 files changed

+63
-12
lines changed

6 files changed

+63
-12
lines changed
 

‎python/core/auto_generated/layout/qgslayoutmanager.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Returns a DOM element representing the state of the manager.
106106
%Docstring
107107
Duplicates an existing ``layout`` from the manager. The new
108108
layout will automatically be stored in the manager.
109-
Returns new the layout if duplication was successful.
109+
Returns the new layout if duplication was successful.
110110
%End
111111

112112
QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;

‎python/gui/auto_generated/qgsnewnamedialog.sip.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ Returns whether users are permitted to overwrite existing names.
8080
.. seealso:: :py:func:`setOverwriteEnabled`
8181

8282
.. versionadded:: 2.12
83+
%End
84+
85+
void setAllowEmptyName( bool allowed );
86+
%Docstring
87+
Sets whether users are permitted to leave the widget empty.
88+
If ``True``, the dialog will accept an empty name value.
89+
90+
.. seealso:: :py:func:`allowEmptyName`
91+
92+
.. versionadded:: 3.14
93+
%End
94+
95+
bool allowEmptyName() const;
96+
%Docstring
97+
Returns ``True`` if the widget can be left empty (no name filled).
98+
99+
.. seealso:: :py:func:`setAllowEmptyName`
100+
101+
.. versionadded:: 3.14
83102
%End
84103

85104
void setConflictingNameWarning( const QString &string );

‎src/app/qgisapp.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9189,18 +9189,20 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
91899189
{
91909190
parent = this;
91919191
}
9192-
bool ok = false;
91939192
bool titleValid = false;
91949193
QString newTitle = QString( currentTitle );
91959194

91969195
QString typeString;
9196+
QString helpPage;
91979197
switch ( type )
91989198
{
91999199
case QgsMasterLayoutInterface::PrintLayout:
92009200
typeString = tr( "print layout" );
9201+
helpPage = QStringLiteral( "print_composer/index.html" );
92019202
break;
92029203
case QgsMasterLayoutInterface::Report:
92039204
typeString = tr( "report" );
9205+
helpPage = QStringLiteral( "print_composer/create_reports.html" );
92049206
break;
92059207
}
92069208

@@ -9214,24 +9216,32 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
92149216
QStringList layoutNames;
92159217
const QList< QgsMasterLayoutInterface * > layouts = QgsProject::instance()->layoutManager()->layouts();
92169218
layoutNames.reserve( layouts.size() + 1 );
9217-
layoutNames << newTitle;
92189219
for ( QgsMasterLayoutInterface *l : layouts )
92199220
{
92209221
layoutNames << l->name();
92219222
}
92229223
while ( !titleValid )
92239224
{
9224-
newTitle = QInputDialog::getText( parent,
9225-
tr( "Create %1 Title" ).arg( typeString ),
9226-
titleMsg,
9227-
QLineEdit::Normal,
9228-
newTitle,
9229-
&ok );
9230-
if ( !ok )
9225+
9226+
QgsNewNameDialog dlg( typeString, newTitle, QStringList(), layoutNames, QRegExp(), Qt::CaseSensitive, parent );
9227+
dlg.setWindowTitle( tr( "Create %1 Title" ).arg( typeString ) );
9228+
dlg.setHintString( titleMsg );
9229+
dlg.setOverwriteEnabled( false );
9230+
dlg.setAllowEmptyName( true );
9231+
dlg.setConflictingNameWarning( tr( "Title already exists!" ) );
9232+
9233+
dlg.buttonBox()->addButton( QDialogButtonBox::Help );
9234+
connect( dlg.buttonBox(), &QDialogButtonBox::helpRequested, this, [ = ]
9235+
{
9236+
QgsHelp::openHelp( helpPage );
9237+
} );
9238+
9239+
if ( dlg.exec() != QDialog::Accepted )
92319240
{
92329241
return false;
92339242
}
92349243

9244+
newTitle = dlg.name();
92359245
if ( newTitle.isEmpty() )
92369246
{
92379247
if ( !acceptEmpty )

‎src/core/layout/qgslayoutmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class CORE_EXPORT QgsLayoutManager : public QObject
113113
/**
114114
* Duplicates an existing \a layout from the manager. The new
115115
* layout will automatically be stored in the manager.
116-
* Returns new the layout if duplication was successful.
116+
* Returns the new layout if duplication was successful.
117117
*/
118118
QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
119119

‎src/gui/qgsnewnamedialog.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ void QgsNewNameDialog::setOverwriteEnabled( bool enabled )
103103
nameChanged(); //update UI
104104
}
105105

106+
void QgsNewNameDialog::setAllowEmptyName( bool allowed )
107+
{
108+
mAllowEmptyName = allowed;
109+
nameChanged(); //update UI
110+
}
111+
106112
void QgsNewNameDialog::setConflictingNameWarning( const QString &string )
107113
{
108114
mConflictingNameWarning = string;
@@ -132,7 +138,7 @@ void QgsNewNameDialog::nameChanged()
132138
if ( newName.length() == 0 || ( !mRegexp.isEmpty() && !mRegexp.exactMatch( newName ) ) )
133139
{
134140
//mErrorLabel->setText( highlightText( tr( "Enter new name" ) );
135-
okButton->setEnabled( false );
141+
okButton->setEnabled( mAllowEmptyName );
136142
return;
137143
}
138144

‎src/gui/qgsnewnamedialog.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ class GUI_EXPORT QgsNewNameDialog : public QgsDialog
8383
*/
8484
bool overwriteEnabled() const { return mOverwriteEnabled; }
8585

86+
/**
87+
* Sets whether users are permitted to leave the widget empty.
88+
* If TRUE, the dialog will accept an empty name value.
89+
* \see allowEmptyName()
90+
* \since QGIS 3.14
91+
*/
92+
void setAllowEmptyName( bool allowed );
93+
94+
/**
95+
* Returns TRUE if the widget can be left empty (no name filled).
96+
* \see setAllowEmptyName()
97+
* \since QGIS 3.14
98+
*/
99+
bool allowEmptyName() const { return mAllowEmptyName; }
100+
86101
/**
87102
* Sets the string used for warning users if a conflicting name exists.
88103
* \param string warning string. If empty a default warning string will be used.
@@ -141,6 +156,7 @@ class GUI_EXPORT QgsNewNameDialog : public QgsDialog
141156
QString mOkString;
142157
QRegExp mRegexp;
143158
bool mOverwriteEnabled = true;
159+
bool mAllowEmptyName = false;
144160
QString mConflictingNameWarning;
145161

146162
QString highlightText( const QString &text );

0 commit comments

Comments
 (0)
Please sign in to comment.