16
16
* (at your option) any later version. *
17
17
* *
18
18
***************************************************************************/
19
+ /* Adapted by Erik van de Pol, B3Partners BV. */
19
20
"""
20
21
# Import the PyQt and QGIS libraries
21
22
from PyQt4 .QtCore import *
22
23
from PyQt4 .QtGui import *
24
+ from xml .dom import minidom
23
25
from qgis .core import *
24
26
# Initialize Qt resources from file resources.py
25
- import resources_rc
27
+ import resources
26
28
# Import the code for the dialog
27
29
from mapserverexportdialog import MapServerExportDialog
28
30
# Import the ms_export script that does the real work
@@ -59,7 +61,7 @@ def initGui(self):
59
61
"MapServer Export" , self .iface .mainWindow ())
60
62
#self.action.setWhatsThis("Configuration for Zoom To Point plugin")
61
63
# connect the action to the run method
62
- QObject .connect (self .action , SIGNAL ("triggered ()" ), self .run )
64
+ QObject .connect (self .action , SIGNAL ("activated ()" ), self .run )
63
65
QObject .connect (self .iface , SIGNAL ("currentThemeChanged ( QString )" ), self .setCurrentTheme )
64
66
65
67
# Add toolbar button and menu item
@@ -74,17 +76,48 @@ def unload(self):
74
76
# run method that performs all the real work
75
77
def run (self ):
76
78
# create and show the MapServerExport dialog
77
- self .dlg = MapServerExportDialog ()
79
+ self .dlg = MapServerExportDialog ()
78
80
#dlg.setupUi(self)
81
+
82
+ project = QgsProject .instance ()
83
+ # question: save project on loading export dialog?
84
+ if project .isDirty ():
85
+ shouldSave = QMessageBox .question (None ,
86
+ "Save?" ,
87
+ "Save project to \" " + project .fileName () + "\" before exporting? Only the last saved version of your project will be exported." ,
88
+ QMessageBox .Yes ,
89
+ QMessageBox .No ,
90
+ QMessageBox .Cancel
91
+ )
92
+ if shouldSave == QMessageBox .Yes :
93
+ if project .fileName ().size () == 0 :
94
+ # project has not yet been saved:
95
+ saveAsFileName = QFileDialog .getSaveFileName (self .dlg ,
96
+ "Save QGIS Project file as..." ,
97
+ "." ,
98
+ "QGIS Project Files (*.qgs)" ,
99
+ "Filter list for selecting files from a dialog box" )
100
+ project .setFileName (saveAsFileName )
101
+ project .write ()
102
+ elif shouldSave == QMessageBox .Cancel :
103
+ return # do not show the export dialog
104
+
105
+ self .dlg .ui .txtQgisFilePath .setText (project .fileName ())
106
+ self .dlg .ui .txtMapName .setText (project .title ())
107
+
108
+ # TODO: fetch unit used from QSettings
109
+
110
+ # TODO: fetch width/height guess from QSettings:
79
111
# fetch the last used values from settings and intialize the
80
112
# dialog with them
81
113
#settings = QSettings("MicroResources", "ZoomToPoint")
82
114
#xValue = settings.value("coordinate/x")
83
- #dlg.ui.xCoord.setText(str(xValue.toString()))
115
+ #self. dlg.ui.xCoord.setText(str(xValue.toString()))
84
116
#yValue = settings.value("coordinate/y")
85
- #dlg.ui.yCoord.setText(str(yValue.toString()))
117
+ #self. dlg.ui.yCoord.setText(str(yValue.toString()))
86
118
#scale = settings.value("zoom/scale", QVariant(4))
87
- #dlg.ui.spinBoxScale.setValue(scale.toInt()[0])
119
+ #self.dlg.ui.spinBoxScale.setValue(scale.toInt()[0])
120
+
88
121
QObject .connect (self .dlg .ui .btnChooseFile , SIGNAL ("clicked()" ), self .setSaveFile )
89
122
QObject .connect (self .dlg .ui .btnChooseProjectFile , SIGNAL ("clicked()" ), self .setProjectFile )
90
123
QObject .connect (self .dlg .ui .chkExpLayersOnly , SIGNAL ("clicked(bool)" ), self .toggleLayersOnly )
@@ -100,15 +133,22 @@ def run(self):
100
133
print "Creating exporter using %s and %s" % (self .dlg .ui .txtQgisFilePath .text (), self .dlg .ui .txtMapFilePath .text ())
101
134
exporter = Qgis2Map (unicode (self .dlg .ui .txtQgisFilePath .text ()), unicode (self .dlg .ui .txtMapFilePath .text ()))
102
135
print "Setting options"
103
- exporter .setOptions (
136
+ exporter .setOptions (
137
+ unicode (self .dlg .ui .txtMapServerUrl .text ()),
104
138
unicode (self .dlg .ui .cmbMapUnits .itemData ( self .dlg .ui .cmbMapUnits .currentIndex () ).toString ()),
105
139
unicode (self .dlg .ui .cmbMapImageType .currentText ()),
106
140
unicode (self .dlg .ui .txtMapName .text ()),
107
141
unicode (self .dlg .ui .txtMapWidth .text ()),
108
142
unicode (self .dlg .ui .txtMapHeight .text ()),
109
143
unicode (self .dlg .ui .txtWebTemplate .text ()),
110
144
unicode (self .dlg .ui .txtWebFooter .text ()),
111
- unicode (self .dlg .ui .txtWebHeader .text ())
145
+ unicode (self .dlg .ui .txtWebHeader .text ()),
146
+ self .dlg .ui .checkBoxDump .isChecked (),
147
+ self .dlg .ui .checkBoxForce .isChecked (),
148
+ self .dlg .ui .checkBoxAntiAlias .isChecked (),
149
+ self .dlg .ui .checkBoxPartials .isChecked (),
150
+ unicode (self .dlg .ui .txtFontsetPath .text ()),
151
+ unicode (self .dlg .ui .txtSymbolsetPath .text ())
112
152
)
113
153
print "Calling writeMapFile"
114
154
result = exporter .writeMapFile ()
0 commit comments