16
16
* *
17
17
***************************************************************************
18
18
"""
19
- import sys
20
19
21
20
__author__ = 'Victor Olaya'
22
21
__date__ = 'August 2012'
23
22
__copyright__ = '(C) 2012, Victor Olaya'
24
23
# This will get replaced with a git SHA1 when you do a git archive
25
24
__revision__ = '$Format:%H$'
26
25
26
+ import sys
27
+ import codecs
28
+ import pickle
29
+
27
30
from PyQt4 .QtCore import *
28
31
from PyQt4 .QtGui import *
29
32
30
- import codecs
31
- import pickle
33
+ from processing . core . ProcessingConfig import ProcessingConfig
34
+ from processing . core . GeoAlgorithm import GeoAlgorithm
32
35
33
- from processing .tools .system import *
34
36
from processing .gui .HelpEditionDialog import HelpEditionDialog
35
37
from processing .gui .ParametersDialog import ParametersDialog
36
- from processing .core .ProcessingConfig import ProcessingConfig
37
- from processing .core .GeoAlgorithm import GeoAlgorithm
38
38
from processing .gui .AlgorithmClassification import AlgorithmDecorator
39
+
39
40
from processing .modeler .ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
40
41
from processing .modeler .ModelerAlgorithm import ModelerAlgorithm
41
42
from processing .modeler .ModelerParametersDialog import ModelerParametersDialog
42
43
from processing .modeler .ModelerUtils import ModelerUtils
43
44
from processing .modeler .WrongModelException import WrongModelException
44
45
from processing .modeler .ModelerScene import ModelerScene
45
46
from processing .modeler .Providers import Providers
47
+
48
+ from processing .tools .system import *
49
+
46
50
from processing .ui .ui_DlgModeler import Ui_DlgModeler
47
51
48
52
class ModelerDialog (QDialog , Ui_DlgModeler ):
@@ -76,9 +80,12 @@ def __init__(self, alg=None):
76
80
self .saveButton = QPushButton (self .tr ("Save" ))
77
81
self .saveButton .setToolTip (self .tr ("Save current model" ))
78
82
self .buttonBox .addButton (self .saveButton , QDialogButtonBox .ActionRole )
79
- self .saveAsButton = QPushButton (self .tr ("Save as ..." ))
83
+ self .saveAsButton = QPushButton (self .tr ("Save as..." ))
80
84
self .saveAsButton .setToolTip (self .tr ("Save current model as" ))
81
85
self .buttonBox .addButton (self .saveAsButton , QDialogButtonBox .ActionRole )
86
+ self .saveAsImageButton = QPushButton (self .tr ("Export as image..." ))
87
+ self .exportAsImageButton .setToolTip (self .tr ("Export current model to image" ))
88
+ self .buttonBox .addButton (self .saveAsImageButton , QDialogButtonBox .ActionRole )
82
89
83
90
# fill trees with inputs and algorithms
84
91
self .fillInputsTree ()
@@ -100,6 +107,7 @@ def __init__(self, alg=None):
100
107
self .openButton .clicked .connect (self .openModel )
101
108
self .saveButton .clicked .connect (self .save )
102
109
self .saveAsButton .clicked .connect (self .saveAs )
110
+ self .exportAsImageButton .clicked .connect (self .exportAsImage )
103
111
self .runButton .clicked .connect (self .runModel )
104
112
self .editHelpButton .clicked .connect (self .editHelp )
105
113
@@ -116,7 +124,6 @@ def __init__(self, alg=None):
116
124
self .help = None
117
125
self .update = False #indicates whether to update or not the toolbox after closing this dialog
118
126
119
-
120
127
def editHelp (self ):
121
128
dlg = HelpEditionDialog (self .alg )
122
129
dlg .exec_ ()
@@ -159,6 +166,33 @@ def save(self):
159
166
def saveAs (self ):
160
167
self .saveModel (True )
161
168
169
+ def exportAsImage (self ):
170
+ filename = unicode (QFileDialog .getSaveFileName (self ,
171
+ self .tr ("Save Model As Image" ),
172
+ "" ,
173
+ self .tr ("PNG files (*.png *.PNG)" )
174
+ ))
175
+ if not filename :
176
+ return
177
+
178
+ if not filename .lower ().endswith (".png" ):
179
+ filename += ".png"
180
+
181
+ totalRect = QRectF (0 , 0 , 1 , 1 )
182
+ for item in self .scene .items ():
183
+ totalRect = totalRect .united (item .sceneBoundingRect ())
184
+ totalRect .adjust (- 10 , - 10 , 10 , 10 )
185
+
186
+ img = QImage (totalRect .width (), totalRect .height (), QImage .Format_ARGB32_Premultiplied )
187
+ img .fill (Qt .white )
188
+ painter = QPainter ()
189
+ painter .setRenderHint (QPainter .Antialiasing )
190
+ painter .begin (img )
191
+ self .scene .render (painter , totalRect , totalRect )
192
+ painter .end ()
193
+
194
+ img .save (filename )
195
+
162
196
def saveModel (self , saveAs ):
163
197
if unicode (self .textGroup .text ()).strip () == "" or unicode (self .textName .text ()).strip () == "" :
164
198
QMessageBox .warning (self ,
@@ -427,4 +461,3 @@ def __init__(self, alg):
427
461
self .setIcon (0 , icon )
428
462
self .setToolTip (0 , name )
429
463
self .setText (0 , name )
430
-
0 commit comments