Skip to content
Permalink
Browse files
use separate curves for each raster layer in identify result graph
  • Loading branch information
etiennesky authored and NathanW2 committed May 19, 2014
1 parent 1012d3d commit c80d84085caaf8624a1fd20a43f4ae182a83f7b2
@@ -57,6 +57,8 @@
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
#include <qwt_legend.h>
#include "qgsvectorcolorrampv2.h" // for random colors
#endif

QgsIdentifyResultsWebView::QgsIdentifyResultsWebView( QWidget *parent ) : QWebView( parent )
@@ -303,17 +305,13 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
mPlot->setAutoFillBackground( false );
mPlot->setAutoDelete( true );
mPlot->insertLegend( new QwtLegend(), QwtPlot::RightLegend );
QSizePolicy sizePolicy = QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
sizePolicy.setHeightForWidth( mPlot->sizePolicy().hasHeightForWidth() );
mPlot->setSizePolicy( sizePolicy );
mPlot->updateGeometry();

mPlotCurve = new QwtPlotCurve( "" );
mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
QPen( Qt::red, 2 ), QSize( 9, 9 ) ) );
mPlotCurve->attach( mPlot );
#else
delete mPlot;
mPlot = 0;
@@ -347,7 +345,9 @@ QgsIdentifyResultsDialog::~QgsIdentifyResultsDialog()
if ( mActionPopup )
delete mActionPopup;
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
delete mPlotCurve;
foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves )
delete curve;
mPlotCurves.clear();
#endif
}

@@ -600,6 +600,48 @@ void QgsIdentifyResultsDialog::mapLayerActionDestroyed()
}
}

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
QgsIdentifyPlotCurve::QgsIdentifyPlotCurve( const QMap<QString, QString> &attributes,
QwtPlot* plot, const QString &title, QColor color )
{
mPlotCurve = new QwtPlotCurve( title );

if ( color == QColor() )
{
color = QgsVectorRandomColorRampV2::randomColors( 1 )[0];
}
mPlotCurve->setSymbol( QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::white ),
QPen( color, 2 ), QSize( 9, 9 ) ) );

int i = 1;
for ( QMap<QString, QString>::const_iterator it = attributes.begin();
it != attributes.end(); ++it )
{
mPlotCurveXData.append( double( i++ ) );
mPlotCurveYData.append( double( it.value().toDouble() ) );
}
mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData );

mPlotCurve->attach( plot );

plot->setAxisMaxMinor( QwtPlot::xBottom, 0 );
//mPlot->setAxisScale( QwtPlot::xBottom, 1, mPlotCurve->dataSize());
//mPlot->setAxisScale( QwtPlot::yLeft, ymin, ymax );

plot->replot();
plot->setVisible( true );
}

QgsIdentifyPlotCurve::~QgsIdentifyPlotCurve()
{
if ( mPlotCurve )
{
mPlotCurve->detach();
delete mPlotCurve;
}
}
#endif

void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
QString label,
const QMap<QString, QString> &attributes,
@@ -741,20 +783,10 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,

// graph
#if defined(QWT_VERSION) && QWT_VERSION<0x060000
i = mPlotCurveXData.count();
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
if ( attributes.count() > 0 )
{
mPlotCurveXData.append( double( ++i ) );
mPlotCurveYData.append( double( it.value().toDouble() ) );
mPlotCurves.append( new QgsIdentifyPlotCurve( attributes, mPlot, layer->name() ) );
}
mPlotCurve->setData( mPlotCurveXData, mPlotCurveYData );

mPlot->setAxisMaxMinor( QwtPlot::xBottom, 0 );
//mPlot->setAxisScale( QwtPlot::xBottom, 1, mPlotCurve->dataSize());
//mPlot->setAxisScale( QwtPlot::yLeft, ymin, ymax );

mPlot->replot();
mPlot->setVisible( mPlotCurveXData.count() > 0 );
#endif
}

@@ -1031,8 +1063,9 @@ void QgsIdentifyResultsDialog::clear()

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
mPlot->setVisible( false );
mPlotCurveXData.clear();
mPlotCurveYData.clear();
foreach ( QgsIdentifyPlotCurve *curve, mPlotCurves )
delete curve;
mPlotCurves.clear();
#endif

// keep it visible but disabled, it can switch from disabled/enabled
@@ -94,6 +94,22 @@ class APP_EXPORT QgsIdentifyResultsWebViewItem: public QObject, public QTreeWidg
QgsIdentifyResultsWebView *mWebView;
};

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
class APP_EXPORT QgsIdentifyPlotCurve
{
public:

QgsIdentifyPlotCurve() { mPlotCurve = 0; }
QgsIdentifyPlotCurve( const QMap<QString, QString> &attributes,
QwtPlot* plot, const QString &title = QString(), QColor color = QColor() ) ;
~QgsIdentifyPlotCurve();

private:
QwtPlotCurve* mPlotCurve;
QVector<double> mPlotCurveXData, mPlotCurveYData;
};
#endif

class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdentifyResultsBase
{
Q_OBJECT
@@ -230,8 +246,9 @@ class APP_EXPORT QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdenti
QDockWidget *mDock;

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
QwtPlotCurve* mPlotCurve;
QVector<double> mPlotCurveXData, mPlotCurveYData;
/* QwtPlotCurve* mPlotCurve; */
/* QVector<double> mPlotCurveXData, mPlotCurveYData; */
QVector<QgsIdentifyPlotCurve *> mPlotCurves;
#endif
};

@@ -309,26 +309,33 @@ QgsStringMap QgsVectorRandomColorRampV2::properties() const
return map;
}

void QgsVectorRandomColorRampV2::updateColors()
QList<QColor> QgsVectorRandomColorRampV2::randomColors( int count,
int hueMax, int hueMin, int satMax, int satMin, int valMax, int valMin )
{
int h, s, v;
QList<QColor> colors;

mColors.clear();
//start hue at random angle
double currentHueAngle = 360.0 * ( double )rand() / RAND_MAX;

for ( int i = 0; i < mCount; i++ )
for ( int i = 0; i < count; i++ )
{
//increment hue by golden ratio (approx 137.507 degrees)
//as this minimises hue nearness as count increases
//see http://basecase.org/env/on-rainbows for more details
currentHueAngle += 137.50776;
//scale hue to between mHueMax and mHueMin
h = ( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( mHueMax - mHueMin ) + mHueMin;
s = ( rand() % ( mSatMax - mSatMin + 1 ) ) + mSatMin;
v = ( rand() % ( mValMax - mValMin + 1 ) ) + mValMin;
mColors.append( QColor::fromHsv( h, s, v ) );
//scale hue to between hueMax and hueMin
h = ( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( hueMax - hueMin ) + hueMin;
s = ( rand() % ( satMax - satMin + 1 ) ) + satMin;
v = ( rand() % ( valMax - valMin + 1 ) ) + valMin;
colors.append( QColor::fromHsv( h, s, v ) );
}
return colors;
}

void QgsVectorRandomColorRampV2::updateColors()
{
mColors = QgsVectorRandomColorRampV2::randomColors( mCount, mHueMax, mHueMin, mSatMax, mSatMin, mValMax, mValMin );
}

/////////////
@@ -131,6 +131,12 @@ class CORE_EXPORT QgsVectorRandomColorRampV2 : public QgsVectorColorRampV2

virtual QgsStringMap properties() const;

/** get a list of random colors
* @note added in 2.4 */
static QList<QColor> randomColors( int count,
int hueMax = DEFAULT_RANDOM_HUE_MAX, int hueMin = DEFAULT_RANDOM_HUE_MIN,
int satMax = DEFAULT_RANDOM_SAT_MAX, int satMin = DEFAULT_RANDOM_SAT_MIN,
int valMax = DEFAULT_RANDOM_VAL_MAX, int valMin = DEFAULT_RANDOM_VAL_MIN );
void updateColors();

int count() const { return mCount; }

0 comments on commit c80d840

Please sign in to comment.