PDA

View Full Version : Promote to ..



fantom
10th March 2011, 17:36
Hallo all,

I manage to adapt the tvplot example in my app. It works ok and i can see the plot. My issue now is to see the plot included in an already implemented dialog box. I read this has to be done via promote widget but when i promote to my Plot class i get many errors. Please i need urgently some help :(.

Find below the code of the cpp and h file of the plot

cpp


#include <stdlib.h>
#include <qpen.h>
#include <qwt_plot_layout.h>
#include <qwt_legend.h>
#include <qwt_legend_item.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_histogram.h>
#include <qwt_column_symbol.h>
#include <qwt_series_data.h>
#include "plot.h"

class Histogram: public QwtPlotHistogram
{
public:
Histogram(const QString &, const QColor &);

void setColor(const QColor &);
void setValues(uint numValues, char *);
};

Histogram::Histogram(const QString &title, const QColor &symbolColor):
QwtPlotHistogram(title)
{
setStyle(QwtPlotHistogram::Columns);

setColor(symbolColor);
}

void Histogram::setColor(const QColor &symbolColor)
{
QColor color = symbolColor;
color.setAlpha(180);

setPen(QPen(Qt::black));
setBrush(QBrush(color));

QwtColumnSymbol *symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
symbol->setFrameStyle(QwtColumnSymbol::Raised);
symbol->setLineWidth(2);
symbol->setPalette(QPalette(color));
setSymbol(symbol);
}

void Histogram::setValues(uint numValues, char *values)
{
QVector<QwtIntervalSample> samples(numValues);
for ( uint i = 0; i < numValues; i++ )
{
QwtInterval interval(double(i), i + 1.0);
interval.setBorderFlags(QwtInterval::ExcludeMaximu m);

samples[i] = QwtIntervalSample(values[i], interval);
}

setData(new QwtIntervalSeriesData(samples));
}

Plot::Plot(QWidget *parent):
QwtPlot(parent)
{
setTitle("Patient Adherence");

setCanvasBackground(QColor(Qt::gray));
plotLayout()->setAlignCanvasToScales(true);

setAxisTitle(QwtPlot::yLeft, "Probability(%)");
setAxisTitle(QwtPlot::xBottom, "Adherence");

QwtLegend *legend = new QwtLegend;
legend->setItemMode(QwtLegend::CheckableItem);
insertLegend(legend, QwtPlot::RightLegend);

populate();

// connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
// SLOT(showItem(QwtPlotItem *, bool)));

replot(); // creating the legend items

QwtPlotItemList items = itemList(QwtPlotItem::Rtti_PlotHistogram);
for ( int i = 0; i < items.size(); i++ )
{
if ( i == 0 )
{
QwtLegendItem *legendItem = (QwtLegendItem *)legend->find(items[i]);
if ( legendItem )
legendItem->setChecked(true);
items[i]->setVisible(true);
}
else
items[i]->setVisible(false);
}

setAutoReplot(true);
}

void Plot::populate()
{
QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableX(false);
grid->enableY(true);
grid->enableXMin(false);
grid->enableYMin(false);
grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
grid->attach(this);

char patientValues[] = { 'a', 'd', 'na'};


Histogram *histogramClient = new Histogram("Blue Pills", Qt::red);
histogramClient->setValues(
sizeof(clientValues) / sizeof(char), clientValues);
histogramClient->attach(this);

}

void Plot::showItem(QwtPlotItem *item, bool on)
{
item->setVisible(on);
}


.h


#pragma once

#include <qwt_plot.h>

class Plot: public QObject, public QwtPlot
{
Q_OBJECT

public:
Plot(QWidget * = NULL);

private:
void populate();

private Q_SLOTS:
void showItem(QwtPlotItem *, bool on);
};



Thank you in advance!

Uwe
11th March 2011, 10:02
I read this has to be done via promote widget but when i promote to my Plot class i get many errors.

Do you really expect to get an answer without any further information about the errors ?

Uwe