80 changes: 80 additions & 0 deletions src/app/qgsdecorationitem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/***************************************************************************
qgsdecorationitem.cpp
----------------------
begin : May 10, 2012
copyright : (C) 2012 by Etienne Tourigny
email : etourigny.dev at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdecorationitem.h"

#include "qgisapp.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsmaptopixel.h"
#include "qgspoint.h"
#include "qgsproject.h"
#include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance

#include <QPainter>
#include <QAction>
#include <QPen>
#include <QPolygon>
#include <QString>
#include <QFontMetrics>
#include <QFont>
#include <QColor>
#include <QMenu>
#include <QFile>
#include <QLocale>

//non qt includes
#include <cmath>

QgsDecorationItem::QgsDecorationItem( QObject* parent )
: QObject( parent )
{
mEnabled = false;
}

QgsDecorationItem::~QgsDecorationItem()
{

}

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

void QgsDecorationItem::projectRead()
{
QgsDebugMsg( "Entered" );
mEnabled = QgsProject::instance()->readBoolEntry( mNameConfig, "/Enabled", false );
}

void QgsDecorationItem::saveToProject()
{
QgsDebugMsg( "Entered" );
QgsProject::instance()->writeEntry( mNameConfig, "/Enabled", mEnabled );
}
void QgsDecorationItem::setName( const char *name )
{
mName = name;
mNameConfig = name;
mNameConfig.remove( " " );
mNameTranslated = tr( name );
QgsDebugMsg( QString( "name=%1 nameconfig=%2 nametrans=%3").arg(mName).arg(mNameConfig).arg(mNameTranslated) );
}
67 changes: 67 additions & 0 deletions src/app/qgsdecorationitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***************************************************************************
qgsdecorationitem.h
----------------------
begin : May 10, 2012
copyright : (C) 2012 by Etienne Tourigny
email : etourigny.dev at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSDECORATIONITEM_H
#define QGSDECORATIONITEM_H

#include <QObject>
#include "qgslogger.h"

class QPainter;

class QgsDecorationItem: public QObject
{
Q_OBJECT
public:
//! Constructor
QgsDecorationItem( QObject* parent = NULL );
//! Destructor
virtual ~ QgsDecorationItem();

void setEnabled( bool enabled ) { mEnabled = enabled; }
bool enabled() const { return mEnabled; }

void update();

signals:
void toggled( bool t );

public slots:
//! set values on the gui when a project is read or the gui first loaded
virtual void projectRead();
//! save values to the project
virtual void saveToProject();

//! this does the meaty bit of the work
virtual void render( QPainter * ) {}
//! Show the dialog box
virtual void run() {}

virtual void setName( const char *name );
virtual QString name() { return mName; }

protected:

/**True if decoration item has to be displayed*/
bool mEnabled;

QString mName;
QString mNameConfig;
QString mNameTranslated;
};

#endif