@@ -205,6 +205,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
205
205
#include "qgslayertreeutils.h"
206
206
#include "qgslayertreeview.h"
207
207
#include "qgslayertreeviewdefaultactions.h"
208
+ #include "qgslayout.h"
208
209
#include "qgslayoutcustomdrophandler.h"
209
210
#include "qgslayoutdesignerdialog.h"
210
211
#include "qgslayoutmanager.h"
@@ -7333,6 +7334,71 @@ bool QgisApp::uniqueComposerTitle( QWidget *parent, QString &composerTitle, bool
7333
7334
return true;
7334
7335
}
7335
7336
7337
+ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmpty, const QString ¤tTitle )
7338
+ {
7339
+ if ( !parent )
7340
+ {
7341
+ parent = this;
7342
+ }
7343
+ bool ok = false;
7344
+ bool titleValid = false;
7345
+ QString newTitle = QString( currentTitle );
7346
+ QString chooseMsg = tr( "Create unique print layout title" );
7347
+ if ( acceptEmpty )
7348
+ {
7349
+ chooseMsg += '\n' + tr( "(title generated if left empty)" );
7350
+ }
7351
+ QString titleMsg = chooseMsg;
7352
+
7353
+ QStringList cNames;
7354
+ cNames << newTitle;
7355
+ #if 0 //TODO
7356
+ Q_FOREACH ( QgsComposition *c, QgsProject::instance()->layoutManager()->compositions() )
7357
+ {
7358
+ cNames << c->name();
7359
+ }
7360
+ #endif
7361
+ while ( !titleValid )
7362
+ {
7363
+ newTitle = QInputDialog::getText( parent,
7364
+ tr( "Layout title" ),
7365
+ titleMsg,
7366
+ QLineEdit::Normal,
7367
+ newTitle,
7368
+ &ok );
7369
+ if ( !ok )
7370
+ {
7371
+ return false;
7372
+ }
7373
+
7374
+ if ( newTitle.isEmpty() )
7375
+ {
7376
+ if ( !acceptEmpty )
7377
+ {
7378
+ titleMsg = chooseMsg + "\n\n" + tr( "Title can not be empty!" );
7379
+ }
7380
+ else
7381
+ {
7382
+ titleValid = true;
7383
+ newTitle = QgsProject::instance()->layoutManager()->generateUniqueTitle();
7384
+ }
7385
+ }
7386
+ else if ( cNames.indexOf( newTitle, 1 ) >= 0 )
7387
+ {
7388
+ cNames[0] = QString(); // clear non-unique name
7389
+ titleMsg = chooseMsg + "\n\n" + tr( "Title already exists!" );
7390
+ }
7391
+ else
7392
+ {
7393
+ titleValid = true;
7394
+ }
7395
+ }
7396
+
7397
+ title = newTitle;
7398
+
7399
+ return true;
7400
+ }
7401
+
7336
7402
QgsComposer *QgisApp::createNewComposer( QString title )
7337
7403
{
7338
7404
if ( title.isEmpty() )
@@ -7441,6 +7507,21 @@ QgsComposer *QgisApp::duplicateComposer( QgsComposer *currentComposer, QString t
7441
7507
return newComposer;
7442
7508
}
7443
7509
7510
+ QgsLayoutDesignerDialog *QgisApp::duplicateLayout( QgsLayout *layout, const QString &t )
7511
+ {
7512
+ QString title = t;
7513
+ if ( title.isEmpty() )
7514
+ {
7515
+ // TODO: inject a bit of randomness in auto-titles?
7516
+ title = tr( "%1 copy" ).arg( layout->name() );
7517
+ }
7518
+
7519
+ QgsLayout *newLayout = QgsProject::instance()->layoutManager()->duplicateLayout( layout, title );
7520
+ QgsLayoutDesignerDialog *dlg = openLayoutDesignerDialog( newLayout );
7521
+ dlg->activate();
7522
+ return dlg;
7523
+ }
7524
+
7444
7525
void QgisApp::deletePrintComposers()
7445
7526
{
7446
7527
QSet<QgsComposer *>::iterator it = mPrintComposers.begin();
0 commit comments