Skip to content
Permalink
Browse files

create QgsDecorationItem class for all decoration items and render in…

… a specific order (grid before others so it's on bottom
  • Loading branch information
etiennesky committed Jun 18, 2012
1 parent edda90a commit 01813240c5918c44768bc35df80b5c246a5cc84e
@@ -19,6 +19,7 @@ SET(QGIS_APP_SRCS
qgsconfigureshortcutsdialog.cpp
qgscustomization.cpp
qgscustomprojectiondialog.cpp
qgsdecorationitem.cpp
qgsdecorationcopyright.cpp
qgsdecorationcopyrightdialog.cpp
qgsdecorationnortharrow.cpp
@@ -169,6 +170,7 @@ SET (QGIS_APP_MOC_HDRS
qgscontinuouscolordialog.h
qgscustomization.h
qgscustomprojectiondialog.h
qgsdecorationitem.h
qgsdecorationcopyright.h
qgsdecorationcopyrightdialog.h
qgsdecorationnortharrow.h
@@ -2004,26 +2004,41 @@ void QgisApp::createMapTips()

void QgisApp::createDecorations()
{
mDecorationCopyright = new QgsDecorationCopyright( this );
QgsDecorationCopyright* mDecorationCopyright = new QgsDecorationCopyright( this );
connect( mActionDecorationCopyright, SIGNAL( triggered() ), mDecorationCopyright, SLOT( run() ) );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), mDecorationCopyright, SLOT( renderLabel( QPainter * ) ) );
connect( this, SIGNAL( projectRead() ), mDecorationCopyright, SLOT( projectRead() ) );

mDecorationNorthArrow = new QgsDecorationNorthArrow( this );
QgsDecorationNorthArrow* mDecorationNorthArrow = new QgsDecorationNorthArrow( this );
connect( mActionDecorationNorthArrow, SIGNAL( triggered() ), mDecorationNorthArrow, SLOT( run() ) );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), mDecorationNorthArrow, SLOT( renderNorthArrow( QPainter * ) ) );
connect( this, SIGNAL( projectRead() ), mDecorationNorthArrow, SLOT( projectRead() ) );

mDecorationScaleBar = new QgsDecorationScaleBar( this );
QgsDecorationScaleBar* mDecorationScaleBar = new QgsDecorationScaleBar( this );
connect( mActionDecorationScaleBar, SIGNAL( triggered() ), mDecorationScaleBar, SLOT( run() ) );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), mDecorationScaleBar, SLOT( renderScaleBar( QPainter * ) ) );
connect( this, SIGNAL( projectRead() ), mDecorationScaleBar, SLOT( projectRead() ) );

// TODO draw the decorations in a particular order - perhaps use a vector or decoration objects?
mDecorationGrid = new QgsDecorationGrid( this );
QgsDecorationGrid* mDecorationGrid = new QgsDecorationGrid( this );
connect( mActionDecorationGrid, SIGNAL( triggered() ), mDecorationGrid, SLOT( run() ) );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), mDecorationGrid, SLOT( renderGrid( QPainter * ) ) );
connect( this, SIGNAL( projectRead() ), mDecorationGrid, SLOT( projectRead() ) );

// add the decorations in a particular order so they are rendered in that order
addDecorationItem( mDecorationGrid );
addDecorationItem( mDecorationCopyright );
addDecorationItem( mDecorationNorthArrow );
addDecorationItem( mDecorationScaleBar );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( renderDecorationItems( QPainter * ) ) );
connect( this, SIGNAL( projectRead() ), this, SLOT( projectReadDecorationItems() ) );
}

void QgisApp::renderDecorationItems( QPainter *p )
{
foreach( QgsDecorationItem* item, mDecorationItems )
{
item->render( p );
}
}

void QgisApp::projectReadDecorationItems()
{
foreach( QgsDecorationItem* item, mDecorationItems )
{
item->projectRead( );
}
}

// Update file menu with the current list of recently accessed projects
@@ -69,10 +69,7 @@ class QgsBrowserDockWidget;
class QgsSnappingDialog;
class QgsGPSInformationWidget;

class QgsDecorationCopyright;
class QgsDecorationNorthArrow;
class QgsDecorationScaleBar;
class QgsDecorationGrid;
class QgsDecorationItem;

class QgsMessageLogViewer;

@@ -381,6 +378,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

void emitCustomSrsValidation( QgsCoordinateReferenceSystem *crs );

QList<QgsDecorationItem*> decorationItems() { return mDecorationItems; }
void addDecorationItem( QgsDecorationItem* item ) { mDecorationItems.append( item ); }

public slots:
//! Zoom to full extent
void zoomFull();
@@ -869,6 +869,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Activates label property tool
void changeLabelProperties();

void renderDecorationItems( QPainter *p );
void projectReadDecorationItems( );

signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -1185,10 +1188,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

QgsSnappingDialog* mSnappingDialog;

QgsDecorationCopyright* mDecorationCopyright;
QgsDecorationNorthArrow* mDecorationNorthArrow;
QgsDecorationScaleBar* mDecorationScaleBar;
QgsDecorationGrid* mDecorationGrid;
//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;

QList<QgsDecorationItem*> mDecorationItems;

int mLastComposerId;

@@ -1214,6 +1217,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
#endif

};

#ifdef ANDROID
@@ -42,11 +42,12 @@ email : tim@linfiniti.com


QgsDecorationCopyright::QgsDecorationCopyright( QObject* parent )
: QObject( parent )
: QgsDecorationItem( parent )
{
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
<< tr( "Top Right" ) << tr( "Bottom Right" );

setName( "Copyright Label" );
// initialise default values in the gui
projectRead();
}
@@ -56,20 +57,29 @@ QgsDecorationCopyright::~QgsDecorationCopyright()

void QgsDecorationCopyright::projectRead()
{
QDate now;
QString defString;
QgsDecorationItem::projectRead();

now = QDate::currentDate();
defString = "&copy; QGIS " + now.toString( "yyyy" );
QDate now = QDate::currentDate();
QString defString = "&copy; QGIS " + now.toString( "yyyy" );

// there is no font setting in the UI, so just use the Qt/QGIS default font (what mQFont gets when created)
// mQFont.setFamily( QgsProject::instance()->readEntry( "CopyrightLabel", "/FontName", "Sans Serif" ) );
// mQFont.setPointSize( QgsProject::instance()->readNumEntry( "CopyrightLabel", "/FontSize", 9 ) );
QgsProject* prj = QgsProject::instance();
mLabelQString = prj->readEntry( "CopyrightLabel", "/Label", defString );
mPlacementIndex = prj->readNumEntry( "CopyrightLabel", "/Placement", 3 );
mEnable = prj->readBoolEntry( "CopyrightLabel", "/Enabled", false );
mLabelQColor.setNamedColor( prj->readEntry( "CopyrightLabel", "/Color", "#000000" ) ); // default color is black
mLabelQString = prj->readEntry( mNameConfig, "/Label", defString );
mPlacementIndex = prj->readNumEntry( mNameConfig, "/Placement", 3 );
mLabelQColor.setNamedColor( prj->readEntry( mNameConfig, "/Color", "#000000" ) ); // default color is black
}

void QgsDecorationCopyright::saveToProject()
{
QgsDecorationItem::saveToProject();
QgsProject* prj = QgsProject::instance();
prj->writeEntry( mNameConfig, "/FontName", mQFont.family() );
prj->writeEntry( mNameConfig, "/FontSize", mQFont.pointSize() );
prj->writeEntry( mNameConfig, "/Label", mLabelQString );
prj->writeEntry( mNameConfig, "/Color", mLabelQColor.name() );
prj->writeEntry( mNameConfig, "/Placement", mPlacementIndex );
}

// Slot called when the buffer menu item is activated
@@ -79,16 +89,15 @@ void QgsDecorationCopyright::run()

if ( dlg.exec() )
{
saveToProject();
QgisApp::instance()->mapCanvas()->refresh();
update();
}
}


void QgsDecorationCopyright::renderLabel( QPainter * theQPainter )
void QgsDecorationCopyright::render( QPainter * theQPainter )
{
//Large IF statement to enable/disable copyright label
if ( mEnable )
if ( enabled() )
{
// need width/height of paint device
int myHeight = theQPainter->device()->height();
@@ -139,14 +148,3 @@ void QgsDecorationCopyright::renderLabel( QPainter * theQPainter )
}
}

void QgsDecorationCopyright::saveToProject()
{
//save state to the project file.....
QgsProject* prj = QgsProject::instance();
prj->writeEntry( "CopyrightLabel", "/FontName", mQFont.family() );
prj->writeEntry( "CopyrightLabel", "/FontSize", mQFont.pointSize() );
prj->writeEntry( "CopyrightLabel", "/Label", mLabelQString );
prj->writeEntry( "CopyrightLabel", "/Color", mLabelQColor.name() );
prj->writeEntry( "CopyrightLabel", "/Placement", mPlacementIndex );
prj->writeEntry( "CopyrightLabel", "/Enabled", mEnable );
}
@@ -19,6 +19,8 @@
#ifndef QGSCOPYRIGHTLABELPLUGIN
#define QGSCOPYRIGHTLABELPLUGIN

#include "qgsdecorationitem.h"

#include <QColor>
#include <QFont>
#include <QObject>
@@ -27,7 +29,7 @@ class QPainter;

class QgsDecorationCopyrightDialog;

class QgsDecorationCopyright : public QObject
class QgsDecorationCopyright : public QgsDecorationItem
{
Q_OBJECT
public:
@@ -46,7 +48,7 @@ class QgsDecorationCopyright : public QObject
//! Show the dialog box
void run();
//! render the copyright label
void renderLabel( QPainter * );
void render( QPainter * );

private:
//! This is the font that will be used for the copyright label
@@ -58,8 +60,6 @@ class QgsDecorationCopyright : public QObject
//! Placement of the copyright label - index and translated label names
int mPlacementIndex;
QStringList mPlacementLabels;
//! Copyright label enabled
bool mEnable;

friend class QgsDecorationCopyrightDialog;
};
@@ -33,7 +33,7 @@ QgsDecorationCopyrightDialog::QgsDecorationCopyrightDialog( QgsDecorationCopyrig
cboOrientation->hide();
textLabel15->hide();

cboxEnabled->setChecked( mDeco.mEnable );
cboxEnabled->setChecked( mDeco.enabled() );
// text
txtCopyrightText->setPlainText( mDeco.mLabelQString );
// placement
@@ -60,7 +60,7 @@ void QgsDecorationCopyrightDialog::on_buttonBox_accepted()
mDeco.mLabelQString = txtCopyrightText->toPlainText();
mDeco.mLabelQColor = pbnColorChooser->color();
mDeco.mPlacementIndex = cboPlacement->currentIndex();
mDeco.mEnable = cboxEnabled->isChecked();
mDeco.setEnabled( cboxEnabled->isChecked() );

accept();
}
@@ -52,8 +52,9 @@


QgsDecorationGrid::QgsDecorationGrid( QObject* parent )
: QObject( parent )
: QgsDecorationItem( parent )
{
setName( "Grid" );
projectRead();
}

@@ -62,42 +63,40 @@ QgsDecorationGrid::~QgsDecorationGrid()

}

void QgsDecorationGrid::update()
{
QgisApp::instance()->mapCanvas()->refresh();
}

void QgsDecorationGrid::projectRead()
{
mGridEnabled = QgsProject::instance()->readBoolEntry( "Grid", "/Enabled", false );
mGridStyle = ( GridStyle ) QgsProject::instance()->readNumEntry( "Grid", "/Style", 0 );
mGridIntervalX = QgsProject::instance()->readDoubleEntry( "Grid", "/IntervalX", 0 );
mGridIntervalY = QgsProject::instance()->readDoubleEntry( "Grid", "/IntervalY", 0 );
mGridOffsetX = QgsProject::instance()->readDoubleEntry( "Grid", "/OffsetX", 0 );
mGridOffsetY = QgsProject::instance()->readDoubleEntry( "Grid", "/OffsetY", 0 );
mCrossLength = QgsProject::instance()->readDoubleEntry( "Grid", "/CrossLength", 0 );
// missing mGridPen, mGridAnnotationFont
mGridAnnotationPrecision = ( GridAnnotationPosition ) QgsProject::instance()->readNumEntry( "Grid", "/AnnotationPrecision", 3 );
mShowGridAnnotation = QgsProject::instance()->readBoolEntry( "Grid", "/ShowAnnotation", false );
// mGridAnnotationPosition = (GridAnnotationPosition) QgsProject::instance()->readNumEntry( "Grid", "/AnnotationPosition", 0 );
mAnnotationFrameDistance = QgsProject::instance()->readDoubleEntry( "Grid", "/AnnotationFrameDistance", 0 );
mGridAnnotationDirection = ( GridAnnotationDirection ) QgsProject::instance()->readNumEntry( "Grid", "/AnnotationDirection", 0 );
QgsDecorationItem::projectRead();
mGridStyle = ( GridStyle ) QgsProject::instance()->readNumEntry( mNameConfig, "/Style", 0 );
mGridIntervalX = QgsProject::instance()->readDoubleEntry( mNameConfig, "/IntervalX", 0 );
mGridIntervalY = QgsProject::instance()->readDoubleEntry( mNameConfig, "/IntervalY", 0 );
mGridOffsetX = QgsProject::instance()->readDoubleEntry( mNameConfig, "/OffsetX", 0 );
mGridOffsetY = QgsProject::instance()->readDoubleEntry( mNameConfig, "/OffsetY", 0 );
// missing mGridPen, but should use styles anyway
mCrossLength = QgsProject::instance()->readDoubleEntry( mNameConfig, "/CrossLength", 0 );
mShowGridAnnotation = QgsProject::instance()->readBoolEntry( mNameConfig, "/ShowAnnotation", false );
mGridAnnotationPosition = ( GridAnnotationPosition ) QgsProject::instance()->readNumEntry( mNameConfig, "/AnnotationPosition", 0 );
mGridAnnotationDirection = ( GridAnnotationDirection ) QgsProject::instance()->readNumEntry( mNameConfig, "/AnnotationDirection", 0 );
mGridAnnotationFont.fromString( QgsProject::instance()->readEntry( mNameConfig, "/AnnotationFont", "" ) );
mAnnotationFrameDistance = QgsProject::instance()->readDoubleEntry( mNameConfig, "/AnnotationFrameDistance", 0 );
mGridAnnotationPrecision = QgsProject::instance()->readNumEntry( mNameConfig, "/AnnotationPrecision", 3 );
}

void QgsDecorationGrid::saveToProject()
{
QgsProject::instance()->writeEntry( "Grid", "/Enabled", mGridEnabled );
QgsProject::instance()->writeEntry( "Grid", "/IntervalX", mGridIntervalX );
QgsProject::instance()->writeEntry( "Grid", "/IntervalY", mGridIntervalY );
QgsProject::instance()->writeEntry( "Grid", "/OffsetX", mGridOffsetX );
QgsProject::instance()->writeEntry( "Grid", "/OffsetX", mGridOffsetY );
QgsProject::instance()->writeEntry( "Grid", "/CrossLength", mCrossLength );
// missing mGridPen, mGridAnnotationFont
QgsProject::instance()->writeEntry( "Grid", "/AnnotationPrecision", mGridAnnotationPrecision );
QgsProject::instance()->writeEntry( "Grid", "/ShowAnnotation", mShowGridAnnotation );
// QgsProject::instance()->writeEntry( "Grid", "/AnnotationPosition", mGridAnnotationPosition );
QgsProject::instance()->writeEntry( "Grid", "/AnnotationFrameDistance", mAnnotationFrameDistance );
QgsProject::instance()->writeEntry( "Grid", "/AnnotationDirection", mGridAnnotationDirection );
QgsDecorationItem::saveToProject();
QgsProject::instance()->writeEntry( mNameConfig, "/Style", ( int ) mGridStyle );
QgsProject::instance()->writeEntry( mNameConfig, "/IntervalX", mGridIntervalX );
QgsProject::instance()->writeEntry( mNameConfig, "/IntervalY", mGridIntervalY );
QgsProject::instance()->writeEntry( mNameConfig, "/OffsetX", mGridOffsetX );
QgsProject::instance()->writeEntry( mNameConfig, "/OffsetX", mGridOffsetY );
QgsProject::instance()->writeEntry( mNameConfig, "/CrossLength", mCrossLength );
// missing mGridPen, but should use styles anyway
QgsProject::instance()->writeEntry( mNameConfig, "/ShowAnnotation", mShowGridAnnotation );
QgsProject::instance()->writeEntry( mNameConfig, "/AnnotationPosition", ( int ) mGridAnnotationPosition );
QgsProject::instance()->writeEntry( mNameConfig, "/AnnotationDirection", ( int ) mGridAnnotationDirection );
QgsProject::instance()->writeEntry( mNameConfig, "/AnnotationFont", mGridAnnotationFont.toString() );
QgsProject::instance()->writeEntry( mNameConfig, "/AnnotationFrameDistance", mAnnotationFrameDistance );
QgsProject::instance()->writeEntry( mNameConfig, "/AnnotationPrecision", mGridAnnotationPrecision );
}


@@ -107,16 +106,13 @@ void QgsDecorationGrid::run()

if ( dlg.exec() )
{
saveToProject();
QgisApp::instance()->mapCanvas()->refresh();
update();
}
}



void QgsDecorationGrid::renderGrid( QPainter * p )
void QgsDecorationGrid::render( QPainter * p )
{
if ( ! mGridEnabled )
if ( ! mEnabled )
return;

p->setPen( mGridPen );

0 comments on commit 0181324

Please sign in to comment.
You can’t perform that action at this time.