QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
layout
qgslayoutqptdrophandler.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgslayoutqptdrophandler.cpp
3
------------------------------
4
begin : December 2017
5
copyright : (C) 2017 by nyall Dawson
6
email : nyall dot dawson at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgslayoutqptdrophandler.h
"
17
18
#include "
qgslayout.h
"
19
#include "
qgslayoutdesignerinterface.h
"
20
#include "
qgslayoutview.h
"
21
#include "
qgsproject.h
"
22
#include "
qgsreadwritecontext.h
"
23
24
#include <QMessageBox>
25
#include <QString>
26
27
#include "moc_qgslayoutqptdrophandler.cpp"
28
29
using namespace
Qt::StringLiterals;
30
31
QgsLayoutQptDropHandler::QgsLayoutQptDropHandler
( QObject *parent )
32
:
QgsLayoutCustomDropHandler
( parent )
33
{}
34
35
bool
QgsLayoutQptDropHandler::handleFileDrop
(
QgsLayoutDesignerInterface
*iface, QPointF,
const
QString &file )
36
{
37
const
QFileInfo fi( file );
38
if
( fi.suffix().compare(
"qpt"
_L1, Qt::CaseInsensitive ) != 0 )
39
return
false
;
40
41
QFile templateFile( file );
42
if
( !templateFile.open( QIODevice::ReadOnly ) )
43
{
44
QMessageBox::warning( iface->
view
(), tr(
"Load from Template"
), tr(
"Could not read template file."
) );
45
return
true
;
46
}
47
48
QDomDocument templateDoc;
49
QgsReadWriteContext
context;
50
context.
setPathResolver
(
QgsProject::instance
()->pathResolver() );
51
if
( templateDoc.setContent( &templateFile ) )
52
{
53
bool
ok =
false
;
54
const
QList<QgsLayoutItem *> items = iface->
layout
()->
loadFromTemplate
( templateDoc, context,
false
, &ok );
55
if
( !ok )
56
{
57
QMessageBox::warning( iface->
view
(), tr(
"Load from Template"
), tr(
"Could not read template file."
) );
58
return
true
;
59
}
60
else
61
{
62
whileBlocking
( iface->
layout
() )->deselectAll();
63
iface->
selectItems
( items );
64
}
65
}
66
67
return
true
;
68
}
QgsLayoutCustomDropHandler::QgsLayoutCustomDropHandler
QgsLayoutCustomDropHandler(QObject *parent=nullptr)
Constructor for QgsLayoutCustomDropHandler.
Definition
qgslayoutcustomdrophandler.cpp:22
QgsLayoutDesignerInterface
A common interface for layout designer dialogs and widgets.
Definition
qgslayoutdesignerinterface.h:56
QgsLayoutDesignerInterface::view
virtual QgsLayoutView * view()=0
Returns the layout view utilized by the designer.
QgsLayoutDesignerInterface::selectItems
virtual void selectItems(const QList< QgsLayoutItem * > &items)=0
Selects the specified items.
QgsLayoutDesignerInterface::layout
virtual QgsLayout * layout()=0
Returns the current layout displayed in the designer.
QgsLayoutQptDropHandler::handleFileDrop
bool handleFileDrop(QgsLayoutDesignerInterface *iface, QPointF point, const QString &file) override
Called when the specified file has been dropped onto a QGIS layout.
Definition
qgslayoutqptdrophandler.cpp:35
QgsLayoutQptDropHandler::QgsLayoutQptDropHandler
QgsLayoutQptDropHandler(QObject *parent=nullptr)
constructor
Definition
qgslayoutqptdrophandler.cpp:31
QgsLayout::loadFromTemplate
QList< QgsLayoutItem * > loadFromTemplate(const QDomDocument &document, const QgsReadWriteContext &context, bool clearExisting=true, bool *ok=nullptr)
Load a layout template document.
Definition
qgslayout.cpp:647
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition
qgsproject.cpp:490
QgsReadWriteContext
A container for the context for various read/write operations on objects.
Definition
qgsreadwritecontext.h:38
QgsReadWriteContext::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Definition
qgsreadwritecontext.cpp:54
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition
qgis.h:7665
qgslayout.h
qgslayoutdesignerinterface.h
qgslayoutqptdrophandler.h
qgslayoutview.h
qgsproject.h
qgsreadwritecontext.h
Generated on
for QGIS API Documentation by
1.17.0