Skip to content

Commit d003d19

Browse files
author
g_j_m
committedMay 13, 2006
Do for the copyright label what has just been done for the scale bar
and north arrow (deal better with translated placement words). Also tidy up scale bar and north arrow code a little bit. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5446 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

7 files changed

+63
-60
lines changed

7 files changed

+63
-60
lines changed
 

‎src/plugins/copyright_label/plugin.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ QgsCopyrightLabelPlugin::QgsCopyrightLabelPlugin(QgisApp * theQGisApp,
6969
QgisPlugin(name_,description_,version_,type_),
7070
qgisMainWindowPointer(theQGisApp),
7171
qGisInterface(theQgisInterFace)
72-
{}
72+
{
73+
mPlacementLabels << tr("Bottom Left") << tr("Top Left")
74+
<< tr("Top Right") << tr("Bottom Right");
75+
}
7376

7477
QgsCopyrightLabelPlugin::~QgsCopyrightLabelPlugin()
7578
{}
@@ -110,7 +113,7 @@ void QgsCopyrightLabelPlugin::projectRead()
110113
mQFont.setFamily(QgsProject::instance()->readEntry("CopyrightLabel","/FontName","Arial"));
111114
mQFont.setPointSize(QgsProject::instance()->readNumEntry("CopyrightLabel","/FontSize",14));
112115
mLabelQString = QgsProject::instance()->readEntry("CopyrightLabel","/Label","&copy; QGIS 2006");
113-
mPlacement = QgsProject::instance()->readEntry("CopyrightLabel","/Placement","Bottom Right");
116+
mPlacementIndex = QgsProject::instance()->readNumEntry("CopyrightLabel","/Placement",3);
114117
mEnable = QgsProject::instance()->readBoolEntry("CopyrightLabel","/Enabled",true);
115118
// todo - read & store state of font color
116119
mLabelQColor = QColor(Qt::black);
@@ -133,10 +136,11 @@ void QgsCopyrightLabelPlugin::run()
133136
connect(myPluginGui, SIGNAL(changeFont(QFont )), this, SLOT(setFont(QFont )));
134137
connect(myPluginGui, SIGNAL(changeLabel(QString )), this, SLOT(setLabel(QString )));
135138
connect(myPluginGui, SIGNAL(changeColor(QColor)), this, SLOT(setColor(QColor)));
136-
connect(myPluginGui, SIGNAL(changePlacement(QString)), this, SLOT(setPlacement(QString)));
139+
connect(myPluginGui, SIGNAL(changePlacement(int)), this, SLOT(setPlacement(int)));
137140
connect(myPluginGui, SIGNAL(enableCopyrightLabel(bool)), this, SLOT(setEnable(bool)));
138141
myPluginGui->setText(mLabelQString);
139-
myPluginGui->setPlacement(mPlacement);
142+
myPluginGui->setPlacementLabels(mPlacementLabels);
143+
myPluginGui->setPlacement(mPlacementIndex);
140144
myPluginGui->show();
141145
}
142146
//! Refresh the map display using the mapcanvas exported via the plugin interface
@@ -167,31 +171,31 @@ void QgsCopyrightLabelPlugin::renderLabel(QPainter * theQPainter)
167171
int myYOffset = myHeight;
168172
int myXOffset = myWidth;
169173

170-
171174
//Determine placement of label from form combo box
172-
if (mPlacement==tr("Bottom Left"))
173-
{
174-
//Define bottom left hand corner start point
175-
myYOffset = myYOffset - (myQSimpleText.height()+5);
176-
myXOffset = 5;
177-
}
178-
else if (mPlacement==tr("Top Left"))
179-
{
180-
//Define top left hand corner start point
181-
myYOffset = 5;
182-
myXOffset = 5;
183-
}
184-
else if (mPlacement==tr("Top Right"))
185-
{
186-
//Define top right hand corner start point
187-
myYOffset = 5;
188-
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
189-
}
190-
else // defaulting to bottom right
175+
switch (mPlacementIndex)
191176
{
192-
//Define bottom right hand corner start point
193-
myYOffset = myYOffset - (myQSimpleText.height()+5);
194-
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
177+
case 0: // Bottom Left
178+
//Define bottom left hand corner start point
179+
myYOffset = myYOffset - (myQSimpleText.height()+5);
180+
myXOffset = 5;
181+
break;
182+
case 1: // Top left
183+
//Define top left hand corner start point
184+
myYOffset = 5;
185+
myXOffset = 5;
186+
break;
187+
case 2: // Top Right
188+
//Define top right hand corner start point
189+
myYOffset = 5;
190+
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
191+
break;
192+
case 3: // Bottom Right
193+
//Define bottom right hand corner start point
194+
myYOffset = myYOffset - (myQSimpleText.height()+5);
195+
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
196+
break;
197+
default:
198+
std::cerr << "Unknown placement index of " << mPlacementIndex << '\n';
195199
}
196200

197201
//Paint label to canvas
@@ -243,10 +247,10 @@ void QgsCopyrightLabelPlugin::setColor(QColor theQColor)
243247
}
244248

245249
//! set placement of copyright label
246-
void QgsCopyrightLabelPlugin::setPlacement(QString theQString)
250+
void QgsCopyrightLabelPlugin::setPlacement(int placementIndex)
247251
{
248-
mPlacement = theQString;
249-
QgsProject::instance()->writeEntry("CopyrightLabel","/Placement", mPlacement);
252+
mPlacementIndex = placementIndex;
253+
QgsProject::instance()->writeEntry("CopyrightLabel","/Placement", mPlacementIndex);
250254
refreshCanvas();
251255
}
252256

‎src/plugins/copyright_label/plugin.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class QgsCopyrightLabelPlugin:public QObject, public QgisPlugin
6363
//! change the copyright font colour
6464
void setColor(QColor);
6565
//! set copyright label placement
66-
void setPlacement(QString);
66+
void setPlacement(int);
6767
//! set copyright label enabled
6868
void setEnable(bool);
6969

@@ -76,8 +76,9 @@ class QgsCopyrightLabelPlugin:public QObject, public QgisPlugin
7676
QString mLabelQString;
7777
//! This is the colour for the copyright label
7878
QColor mLabelQColor;
79-
//! Placement of the copyright label
80-
QString mPlacement;
79+
//! Placement of the copyright label - index and translated label names
80+
int mPlacementIndex;
81+
QStringList mPlacementLabels;
8182
//! Copyright label enabled
8283
bool mEnable;
8384

‎src/plugins/copyright_label/plugingui.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void QgsCopyrightLabelPluginGui::on_pbnOK_clicked()
4444
emit changeFont(txtCopyrightText->currentFont());
4545
emit changeLabel(txtCopyrightText->text());
4646
emit changeColor(txtCopyrightText->color());
47-
emit changePlacement(cboPlacement->currentText());
47+
emit changePlacement(cboPlacement->currentIndex());
4848
emit enableCopyrightLabel(cboxEnabled->isChecked());
4949

5050
done(1);
@@ -68,7 +68,13 @@ void QgsCopyrightLabelPluginGui::setText(QString theTextQString)
6868
txtCopyrightText->setPlainText(theTextQString);
6969
}
7070

71-
void QgsCopyrightLabelPluginGui::setPlacement(QString thePlacementQString)
71+
void QgsCopyrightLabelPluginGui::setPlacementLabels(QStringList& labels)
7272
{
73-
cboPlacement->setCurrentText(tr(thePlacementQString));
73+
cboPlacement->clear();
74+
cboPlacement->addItems(labels);
75+
}
76+
77+
void QgsCopyrightLabelPluginGui::setPlacement(int placementIndex)
78+
{
79+
cboPlacement->setCurrentIndex(placementIndex);
7480
}

‎src/plugins/copyright_label/plugingui.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Q_OBJECT;
2727
QgsCopyrightLabelPluginGui( QWidget* parent = 0, Qt::WFlags fl = 0 );
2828
~QgsCopyrightLabelPluginGui();
2929
void setText(QString);
30-
void setPlacement(QString);
30+
void setPlacementLabels(QStringList&);
31+
void setPlacement(int);
3132

3233
public slots:
3334
void on_pbnOK_clicked();
@@ -44,7 +45,7 @@ public slots:
4445
void changeFont(QFont);
4546
void changeLabel(QString);
4647
void changeColor(QColor);
47-
void changePlacement(QString);
48+
void changePlacement(int);
4849
void enableCopyrightLabel(bool);
4950

5051
};

‎src/plugins/north_arrow/plugin.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ QgsNorthArrowPlugin::QgsNorthArrowPlugin(QgisApp * theQGisApp,
7474
QgisIface * theQgisInterFace):
7575
QgisPlugin(name_,description_,version_,type_),
7676
qgisMainWindowPointer(theQGisApp),
77-
qGisInterface(theQgisInterFace),
78-
mPlacementIndex(1)
77+
qGisInterface(theQgisInterFace)
7978
{
8079
mRotationInt=0;
8180
mAutomatic=true;
82-
mPlacementLabels << tr("Bottom Left") << tr("Top Left") << tr("Top Right") << tr("Bottom Right");
83-
mPlacementIndex = 0;
81+
mPlacementLabels << tr("Bottom Left") << tr("Top Left")
82+
<< tr("Top Right") << tr("Bottom Right");
8483
}
8584

8685
QgsNorthArrowPlugin::~QgsNorthArrowPlugin()

‎src/plugins/north_arrow/plugingui.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,6 @@ void QgsNorthArrowPluginGui::rotatePixmap(int theRotationInt)
161161
}
162162
}
163163

164-
// Called when the widget needs to be updated.
165-
//
166-
/*
167-
void QgsNorthArrowPluginGui::paintEvent( QPaintEvent * thePaintEvent)
168-
{
169-
std::cerr<<__FILE__<<__LINE__<<'\n';
170-
rotatePixmap(sliderRotation->value());
171-
std::cerr<<__FILE__<<__LINE__<<'\n';
172-
}
173-
*/
174164
//
175165
// Called when the widget has been resized.
176166
//

‎src/plugins/scale_bar/plugin.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ QgsScaleBarPlugin::QgsScaleBarPlugin(QgisApp * theQGisApp,
7777
qgisMainWindowPointer(theQGisApp),
7878
qGisInterface(theQgisInterFace)
7979
{
80-
mPlacementLabels << tr("Top Left") << tr("Bottom Left") << tr("Top Right") << tr("Bottom Right");
81-
mStyleLabels << tr("Tick Down") << tr("Tick Up") << tr("Bar") << tr("Box");
80+
mPlacementLabels << tr("Bottom Left") << tr("Top Left")
81+
<< tr("Top Right") << tr("Bottom Right");
82+
mPlacementIndex = 1;
83+
mStyleLabels << tr("Tick Down") << tr("Tick Up")
84+
<< tr("Bar") << tr("Box");
8285

8386
mPreferredSize = 30;
84-
mPlacementIndex = 0;
8587
mStyleIndex = 0;
8688
mEnabled = true;
8789
mSnapping = true;
@@ -129,7 +131,7 @@ void QgsScaleBarPlugin::projectRead()
129131

130132
mPreferredSize = QgsProject::instance()->readNumEntry("ScaleBar","/PreferredSize",30);
131133
mStyleIndex = QgsProject::instance()->readNumEntry("ScaleBar","/Style",0);
132-
mPlacementIndex = QgsProject::instance()->readNumEntry("ScaleBar","/Placement",0);
134+
mPlacementIndex = QgsProject::instance()->readNumEntry("ScaleBar","/Placement",2);
133135
mEnabled = QgsProject::instance()->readBoolEntry("ScaleBar","/Enabled",true);
134136
mSnapping = QgsProject::instance()->readBoolEntry("ScaleBar","/Snapping",true);
135137
int myRedInt = QgsProject::instance()->readNumEntry("ScaleBar","/ColorRedPart",0);
@@ -301,13 +303,13 @@ void QgsScaleBarPlugin::renderScaleBar(QPainter * theQPainter)
301303
int myOriginY=myMargin;
302304
switch (mPlacementIndex)
303305
{
304-
case 0: // Top Left
306+
case 0: // Bottom Left
305307
myOriginX=myMargin;
306-
myOriginY=myMargin;
308+
myOriginY=myCanvasHeight - myMargin;
307309
break;
308-
case 1: // Bottom Left
310+
case 1: // Top Left
309311
myOriginX=myMargin;
310-
myOriginY=myCanvasHeight - myMargin;
312+
myOriginY=myMargin;
311313
break;
312314
case 2: // Top Right
313315
myOriginX=myCanvasWidth - ((int) myTotalScaleBarWidth) - myMargin;

0 commit comments

Comments
 (0)
Please sign in to comment.