Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][layouts] Support drag and drop of QPT templates onto layout…
… windows To add contents of template onto layout
- Loading branch information
1 parent
eea36c0
commit a64a675
Showing
17 changed files
with
180 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,6 @@ class QgsLayoutAppUtils | |
|
||
}; | ||
|
||
|
||
|
||
#endif // QGSLAYOUTAPPUTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*************************************************************************** | ||
qgslayoutqptdrophandler.cpp | ||
------------------------------ | ||
begin : December 2017 | ||
copyright : (C) 2017 by nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayoutqptdrophandler.h" | ||
#include "qgslayoutdesignerinterface.h" | ||
#include "qgslayout.h" | ||
#include "qgsreadwritecontext.h" | ||
#include "qgsproject.h" | ||
#include "qgslayoutview.h" | ||
#include <QMessageBox> | ||
|
||
QgsLayoutQptDropHandler::QgsLayoutQptDropHandler( QObject *parent ) | ||
: QgsLayoutCustomDropHandler( parent ) | ||
{ | ||
|
||
} | ||
|
||
bool QgsLayoutQptDropHandler::handleFileDrop( QgsLayoutDesignerInterface *iface, const QString &file ) | ||
{ | ||
QFileInfo fi( file ); | ||
if ( !fi.suffix().compare( QLatin1String( "qpt" ), Qt::CaseInsensitive ) == 0 ) | ||
return false; | ||
|
||
QFile templateFile( file ); | ||
if ( !templateFile.open( QIODevice::ReadOnly ) ) | ||
{ | ||
QMessageBox::warning( iface->view(), tr( "Load from template" ), tr( "Could not read template file." ) ); | ||
return true; | ||
} | ||
|
||
QDomDocument templateDoc; | ||
QgsReadWriteContext context; | ||
context.setPathResolver( QgsProject::instance()->pathResolver() ); | ||
if ( templateDoc.setContent( &templateFile ) ) | ||
{ | ||
bool ok = false; | ||
QList< QgsLayoutItem * > items = iface->layout()->loadFromTemplate( templateDoc, context, false, &ok ); | ||
if ( !ok ) | ||
{ | ||
QMessageBox::warning( iface->view(), tr( "Load from template" ), tr( "Could not read template file." ) ); | ||
return true; | ||
} | ||
else | ||
{ | ||
whileBlocking( iface->layout() )->deselectAll(); | ||
iface->selectItems( items ); | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*************************************************************************** | ||
qgslayoutqptdrophandler.h | ||
------------------------- | ||
begin : December 2017 | ||
copyright : (C) 2017 by nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYOUTQPTDROPHANDLER_H | ||
#define QGSLAYOUTQPTDROPHANDLER_H | ||
|
||
#include "qgslayoutcustomdrophandler.h" | ||
|
||
class QgsLayoutQptDropHandler : public QgsLayoutCustomDropHandler | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsLayoutQptDropHandler( QObject *parent = nullptr ); | ||
|
||
virtual bool handleFileDrop( QgsLayoutDesignerInterface *iface, const QString &file ); | ||
}; | ||
|
||
#endif // QGSLAYOUTQPTDROPHANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.