Skip to content

Commit 4c2447f

Browse files
committedJul 11, 2017
Add shell for QgsLayoutView
1 parent 67c6e8f commit 4c2447f

File tree

6 files changed

+276
-0
lines changed

6 files changed

+276
-0
lines changed
 

‎python/gui/gui_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
%Include layertree/qgslayertreeview.sip
276276
%Include layertree/qgslayertreeviewdefaultactions.sip
277277
%Include layout/qgslayoutdesignerinterface.sip
278+
%Include layout/qgslayoutview.sip
278279
%Include locator/qgslocator.sip
279280
%Include locator/qgslocatorfilter.sip
280281
%Include locator/qgslocatorwidget.sip

‎python/gui/layout/qgslayoutview.sip

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/layout/qgslayoutview.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLayoutView: QGraphicsView
13+
{
14+
%Docstring
15+
A graphical widget to display and interact with QgsLayouts.
16+
17+
QgsLayoutView manages the layout interaction tools and mouse/key events.
18+
19+
.. versionadded:: 3.0
20+
%End
21+
22+
%TypeHeaderCode
23+
#include "qgslayoutview.h"
24+
%End
25+
public:
26+
27+
enum Tool
28+
{
29+
ToolSelect,
30+
ToolAddItem,
31+
};
32+
33+
QgsLayoutView( QWidget *parent /TransferThis/ = 0 );
34+
%Docstring
35+
Constructor for QgsLayoutView.
36+
%End
37+
38+
QgsLayout *currentLayout();
39+
%Docstring
40+
Returns the current layout associated with the view.
41+
.. seealso:: setCurrentLayout()
42+
.. seealso:: layoutSet()
43+
:rtype: QgsLayout
44+
%End
45+
46+
void setCurrentLayout( QgsLayout *layout /KeepReference/ );
47+
%Docstring
48+
Sets the current ``layout`` to edit in the view.
49+
.. seealso:: currentLayout()
50+
.. seealso:: layoutSet()
51+
%End
52+
53+
signals:
54+
55+
void layoutSet( QgsLayout *layout );
56+
%Docstring
57+
Emitted when a ``layout`` is set for the view.
58+
.. seealso:: currentLayout()
59+
.. seealso:: setCurrentLayout()
60+
%End
61+
62+
protected:
63+
virtual void mousePressEvent( QMouseEvent *event );
64+
65+
virtual void mouseReleaseEvent( QMouseEvent *event );
66+
67+
virtual void mouseMoveEvent( QMouseEvent *event );
68+
69+
virtual void mouseDoubleClickEvent( QMouseEvent *event );
70+
71+
72+
};
73+
74+
/************************************************************************
75+
* This file has been generated automatically from *
76+
* *
77+
* src/gui/layout/qgslayoutview.h *
78+
* *
79+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
80+
************************************************************************/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import glob
2+
3+
import re
4+
5+
#regex = re.compile(r"( *)def defineCharacteristics(self):\n(\s*)self.name, self.i18n_name = self.trAlgorithm\('(.*)'\)\n(\s*)self.group, self.i18n_group = self.trAlgorithm\('(.*)'\)", re.MULTILINE)
6+
7+
regex = re.compile(r"^(.*)(\s*def name)", re.M | re.DOTALL)
8+
regex2 = re.compile(r"", re.M | re.DOTALL)
9+
regex = re.compile(r"^(.*?)(\s*def name.*)def defineCharacteristics\(self\):\s*\n(.*?)(\s*def .*)$", re.M | re.DOTALL)
10+
#regex = re.compile(r"(\s*)def defineCharacteristics(self):", re.MULTILINE)
11+
12+
for filename in glob.iglob('./**/*.py', recursive=True):
13+
out = None
14+
with open(filename, 'r') as myfile:
15+
data = myfile.read()
16+
17+
r = regex.search(data)
18+
if r:
19+
20+
out = r.groups()[0]
21+
out += '\n\n def __init__(self):\n super().__init__()\n'
22+
out += r.groups()[2]
23+
out += r.groups()[1]
24+
out += r.groups()[3]
25+
print(out)
26+
27+
#r2=regex2.search(data)
28+
#if r2:
29+
# print(r2.groups()[1])
30+
# print('-0-----')
31+
# print(r2.groups()[2])
32+
33+
#d=regex.sub(r"\1def name(self):\n\2return '\3'\n\n\1def group(self):\n\2return '\5'\n\n\1def defineCharacteristics(self):",data)
34+
#d=regex.sub(r"\1def defineCharacteristics(self)",data)
35+
36+
if out:
37+
with open(filename, 'w') as myfile:
38+
myfile.write(out)
39+
40+
if False:
41+
d = r.group() # print(r.groups())
42+
#print(d)
43+
d = regex.sub(r"\1def name(self):\n\2return '\3'\n\n\1def group(self):\n\2return '\5'\n", d)
44+
print(d)
45+
46+
# def group(self):
47+
# return '[GDAL] Analysis' d)

‎src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ SET(QGIS_GUI_SRCS
158158
layertree/qgslayertreeview.cpp
159159
layertree/qgslayertreeviewdefaultactions.cpp
160160

161+
layout/qgslayoutview.cpp
162+
161163
locator/qgslocator.cpp
162164
locator/qgslocatorfilter.cpp
163165
locator/qgslocatorwidget.cpp
@@ -620,6 +622,7 @@ SET(QGIS_GUI_MOC_HDRS
620622
layertree/qgslayertreeviewdefaultactions.h
621623

622624
layout/qgslayoutdesignerinterface.h
625+
layout/qgslayoutview.h
623626

624627
locator/qgslocator.h
625628
locator/qgslocatorfilter.h

‎src/gui/layout/qgslayoutview.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/***************************************************************************
2+
qgslayoutview.cpp
3+
-----------------
4+
Date : July 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgslayoutview.h"
19+
#include "qgslayout.h"
20+
21+
QgsLayoutView::QgsLayoutView( QWidget *parent )
22+
: QGraphicsView( parent )
23+
{
24+
25+
}
26+
27+
QgsLayout *QgsLayoutView::currentLayout()
28+
{
29+
return qobject_cast<QgsLayout *>( scene() );
30+
}
31+
32+
void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
33+
{
34+
setScene( layout );
35+
36+
//emit layoutSet, so that designer dialogs can update for the new layout
37+
emit layoutSet( layout );
38+
}
39+
40+
void QgsLayoutView::mousePressEvent( QMouseEvent *event )
41+
{
42+
QGraphicsView::mousePressEvent( event );
43+
}
44+
45+
void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
46+
{
47+
QGraphicsView::mouseReleaseEvent( event );
48+
}
49+
50+
void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
51+
{
52+
QGraphicsView::mouseMoveEvent( event );
53+
}
54+
55+
void QgsLayoutView::mouseDoubleClickEvent( QMouseEvent *event )
56+
{
57+
QGraphicsView::mouseDoubleClickEvent( event );
58+
}

‎src/gui/layout/qgslayoutview.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/***************************************************************************
2+
qgslayoutview.h
3+
---------------
4+
Date : July 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
#ifndef QGSLAYOUTVIEW_H
18+
#define QGSLAYOUTVIEW_H
19+
20+
#include <QGraphicsView>
21+
#include "qgis.h"
22+
#include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
23+
#include "qgis_gui.h"
24+
25+
class QgsLayout;
26+
27+
/**
28+
* \ingroup gui
29+
* A graphical widget to display and interact with QgsLayouts.
30+
*
31+
* QgsLayoutView manages the layout interaction tools and mouse/key events.
32+
*
33+
* \since QGIS 3.0
34+
*/
35+
class GUI_EXPORT QgsLayoutView: public QGraphicsView
36+
{
37+
38+
Q_OBJECT
39+
40+
Q_PROPERTY( QgsLayout *currentLayout READ currentLayout WRITE setCurrentLayout NOTIFY layoutSet )
41+
42+
public:
43+
44+
//! Current view tool
45+
enum Tool
46+
{
47+
ToolSelect = 0, //!< Select/move/resize item tool
48+
ToolAddItem, //!< Add new item tool
49+
};
50+
51+
/**
52+
* Constructor for QgsLayoutView.
53+
*/
54+
QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );
55+
56+
/**
57+
* Returns the current layout associated with the view.
58+
* \see setCurrentLayout()
59+
* \see layoutSet()
60+
*/
61+
QgsLayout *currentLayout();
62+
63+
/**
64+
* Sets the current \a layout to edit in the view.
65+
* \see currentLayout()
66+
* \see layoutSet()
67+
*/
68+
void setCurrentLayout( QgsLayout *layout SIP_KEEPREFERENCE );
69+
70+
signals:
71+
72+
/**
73+
* Emitted when a \a layout is set for the view.
74+
* \see currentLayout()
75+
* \see setCurrentLayout()
76+
*/
77+
void layoutSet( QgsLayout *layout );
78+
79+
protected:
80+
void mousePressEvent( QMouseEvent *event ) override;
81+
void mouseReleaseEvent( QMouseEvent *event ) override;
82+
void mouseMoveEvent( QMouseEvent *event ) override;
83+
void mouseDoubleClickEvent( QMouseEvent *event ) override;
84+
85+
};
86+
87+
#endif // QGSLAYOUTVIEW_H

0 commit comments

Comments
 (0)
Please sign in to comment.