Skip to content

Commit 2095872

Browse files
committed
Moved copyright label plugin to app
1 parent 92e57da commit 2095872

18 files changed

+261
-660
lines changed

images/images.qrc

+1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@
350350
<file>north_arrows/default.png</file>
351351
<file>themes/default/locked.png</file>
352352
<file>themes/default/unlocked.png</file>
353+
<file>themes/default/plugins/copyright_label.png</file>
353354
</qresource>
354355
<qresource prefix="/images/tips">
355356
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>

src/app/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ SET(QGIS_APP_SRCS
2121
qgscustomprojectiondialog.cpp
2222
qgsdbfilterproxymodel.cpp
2323
qgsdbtablemodel.cpp
24+
qgsdecorationcopyright.cpp
25+
qgsdecorationcopyrightdialog.cpp
2426
qgsembedlayerdialog.cpp
2527
qgsformannotationdialog.cpp
2628
qgsdelattrdialog.cpp
@@ -153,6 +155,8 @@ SET (QGIS_APP_MOC_HDRS
153155
qgscustomization.h
154156
qgscustomprojectiondialog.h
155157
qgsdbtablemodel.h
158+
qgsdecorationcopyright.h
159+
qgsdecorationcopyrightdialog.h
156160
qgsdelattrdialog.h
157161
qgsdisplayangle.h
158162
qgsembedlayerdialog.h

src/app/qgisapp.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include "qgscustomization.h"
115115
#include "qgscustomprojectiondialog.h"
116116
#include "qgsdatasourceuri.h"
117+
#include "qgsdecorationcopyright.h"
117118
#include "qgsembedlayerdialog.h"
118119
#include "qgsencodingfiledialog.h"
119120
#include "qgsexception.h"
@@ -437,6 +438,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
437438
initLegend();
438439
createOverview();
439440
createMapTips();
441+
createDecorations();
440442
readSettings();
441443
updateRecentProjectPaths();
442444
activateDeactivateLayerRelatedActions( NULL );
@@ -1470,6 +1472,7 @@ void QgisApp::setTheme( QString theThemeName )
14701472
mActionMoveLabel->setIcon( getThemeIcon( "/mActionMoveLabel.png" ) );
14711473
mActionRotateLabel->setIcon( getThemeIcon( "/mActionRotateLabel.png" ) );
14721474
mActionChangeLabelProperties->setIcon( getThemeIcon( "/mActionChangeLabelProperties.png" ) );
1475+
mActionDecorationCopyright->setIcon( getThemeIcon( "/plugins/copyright_label.png" ) );
14731476

14741477
//change themes of all composers
14751478
QSet<QgsComposer*>::iterator composerIt = mPrintComposers.begin();
@@ -1803,6 +1806,14 @@ void QgisApp::createMapTips()
18031806
mpMaptip = new QgsMapTip();
18041807
}
18051808

1809+
void QgisApp::createDecorations()
1810+
{
1811+
mDecorationCopyright = new QgsDecorationCopyright(this);
1812+
connect( mActionDecorationCopyright, SIGNAL( triggered() ), mDecorationCopyright, SLOT( run() ) );
1813+
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), mDecorationCopyright, SLOT( renderLabel( QPainter * ) ) );
1814+
connect( this, SIGNAL( projectRead() ), mDecorationCopyright, SLOT( projectRead() ) );
1815+
}
1816+
18061817
// Update file menu with the current list of recently accessed projects
18071818
void QgisApp::updateRecentProjectPaths()
18081819
{

src/app/qgisapp.h

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class QgsBrowserDockWidget;
6969
class QgsSnappingDialog;
7070
class QgsGPSInformationWidget;
7171

72+
class QgsDecorationCopyright;
73+
7274
#include <QMainWindow>
7375
#include <QToolBar>
7476
#include <QAbstractSocket>
@@ -864,6 +866,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
864866
bool createDB();
865867
void createMapTips();
866868
void updateCRSStatusBar();
869+
void createDecorations();
867870

868871
// actions for menus and toolbars -----------------
869872

@@ -1051,6 +1054,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
10511054
//! Persistent tile scale slider
10521055
QgsTileScaleWidget * mpTileScaleWidget;
10531056

1057+
QgsDecorationCopyright* mDecorationCopyright;
1058+
10541059
int mLastComposerId;
10551060

10561061
#ifdef Q_OS_WIN

src/app/qgsdecorationcopyright.cpp

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/***************************************************************************
2+
plugin.cpp
3+
Import tool for various worldmap analysis output files
4+
Functions:
5+
6+
-------------------
7+
begin : Jan 21, 2004
8+
copyright : (C) 2004 by Tim Sutton
9+
email : tim@linfiniti.com
10+
11+
***************************************************************************/
12+
13+
/***************************************************************************
14+
* *
15+
* This program is free software; you can redistribute it and/or modify *
16+
* it under the terms of the GNU General Public License as published by *
17+
* the Free Software Foundation; either version 2 of the License, or *
18+
* (at your option) any later version. *
19+
* *
20+
***************************************************************************/
21+
22+
// includes
23+
24+
#include "qgsdecorationcopyright.h"
25+
#include "qgsdecorationcopyrightdialog.h"
26+
27+
#include "qgsapplication.h"
28+
#include "qgslogger.h"
29+
#include "qgsmapcanvas.h"
30+
#include "qgsproject.h"
31+
#include "qgisapp.h"
32+
33+
#include <QPainter>
34+
#include <QMenu>
35+
#include <QDate>
36+
#include <QTextDocument>
37+
#include <QMatrix>
38+
#include <QFile>
39+
40+
//non qt includes
41+
#include <cmath>
42+
43+
44+
QgsDecorationCopyright::QgsDecorationCopyright( QObject* parent )
45+
: QObject(parent)
46+
{
47+
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
48+
<< tr( "Top Right" ) << tr( "Bottom Right" );
49+
50+
// initialise default values in the gui
51+
projectRead();
52+
}
53+
54+
QgsDecorationCopyright::~QgsDecorationCopyright()
55+
{}
56+
57+
void QgsDecorationCopyright::projectRead()
58+
{
59+
QDate now;
60+
QString defString;
61+
62+
now = QDate::currentDate();
63+
defString = "&copy; QGIS " + now.toString( "yyyy" );
64+
65+
// there is no font setting in the UI, so just use the Qt/QGIS default font (what mQFont gets when created)
66+
// mQFont.setFamily( QgsProject::instance()->readEntry( "CopyrightLabel", "/FontName", "Sans Serif" ) );
67+
// mQFont.setPointSize( QgsProject::instance()->readNumEntry( "CopyrightLabel", "/FontSize", 9 ) );
68+
QgsProject* prj = QgsProject::instance();
69+
mLabelQString = prj->readEntry( "CopyrightLabel", "/Label", defString );
70+
mPlacementIndex = prj->readNumEntry( "CopyrightLabel", "/Placement", 3 );
71+
mEnable = prj->readBoolEntry( "CopyrightLabel", "/Enabled", true );
72+
mLabelQColor.setNamedColor( prj->readEntry( "CopyrightLabel", "/Color", "#000000" ) ); // default color is black
73+
}
74+
75+
// Slot called when the buffer menu item is activated
76+
void QgsDecorationCopyright::run()
77+
{
78+
QgsDecorationCopyrightDialog dlg( *this, QgisApp::instance() );
79+
80+
if (dlg.exec())
81+
{
82+
saveToProject();
83+
QgisApp::instance()->mapCanvas()->refresh();
84+
}
85+
}
86+
87+
88+
void QgsDecorationCopyright::renderLabel( QPainter * theQPainter )
89+
{
90+
//Large IF statement to enable/disable copyright label
91+
if ( mEnable )
92+
{
93+
// need width/height of paint device
94+
int myHeight = theQPainter->device()->height();
95+
int myWidth = theQPainter->device()->width();
96+
97+
QTextDocument text;
98+
text.setDefaultFont( mQFont );
99+
// To set the text color in a QTextDocument we use a CSS style
100+
QString style = "<style type=\"text/css\"> p {color: " +
101+
mLabelQColor.name() + "}</style>";
102+
text.setHtml( style + "<p>" + mLabelQString + "</p>" );
103+
QSizeF size = text.size();
104+
105+
float myXOffset( 0 ), myYOffset( 0 );
106+
//Determine placement of label from form combo box
107+
switch ( mPlacementIndex )
108+
{
109+
case 0: // Bottom Left
110+
//Define bottom left hand corner start point
111+
myYOffset = myHeight - ( size.height() + 5 );
112+
myXOffset = 5;
113+
break;
114+
case 1: // Top left
115+
//Define top left hand corner start point
116+
myYOffset = 0;;
117+
myXOffset = 5;
118+
break;
119+
case 2: // Top Right
120+
//Define top right hand corner start point
121+
myYOffset = 0;
122+
myXOffset = myWidth - ( size.width() + 5 );
123+
break;
124+
case 3: // Bottom Right
125+
//Define bottom right hand corner start point
126+
myYOffset = myHeight - ( size.height() + 5 );
127+
myXOffset = myWidth - ( size.width() + 5 );
128+
break;
129+
default:
130+
QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( mPlacementIndex ) );
131+
}
132+
133+
//Paint label to canvas
134+
QMatrix worldMatrix = theQPainter->worldMatrix();
135+
theQPainter->translate( myXOffset, myYOffset );
136+
text.drawContents( theQPainter );
137+
// Put things back how they were
138+
theQPainter->setWorldMatrix( worldMatrix );
139+
}
140+
}
141+
142+
void QgsDecorationCopyright::saveToProject()
143+
{
144+
//save state to the project file.....
145+
QgsProject* prj = QgsProject::instance();
146+
prj->writeEntry( "CopyrightLabel", "/FontName", mQFont.family() );
147+
prj->writeEntry( "CopyrightLabel", "/FontSize", mQFont.pointSize() );
148+
prj->writeEntry( "CopyrightLabel", "/Label", mLabelQString );
149+
prj->writeEntry( "CopyrightLabel", "/Color", mLabelQColor.name() );
150+
prj->writeEntry( "CopyrightLabel", "/Placement", mPlacementIndex );
151+
prj->writeEntry( "CopyrightLabel", "/Enabled", mEnable );
152+
}

src/plugins/copyright_label/plugin.h renamed to src/app/qgsdecorationcopyright.h

+15-45
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,35 @@
1818
***************************************************************************/
1919
#ifndef QGSCOPYRIGHTLABELPLUGIN
2020
#define QGSCOPYRIGHTLABELPLUGIN
21-
#include "../qgisplugin.h"
2221

2322
#include <QColor>
2423
#include <QFont>
2524
#include <QObject>
2625
class QAction;
2726
class QPainter;
2827

29-
class QgisInterface;
28+
class QgsDecorationCopyrightDialog;
3029

31-
/**
32-
* \class Plugin
33-
* \brief OpenModeller plugin for QGIS
34-
*
35-
*/
36-
class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
30+
class QgsDecorationCopyright : public QObject
3731
{
38-
Q_OBJECT public:
39-
/**
40-
* Constructor for a plugin. The QgisInterface pointer is passed by
41-
* QGIS when it attempts to instantiate the plugin.
42-
* @param qI Pointer to the QgisInterface object.
43-
*/
44-
QgsCopyrightLabelPlugin( QgisInterface * );
32+
Q_OBJECT
33+
public:
34+
35+
//! Constructor
36+
QgsDecorationCopyright( QObject* parent = NULL );
4537
//! Destructor
46-
virtual ~ QgsCopyrightLabelPlugin();
47-
void writeEntry( QString theScope, QString theProperty, QVariant theValue );
38+
virtual ~QgsDecorationCopyright();
39+
4840
public slots:
49-
//! init the gui
50-
void initGui();
51-
//!set values on the gui when a project is read or the gui first loaded
41+
//! set values on the gui when a project is read or the gui first loaded
5242
void projectRead();
43+
//! save values to the project
44+
void saveToProject();
45+
5346
//! Show the dialog box
5447
void run();
48+
//! render the copyright label
5549
void renderLabel( QPainter * );
56-
//! Refresh the map display using the mapcanvas exported via the plugin interface
57-
void refreshCanvas();
58-
//! unload the plugin
59-
void unload();
60-
//! show the help document
61-
void help();
62-
//! change the copyright font
63-
void setFont( QFont );
64-
//! change the copyright text
65-
void setLabel( QString );
66-
//! change the copyright font color
67-
void setColor( QColor );
68-
//! set copyright label placement
69-
void setPlacement( int );
70-
//! set copyright label enabled
71-
void setEnable( bool );
72-
//! update the plugins theme when the app tells us its theme is changed
73-
void setCurrentTheme( QString theThemeName );
74-
75-
7650

7751
private:
7852
//! This is the font that will be used for the copyright label
@@ -87,11 +61,7 @@ class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
8761
//! Copyright label enabled
8862
bool mEnable;
8963

90-
int pluginType;
91-
//! Pointer to the QGIS interface object
92-
QgisInterface *qGisInterface;
93-
//! Pointer to the QAction object used in the menu and toolbar
94-
QAction *myQActionPointer;
64+
friend class QgsDecorationCopyrightDialog;
9565
};
9666

9767
#endif

0 commit comments

Comments
 (0)