Skip to content

Commit 17c037a

Browse files
author
timlinux
committedJan 14, 2008
Improvements and Fixes for quickprint
- moved actual pringing logic into gui lib so that third party apps can make use of it. - fixes for legend font size rendering issues git-svn-id: http://svn.osgeo.org/qgis/trunk@7959 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0b5d71c commit 17c037a

File tree

8 files changed

+1256
-1061
lines changed

8 files changed

+1256
-1061
lines changed
 

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ qgsmaptoolpan.cpp
1818
qgsmaptoolzoom.cpp
1919
qgsmessageviewer.cpp
2020
qgsprojectionselector.cpp
21+
qgsquickprint.cpp
2122
qgsrubberband.cpp
2223
qgsvertexmarker.cpp
2324
)
@@ -31,6 +32,7 @@ qgsmapoverviewcanvas.h
3132
qgsmessageviewer.h
3233
qgsmaptoolemitpoint.h
3334
qgsprojectionselector.h
35+
qgsquickprint.h
3436
)
3537

3638
QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})

‎src/gui/qgsquickprint.cpp

Lines changed: 1104 additions & 0 deletions
Large diffs are not rendered by default.

‎src/gui/qgsquickprint.h

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***************************************************************************
2+
quickprint.h
3+
-------------------
4+
begin : Jan 21, 2004
5+
copyright : (C) 2004 by Tim Sutton
6+
email : tim@linfiniti.com
7+
8+
***************************************************************************/
9+
10+
/***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************/
18+
/* $Id: plugin.h 7796 2007-12-16 22:11:38Z homann $ */
19+
#ifndef QGSQUICKPRINT_H
20+
#define QGSQUICKPRINT_H
21+
22+
//QT4 includes
23+
#include <QObject>
24+
25+
//QGIS includes
26+
#include <qgsmaprender.h>
27+
#include <qgsmapcanvas.h>
28+
29+
30+
/**
31+
* \class QgsQgsQuickPrint
32+
* \brief A convenience class for quickly printing a map.
33+
* Prints a map with a map title, scale bar, north arrow, legend etc.
34+
*/
35+
class QgsQuickPrint:public QObject
36+
{
37+
Q_OBJECT;
38+
public:
39+
40+
QgsQuickPrint();
41+
//! Destructor
42+
virtual ~QgsQuickPrint();
43+
enum SymbolScalingType {ScaleUp, ScaleDown};
44+
45+
public slots:
46+
void print();
47+
void setTitle(QString theText);
48+
void setName(QString theText);
49+
void setCopyright(QString theText);
50+
void setNorthArrow(QString theFileName);
51+
void setLogo1(QString theFileName);
52+
void setLogo2(QString theFileName);
53+
void setOutputPdf(QString theFileName);
54+
void setMapCanvas(QgsMapCanvas * thepMapCanvas);
55+
private:
56+
void renderPrintScaleBar(QPainter * thepPainter, QgsMapCanvas * thepMapCanvas);
57+
/**
58+
* Scale symbols in all layers by the specified amount.
59+
* Typically used for printing. Each symbol in
60+
* each layer of the active mapcanvas will be iterated
61+
* to. If the symbol is a point symbol its size
62+
* will be multiplied by the scale factor or divided. In order
63+
* to choose an appropriate scale factor, typically
64+
* you should divide the print resolution by the
65+
* screen resolution (often 72dpi or 96dpi).
66+
* @param theScaleFactor - amount by which symbol sizes
67+
* will be multiplied.
68+
* @param SymbolScalingType - whether the sizes should
69+
* be scaled up or down.
70+
* @see scaleTextLabels
71+
*/
72+
void scalePointSymbols( int theScaleFactor, SymbolScalingType theDirection );
73+
/**
74+
* Scale text labels in all layers by the specified amount.
75+
* Typically used for printing. Each label in
76+
* each layer of the active mapcanvas will be iterated
77+
* to. The font point size
78+
* will be multiplied by the scale factor or divided. In order
79+
* to choose an appropriate scale factor, typically
80+
* you should divide the print resolution by the
81+
* screen resolution (often 72dpi or 96dpi).
82+
* @param theScaleFactor - amount by which symbol sizes
83+
* will be multiplied.
84+
* @param SymbolScalingType - whether the sizes should
85+
* be scaled up or down.
86+
* @see scalePointSymbols
87+
*/
88+
void scaleTextLabels( int theScaleFactor, SymbolScalingType theDirection);
89+
90+
QgsMapCanvas * mpMapCanvas;
91+
QString mTitleText;
92+
QString mNameText;
93+
QString mCopyrightText;
94+
QString mNorthArrowFile;
95+
QString mLogo1File;
96+
QString mLogo2File;
97+
QString mOutputFileName;
98+
};
99+
100+
#endif //QGSQUICKPRINT_H

‎src/plugins/quick_print/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Files
44

55
SET (quickprint_SRCS
6-
quickprint.cpp
6+
quickprintplugin.cpp
77
quickprintgui.cpp
88
)
99

1010
SET (quickprint_UIS quickprintguibase.ui)
1111

1212
SET (quickprint_MOC_HDRS
13-
quickprint.h
13+
quickprintplugin.h
1414
quickprintgui.h
1515
)
1616

@@ -25,7 +25,11 @@ QT4_WRAP_CPP (quickprint_MOC_SRCS ${quickprint_MOC_HDRS})
2525

2626
QT4_ADD_RESOURCES(quickprint_RCC_SRCS ${quickprint_RCCS})
2727

28-
ADD_LIBRARY (quickprintplugin MODULE ${quickprint_SRCS} ${quickprint_MOC_SRCS} ${quickprint_RCC_SRCS} ${quickprint_UIS_H})
28+
ADD_LIBRARY (quickprintplugin MODULE
29+
${quickprint_SRCS}
30+
${quickprint_MOC_SRCS}
31+
${quickprint_RCC_SRCS}
32+
${quickprint_UIS_H})
2933

3034
INCLUDE_DIRECTORIES(
3135
${CMAKE_CURRENT_BINARY_DIR}

‎src/plugins/quick_print/quickprintgui.cpp

Lines changed: 16 additions & 1000 deletions
Large diffs are not rendered by default.

‎src/plugins/quick_print/quickprintgui.h

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#define QuickPrintGUI_H
1919

2020
#include <QDialog>
21-
#include <qgsmaprender.h>
22-
#include <qgsmapcanvas.h>
2321
#include <ui_quickprintguibase.h>
22+
#include "qgsmapcanvas.h"
23+
2424

2525
/**
2626
@author Tim Sutton
@@ -29,47 +29,10 @@ class QuickPrintGui : public QDialog, private Ui::QuickPrintGuiBase
2929
{
3030
Q_OBJECT
3131
public:
32-
QuickPrintGui( QWidget* parent = 0, Qt::WFlags fl = 0 );
32+
QuickPrintGui( QgsMapCanvas * thepMapCanvas, QWidget* parent = 0, Qt::WFlags fl = 0 );
3333
~QuickPrintGui();
34-
void setMapCanvas(QgsMapCanvas * thepCanvas) {mpMapCanvas = thepCanvas;};;
3534
private:
3635
static const int context_id = 0;
37-
38-
enum SymbolScalingType {ScaleUp, ScaleDown};
39-
/**
40-
* Scale symbols in all layers by the specified amount.
41-
* Typically used for printing. Each symbol in
42-
* each layer of the active mapcanvas will be iterated
43-
* to. If the symbol is a point symbol its size
44-
* will be multiplied by the scale factor or divided. In order
45-
* to choose an appropriate scale factor, typically
46-
* you should divide the print resolution by the
47-
* screen resolution (often 72dpi or 96dpi).
48-
* @param theScaleFactor - amount by which symbol sizes
49-
* will be multiplied.
50-
* @param SymbolScalingType - whether the sizes should
51-
* be scaled up or down.
52-
* @see scaleTextLabels
53-
*/
54-
void scalePointSymbols( int theScaleFactor, SymbolScalingType theDirection );
55-
/**
56-
* Scale text labels in all layers by the specified amount.
57-
* Typically used for printing. Each label in
58-
* each layer of the active mapcanvas will be iterated
59-
* to. The font point size
60-
* will be multiplied by the scale factor or divided. In order
61-
* to choose an appropriate scale factor, typically
62-
* you should divide the print resolution by the
63-
* screen resolution (often 72dpi or 96dpi).
64-
* @param theScaleFactor - amount by which symbol sizes
65-
* will be multiplied.
66-
* @param SymbolScalingType - whether the sizes should
67-
* be scaled up or down.
68-
* @see scalePointSymbols
69-
*/
70-
void scaleTextLabels( int theScaleFactor, SymbolScalingType theDirection);
71-
72-
void renderPrintScaleBar(QPainter * thepPainter, QgsMapCanvas * thepMapCanvas);
7336
void readSettings();
7437
void writeSettings();
7538
QgsMapCanvas * mpMapCanvas;

‎src/plugins/quick_print/quickprint.cpp renamed to ‎src/plugins/quick_print/quickprintplugin.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
#include <qgisinterface.h>
2424
#include <qgisgui.h>
25-
26-
#include "quickprint.h"
25+
#include "quickprintplugin.h"
2726
#include "quickprintgui.h"
27+
#include <qgsapplication.h>
2828

2929
//
3030
// Qt4 Related Includes
@@ -52,13 +52,14 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
5252
* an interface object that provides access to exposed functions in QGIS.
5353
* @param theQGisInterface - Pointer to the QGIS interface object
5454
*/
55-
QuickPrint::QuickPrint(QgisInterface * theQgisInterface):
55+
QuickPrintPlugin::QuickPrintPlugin(QgisInterface * theQgisInterface):
5656
QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
5757
mQGisIface(theQgisInterface)
5858
{
59+
mpMapCanvas = mQGisIface->getMapCanvas();
5960
}
6061

61-
QuickPrint::~QuickPrint()
62+
QuickPrintPlugin::~QuickPrintPlugin()
6263
{
6364

6465
}
@@ -67,7 +68,7 @@ QuickPrint::~QuickPrint()
6768
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
6869
* added to the plugin registry in the QGIS application.
6970
*/
70-
void QuickPrint::initGui()
71+
void QuickPrintPlugin::initGui()
7172
{
7273

7374
// Create the action for tool
@@ -82,7 +83,7 @@ void QuickPrint::initGui()
8283

8384
}
8485
//method defined in interface
85-
void QuickPrint::help()
86+
void QuickPrintPlugin::help()
8687
{
8788
//implement me!
8889
}
@@ -91,17 +92,19 @@ void QuickPrint::help()
9192
// If you created more menu items / toolbar buttons in initiGui, you should
9293
// create a separate handler for each action - this single run() method will
9394
// not be enough
94-
void QuickPrint::run()
95+
void QuickPrintPlugin::run()
9596
{
96-
QuickPrintGui *myPluginGui=new QuickPrintGui(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);
97-
myPluginGui->setAttribute(Qt::WA_DeleteOnClose);
97+
QuickPrintGui *mypPluginGui=new QuickPrintGui(
98+
mpMapCanvas,
99+
mQGisIface->getMainWindow(),
100+
QgisGui::ModalDialogFlags);
101+
mypPluginGui->setAttribute(Qt::WA_DeleteOnClose);
102+
mypPluginGui->exec(); //gui will decide when to call print
98103

99-
myPluginGui->setMapCanvas(mQGisIface->getMapCanvas());
100-
myPluginGui->show();
101104
}
102105

103106
// Unload the plugin by cleaning up the GUI
104-
void QuickPrint::unload()
107+
void QuickPrintPlugin::unload()
105108
{
106109
// remove the GUI
107110
mQGisIface->removePluginMenu("&Quick Print",mQActionPointer);
@@ -129,7 +132,7 @@ void QuickPrint::unload()
129132
// Class factory to return a new instance of the plugin class
130133
QGISEXTERN QgisPlugin * classFactory(QgisInterface * theQgisInterfacePointer)
131134
{
132-
return new QuickPrint(theQgisInterfacePointer);
135+
return new QuickPrintPlugin(theQgisInterfacePointer);
133136
}
134137
// Return the name of the plugin - note that we do not user class members as
135138
// the class may not yet be insantiated when this method is called.

‎src/plugins/quick_print/quickprint.h renamed to ‎src/plugins/quick_print/quickprintplugin.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
#include <QObject>
4141

4242
//QGIS includes
43-
#include "../qgisplugin.h"
43+
#include "qgisplugin.h"
44+
#include <qgsmaprender.h>
45+
#include <qgsmapcanvas.h>
4446

4547
//forward declarations
4648
class QAction;
@@ -53,7 +55,7 @@ class QgisInterface;
5355
* \brief [name] plugin for QGIS
5456
* [description]
5557
*/
56-
class QuickPrint:public QObject, public QgisPlugin
58+
class QuickPrintPlugin:public QObject, public QgisPlugin
5759
{
5860
Q_OBJECT;
5961
public:
@@ -69,9 +71,9 @@ class QuickPrint:public QObject, public QgisPlugin
6971
* QGIS when it attempts to instantiate the plugin.
7072
* @param theInterface Pointer to the QgisInterface object.
7173
*/
72-
QuickPrint(QgisInterface * theInterface);
74+
QuickPrintPlugin(QgisInterface * theInterface);
7375
//! Destructor
74-
virtual ~QuickPrint();
76+
virtual ~QuickPrintPlugin();
7577

7678
public slots:
7779
//! init the gui
@@ -82,9 +84,10 @@ public slots:
8284
void unload();
8385
//! show the help document
8486
void help();
85-
8687
private:
8788

89+
QgsMapCanvas * mpMapCanvas;
90+
8891
////////////////////////////////////////////////////////////////////
8992
//
9093
// MANDATORY PLUGIN PROPERTY DECLARATIONS .....

0 commit comments

Comments
 (0)
Please sign in to comment.