Skip to content
Permalink
Browse files

Merge pull request #181 from etiennesky/decorationgrid

[FEATURE] Added Decoration grid
  • Loading branch information
timlinux committed Jun 26, 2012
2 parents 91862c3 + 94a1210 commit 10ad3fb072ae2d47d29a1e279eb90d7c3e1a5678
@@ -19,12 +19,15 @@ SET(QGIS_APP_SRCS
qgsconfigureshortcutsdialog.cpp
qgscustomization.cpp
qgscustomprojectiondialog.cpp
qgsdecorationitem.cpp
qgsdecorationcopyright.cpp
qgsdecorationcopyrightdialog.cpp
qgsdecorationnortharrow.cpp
qgsdecorationnortharrowdialog.cpp
qgsdecorationscalebar.cpp
qgsdecorationscalebardialog.cpp
qgsdecorationgrid.cpp
qgsdecorationgriddialog.cpp
qgsembedlayerdialog.cpp
qgsformannotationdialog.cpp
qgsdelattrdialog.cpp
@@ -167,12 +170,15 @@ SET (QGIS_APP_MOC_HDRS
qgscontinuouscolordialog.h
qgscustomization.h
qgscustomprojectiondialog.h
qgsdecorationitem.h
qgsdecorationcopyright.h
qgsdecorationcopyrightdialog.h
qgsdecorationnortharrow.h
qgsdecorationnortharrowdialog.h
qgsdecorationscalebar.h
qgsdecorationscalebardialog.h
qgsdecorationgrid.h
qgsdecorationgriddialog.h
qgsdelattrdialog.h
qgsdisplayangle.h
qgsembedlayerdialog.h
@@ -117,6 +117,7 @@
#include "qgsdecorationcopyright.h"
#include "qgsdecorationnortharrow.h"
#include "qgsdecorationscalebar.h"
#include "qgsdecorationgrid.h"
#include "qgsembedlayerdialog.h"
#include "qgsencodingfiledialog.h"
#include "qgsexception.h"
@@ -1609,6 +1610,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionDecorationCopyright->setIcon( getThemeIcon( "/plugins/copyright_label.png" ) );
mActionDecorationNorthArrow->setIcon( getThemeIcon( "/plugins/north_arrow.png" ) );
mActionDecorationScaleBar->setIcon( getThemeIcon( "/plugins/scale_bar.png" ) );
mActionDecorationGrid->setIcon( getThemeIcon( "/transformed.png" ) );

//change themes of all composers
QSet<QgsComposer*>::iterator composerIt = mPrintComposers.begin();
@@ -2002,20 +2004,42 @@ 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() ) );

QgsDecorationGrid* mDecorationGrid = new QgsDecorationGrid( this );
connect( mActionDecorationGrid, SIGNAL( triggered() ), mDecorationGrid, SLOT( run() ) );

// 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( newProject() ), this, SLOT( projectReadDecorationItems() ) );
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
@@ -5003,11 +5027,13 @@ void QgisApp::setProjectCRSFromLayer()

QgsCoordinateReferenceSystem crs = mMapLegend->currentLayer()->crs();
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
mMapCanvas->freeze();
myRenderer->setDestinationCrs( crs );
if ( crs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( crs.mapUnits() );
}
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}

@@ -69,15 +69,14 @@ class QgsBrowserDockWidget;
class QgsSnappingDialog;
class QgsGPSInformationWidget;

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

class QgsMessageLogViewer;

class QgsScaleComboBox;

class QgsDataItem;
class QgsTileScaleWidget;

#include <QMainWindow>
#include <QToolBar>
@@ -381,6 +380,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 +871,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,9 +1190,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

QgsSnappingDialog* mSnappingDialog;

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

QList<QgsDecorationItem*> mDecorationItems;

int mLastComposerId;

@@ -1213,6 +1219,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();
}

0 comments on commit 10ad3fb

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