Skip to content

Commit 1d45c56

Browse files
author
g_j_m
committedJan 4, 2006
Update north arrow plugin for qt4
Remove all qt3 widgets (except one) Tidy up #includes Implemented dialog box pretty pixutre using qt4 resources Implemented anti-aliasing on the rotated arrow image Misc. source code and comments tidy up git-svn-id: http://svn.osgeo.org/qgis/trunk@4466 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b97bb76 commit 1d45c56

File tree

6 files changed

+147
-157
lines changed

6 files changed

+147
-157
lines changed
 

‎plugins/north_arrow/Makefile.am

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ plugin_LTLIBRARIES = northarrowplugin.la
2323
ui_%.h: %.ui
2424
$(UIC) -o $@ $<
2525

26+
%.qrc.cpp: %.qrc
27+
$(RCC) -o $@ $<
28+
2629
northarrowplugin_la_SOURCES = plugin.cpp \
2730
plugin.h \
2831
plugingui.cpp \
2932
plugingui.h \
3033
$(plugin_UI)\
31-
$(plugin_MOC)
34+
$(plugin_MOC) \
35+
$(plugin_QRC) \
36+
$(plugin_RES)
3237

3338
plugin_MOC = plugin.moc.cpp \
3439
plugingui.moc.cpp
@@ -37,8 +42,12 @@ plugin_UI = ui_pluginguibase.h
3742

3843
plugin_UIC = pluginguibase.ui
3944

45+
plugin_RES = northarrow_plugin.qrc.cpp
46+
47+
plugin_QRC = northarrow_plugin.qrc
48+
4049

41-
BUILT_SOURCES = $(plugin_MOC) $(plugin_UI)
50+
BUILT_SOURCES = $(plugin_MOC) $(plugin_UI) $(plugin_RES)
4251

4352

4453
northarrowplugin_la_LIBADD = $(QT_LDADD) $(GDAL_LDADD) ../../src/libqgis.la

‎plugins/north_arrow/plugin.cpp

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,8 @@ email : tim@linfiniti.com
2828
#include "qgsproject.h"
2929
#include "qgsmapcanvas.h"
3030

31-
#include <q3toolbar.h>
32-
#include <qmenubar.h>
33-
#include <qmessagebox.h>
34-
#include <q3popupmenu.h>
35-
#include <qlineedit.h>
36-
#include <qaction.h>
37-
#include <qapplication.h>
38-
#include <qcursor.h>
39-
#include <qpixmap.h>
40-
#include <qpainter.h>
41-
#include <qfont.h>
42-
#include <q3picture.h>
43-
#include <q3pointarray.h>
44-
#include <q3paintdevicemetrics.h>
45-
#include <qglobal.h>
31+
// qt includes
32+
#include <QPainter>
4633

4734
//non qt includes
4835
#include <iostream>
@@ -106,11 +93,7 @@ void QgsNorthArrowPlugin::initGui()
10693
pluginMenu->setWhatsThis(menuId, "Creates a north arrow that is displayed on the map canvas");
10794

10895
// Create the action for tool
109-
#if QT_VERSION < 0x040000
110-
myQActionPointer = new QAction("North Arrow", QIcon(icon), "&Wmi",0, this, "run");
111-
#else
11296
myQActionPointer = new QAction(QIcon(icon), "North Arrow", this);
113-
#endif
11497
myQActionPointer->setWhatsThis("Creates a north arrow that is displayed on the map canvas");
11598
// Connect the action to the run
11699
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
@@ -213,9 +196,8 @@ void QgsNorthArrowPlugin::renderNorthArrow(QPainter * theQPainter)
213196
) - centerYDouble);
214197

215198
// need width/height of paint device
216-
Q3PaintDeviceMetrics myMetrics( theQPainter->device() );
217-
int myHeight = myMetrics.height();
218-
int myWidth = myMetrics.width();
199+
int myHeight = theQPainter->device()->height();
200+
int myWidth = theQPainter->device()->width();
219201

220202
#ifdef QGISDEBUG
221203
std::cout << "Rendering n-arrow at " << mPlacement.toLocal8Bit().data() << std::endl;
@@ -241,14 +223,12 @@ void QgsNorthArrowPlugin::renderNorthArrow(QPainter * theQPainter)
241223
}
242224
//rotate the canvas by the north arrow rotation amount
243225
theQPainter->rotate( mRotationInt );
244-
//Now we can actually do the drawing
226+
//Now we can actually do the drawing, and draw a smooth north arrow even when rotated
227+
theQPainter->setRenderHint(QPainter::SmoothPixmapTransform);
245228
theQPainter->drawPixmap(xShift,yShift,myQPixmap);
246229

247-
//unrotate the canvase again
230+
//unrotate the canvas again
248231
theQPainter->restore();
249-
250-
//bitBlt ( qGisInterface->getMapCanvas()->canvasPixmap(), 0, 0, &myPainterPixmap, 0, 0, -1 , -1, Qt::CopyROP, false);
251-
252232
}
253233
else
254234
{

‎plugins/north_arrow/plugin.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
/* $Id$ */
2020
#ifndef QGSNORTHARROWPLUGIN
2121
#define QGSNORTHARROWPLUGIN
22-
#include "../qgisplugin.h"
23-
#include <qwidget.h>
24-
#include <qpainter.h>
25-
2622

23+
#include "../qgisplugin.h"
2724
#include "../../src/qgisapp.h"
25+
2826
class QToolBar;
2927
/**
3028
* \class Plugin

‎plugins/north_arrow/plugingui.cpp

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,23 @@
1111
***************************************************************************/
1212
#include "plugingui.h"
1313

14-
//qt includes
15-
#include <qapplication.h>
16-
#include <qpainter.h>
17-
#include <qlabel.h>
18-
#include <qglobal.h>
19-
//Added by qt3to4:
20-
#include <QPixmap>
21-
#include <QResizeEvent>
22-
#include <QPaintEvent>
14+
#include <QPainter>
15+
#include <cmath>
16+
2317
#include <iostream>
24-
#include <qspinbox.h>
25-
#include <qslider.h>
26-
#include <qtabwidget.h>
27-
#include <QComboBox>
28-
#include <qcheckbox.h>
29-
//standard includes
30-
#include <math.h>
31-
32-
QgsNorthArrowPluginGui::QgsNorthArrowPluginGui() : QgsNorthArrowPluginGuiBase()
18+
19+
QgsNorthArrowPluginGui::QgsNorthArrowPluginGui() : QDialog()
3320
{
21+
setupUi(this);
3422
//temporary hack until this is implemented
3523
tabNorthArrowOptions->removePage( tabIcon );
3624
rotatePixmap(0);
3725
}
3826

3927
QgsNorthArrowPluginGui::QgsNorthArrowPluginGui( QWidget* parent , const char* name , bool modal , Qt::WFlags fl )
40-
//: QgsNorthArrowPluginGuiBase( parent, name, modal, fl )
41-
//Tim removed params during qt4 ui port - FIXME!
42-
: QgsNorthArrowPluginGuiBase( )
28+
: QDialog( parent, name, modal, fl )
4329
{
30+
setupUi(this);
4431
//temporary hack until this is implemented
4532
tabNorthArrowOptions->removePage( tabIcon );
4633
}
@@ -49,7 +36,7 @@ QgsNorthArrowPluginGui::~QgsNorthArrowPluginGui()
4936
{
5037
}
5138

52-
void QgsNorthArrowPluginGui::pbnOK_clicked()
39+
void QgsNorthArrowPluginGui::on_pbnOK_clicked()
5340
{
5441
// Hide the dialog
5542
hide();
@@ -62,7 +49,7 @@ void QgsNorthArrowPluginGui::pbnOK_clicked()
6249

6350
done(1);
6451
}
65-
void QgsNorthArrowPluginGui::pbnCancel_clicked()
52+
void QgsNorthArrowPluginGui::on_pbnCancel_clicked()
6653
{
6754
close(1);
6855
}
@@ -94,14 +81,13 @@ void QgsNorthArrowPluginGui::setAutomaticDisabled()
9481
}
9582

9683

97-
//overides function byt the same name created in .ui
98-
void QgsNorthArrowPluginGui::spinSize_valueChanged( int theInt)
84+
//overides function by the same name created in .ui
85+
void QgsNorthArrowPluginGui::on_spinAngle_valueChanged( int theInt)
9986
{
10087

10188
}
10289

103-
//overides function byt the same name created in .ui
104-
void QgsNorthArrowPluginGui::sliderRotation_valueChanged( int theInt)
90+
void QgsNorthArrowPluginGui::on_sliderRotation_valueChanged( int theInt)
10591
{
10692
rotatePixmap(theInt);
10793
}
@@ -121,6 +107,8 @@ void QgsNorthArrowPluginGui::rotatePixmap(int theRotationInt)
121107
QPainter myQPainter;
122108
myQPainter.begin(&myPainterPixmap);
123109

110+
myQPainter.setRenderHint(QPainter::SmoothPixmapTransform);
111+
124112
double centerXDouble = myQPixmap.width()/2;
125113
double centerYDouble = myQPixmap.height()/2;
126114
//save the current canvas rotation
@@ -142,27 +130,14 @@ void QgsNorthArrowPluginGui::rotatePixmap(int theRotationInt)
142130
(centerYDouble * cos(myRadiansDouble))
143131
) - centerYDouble);
144132

145-
146-
147133
//draw the pixmap in the proper position
148-
myQPainter.drawPixmap(xShift,yShift,myQPixmap);
134+
myQPainter.drawPixmap(xShift,yShift,myQPixmap);
149135

150-
151-
//unrotate the canvase again
136+
//unrotate the canvas again
152137
myQPainter.restore();
153138
myQPainter.end();
154139

155-
//determine the center of the canvas given that we will bitblt form the origin of the narrow
156-
int myCenterXInt = static_cast<int>((pixmapLabel->width()-myQPixmap.width())/2);
157-
int myCenterYInt = static_cast<int>((pixmapLabel->height()-myQPixmap.height())/2);
158-
#if QT_VERSION < 0x040000
159-
bitBlt ( pixmapLabel, myCenterXInt,myCenterYInt, &myPainterPixmap, 0, 0, -1 , -1, Qt::CopyROP, false);
160-
#else
161-
// TODO: Qt4 uses QPainter::drawPixmap instead; need to refactor
162-
#endif
163-
164-
165-
//pixmapLabel1->setPixmap(myPainterPixmap);
140+
pixmapLabel->setPixmap(myPainterPixmap);
166141
}
167142
else
168143
{

‎plugins/north_arrow/plugingui.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
#define QGSNORTHARROWPLUGINGUI_H
1414

1515
#include <ui_pluginguibase.h>
16-
#include <QDialog>
17-
//Added by qt3to4:
18-
#include <QResizeEvent>
19-
#include <QPaintEvent>
2016

2117
/**
2218
@author Tim Sutton
@@ -28,8 +24,10 @@ Q_OBJECT
2824
QgsNorthArrowPluginGui();
2925
QgsNorthArrowPluginGui( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, Qt::WFlags fl = 0 );
3026
~QgsNorthArrowPluginGui();
31-
void pbnOK_clicked();
32-
void pbnCancel_clicked();
27+
28+
public slots:
29+
void on_pbnOK_clicked();
30+
void on_pbnCancel_clicked();
3331

3432
private:
3533
void rotatePixmap(int theRotationInt);
@@ -53,10 +51,8 @@ public slots:
5351
void setAutomaticDisabled();
5452

5553
private slots:
56-
//overides function byt the same name created in .ui
57-
void spinSize_valueChanged( int theInt);
58-
//overides function byt the same name created in .ui
59-
void sliderRotation_valueChanged( int theInt);
54+
void on_spinAngle_valueChanged( int theInt);
55+
void on_sliderRotation_valueChanged( int theInt);
6056
};
6157

6258
#endif

‎plugins/north_arrow/pluginguibase.ui

Lines changed: 103 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<rect>
99
<x>0</x>
1010
<y>0</y>
11-
<width>540</width>
11+
<width>457</width>
1212
<height>422</height>
1313
</rect>
1414
</property>
@@ -20,75 +20,11 @@
2020
</property>
2121
<layout class="QGridLayout" >
2222
<property name="margin" >
23-
<number>10</number>
23+
<number>9</number>
2424
</property>
2525
<property name="spacing" >
2626
<number>6</number>
2727
</property>
28-
<item rowspan="2" row="0" column="0" >
29-
<widget class="QLabel" name="pixmapLabel2" >
30-
<property name="maximumSize" >
31-
<size>
32-
<width>150</width>
33-
<height>32767</height>
34-
</size>
35-
</property>
36-
<property name="pixmap" >
37-
<pixmap/>
38-
</property>
39-
<property name="scaledContents" >
40-
<bool>true</bool>
41-
</property>
42-
</widget>
43-
</item>
44-
<item rowspan="2" row="0" column="1" >
45-
<widget class="Line" name="line1" >
46-
<property name="maximumSize" >
47-
<size>
48-
<width>2</width>
49-
<height>32767</height>
50-
</size>
51-
</property>
52-
<property name="frameShape" >
53-
<enum>QFrame::VLine</enum>
54-
</property>
55-
<property name="frameShadow" >
56-
<enum>QFrame::Sunken</enum>
57-
</property>
58-
<property name="orientation" >
59-
<enum>Qt::Vertical</enum>
60-
</property>
61-
</widget>
62-
</item>
63-
<item row="0" column="2" >
64-
<widget class="QLabel" name="txtHeading" >
65-
<property name="sizePolicy" >
66-
<sizepolicy>
67-
<hsizetype>5</hsizetype>
68-
<vsizetype>1</vsizetype>
69-
<horstretch>0</horstretch>
70-
<verstretch>0</verstretch>
71-
</sizepolicy>
72-
</property>
73-
<property name="font" >
74-
<font>
75-
<family></family>
76-
<pointsize>24</pointsize>
77-
<weight>50</weight>
78-
<italic>false</italic>
79-
<bold>false</bold>
80-
<underline>false</underline>
81-
<strikeout>false</strikeout>
82-
</font>
83-
</property>
84-
<property name="text" >
85-
<string>North Arrow Plugin</string>
86-
</property>
87-
<property name="alignment" >
88-
<set>Qt::AlignCenter</set>
89-
</property>
90-
</widget>
91-
</item>
9228
<item row="1" column="2" >
9329
<widget class="QTabWidget" name="tabNorthArrowOptions" >
9430
<property name="enabled" >
@@ -234,7 +170,10 @@
234170
<enum>QFrame::Box</enum>
235171
</property>
236172
<property name="scaledContents" >
237-
<bool>true</bool>
173+
<bool>false</bool>
174+
</property>
175+
<property name="alignment" >
176+
<set>Qt::AlignCenter</set>
238177
</property>
239178
</widget>
240179
</item>
@@ -294,8 +233,8 @@
294233
</property>
295234
<property name="sizeHint" >
296235
<size>
297-
<width>326</width>
298-
<height>21</height>
236+
<width>351</width>
237+
<height>31</height>
299238
</size>
300239
</property>
301240
</spacer>
@@ -322,6 +261,64 @@
322261
</item>
323262
</layout>
324263
</item>
264+
<item row="0" column="2" >
265+
<widget class="QLabel" name="txtHeading" >
266+
<property name="sizePolicy" >
267+
<sizepolicy>
268+
<hsizetype>5</hsizetype>
269+
<vsizetype>1</vsizetype>
270+
<horstretch>0</horstretch>
271+
<verstretch>0</verstretch>
272+
</sizepolicy>
273+
</property>
274+
<property name="font" >
275+
<font>
276+
<family>Sans Serif</family>
277+
<pointsize>24</pointsize>
278+
<weight>50</weight>
279+
<italic>false</italic>
280+
<bold>false</bold>
281+
<underline>false</underline>
282+
<strikeout>false</strikeout>
283+
</font>
284+
</property>
285+
<property name="text" >
286+
<string>North Arrow Plugin</string>
287+
</property>
288+
<property name="alignment" >
289+
<set>Qt::AlignCenter</set>
290+
</property>
291+
</widget>
292+
</item>
293+
<item rowspan="2" row="0" column="1" >
294+
<widget class="Line" name="line1" >
295+
<property name="maximumSize" >
296+
<size>
297+
<width>2</width>
298+
<height>32767</height>
299+
</size>
300+
</property>
301+
<property name="frameShape" >
302+
<enum>QFrame::VLine</enum>
303+
</property>
304+
<property name="frameShadow" >
305+
<enum>QFrame::Sunken</enum>
306+
</property>
307+
<property name="orientation" >
308+
<enum>Qt::Vertical</enum>
309+
</property>
310+
</widget>
311+
</item>
312+
<item rowspan="2" row="0" column="0" >
313+
<widget class="QLabel" name="label" >
314+
<property name="text" >
315+
<string/>
316+
</property>
317+
<property name="pixmap" >
318+
<pixmap resource="northarrow_plugin.qrc" >:/northarrow.png</pixmap>
319+
</property>
320+
</widget>
321+
</item>
325322
</layout>
326323
</widget>
327324
<layoutdefault spacing="6" margin="11" />
@@ -335,6 +332,41 @@
335332
<pixmap></pixmap>
336333
</customwidget>
337334
</customwidgets>
338-
<resources/>
339-
<connections/>
335+
<resources>
336+
<include location="northarrow_plugin.qrc" />
337+
</resources>
338+
<connections>
339+
<connection>
340+
<sender>sliderRotation</sender>
341+
<signal>sliderMoved(int)</signal>
342+
<receiver>spinAngle</receiver>
343+
<slot>setValue(int)</slot>
344+
<hints>
345+
<hint type="sourcelabel" >
346+
<x>374</x>
347+
<y>257</y>
348+
</hint>
349+
<hint type="destinationlabel" >
350+
<x>527</x>
351+
<y>259</y>
352+
</hint>
353+
</hints>
354+
</connection>
355+
<connection>
356+
<sender>spinAngle</sender>
357+
<signal>valueChanged(int)</signal>
358+
<receiver>sliderRotation</receiver>
359+
<slot>setValue(int)</slot>
360+
<hints>
361+
<hint type="sourcelabel" >
362+
<x>524</x>
363+
<y>244</y>
364+
</hint>
365+
<hint type="destinationlabel" >
366+
<x>351</x>
367+
<y>263</y>
368+
</hint>
369+
</hints>
370+
</connection>
371+
</connections>
340372
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.