
Originally Posted by
Uwe
Without knowing your code I can't say anything useful.
The code is long and complex but I try to minimize it regarding background, grids and plot only. Here are the simplified source codes:
Starting with the class that initialize the Plot Panel
//includes here
//namespace here
MethodResultScreen
::MethodResultScreen(PMT
::ItfResultMngmt::IResultReader::SPtr resultReader,
QWidget *parent
) : BasicScreen(parent),
m_journalModel(0),
m_journalView(0),
m_plotPanel(0),
m_journalTab(0),
m_chartTab(0),
m_filterControl(0),
m_backButton(0),
m_printButton(0),
m_deleteButton(0),
m_exportButton(0),
m_advancedFilterSettingsScreen(0),
m_filterSelection(DEFAULT_FILTER),
m_isNavigationFromAdvanceFilter(false)
{
Q_ASSERT(resultReader);
//intialize journal view here
// create chart view
m_plotPanel = new PMT::GuiBase::PlotPanel(DISCRETE_PLOT, REDUCED_RULER, this);
m_plotPanel->enableLimitText(true);
m_plotDataAdapter.setModel(m_chartModel);
PlotCurve *curve = new PlotCurve(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
curve->setAxes(X_AXIS, Y_AXIS);
curve->attach(m_plotPanel->plot());
//Upcast needed. The QwtSeriesStore<QPointF>::setData needs the parameter of QwtSeriesData<QPointF> *param
//PlotDataAdapter inherits from QwtSeriesData
QwtSeriesData<QPointF> *parentData = &m_plotDataAdapter;
curve->setData(parentData);
// intialize tabs and buttons here
connect(m_plotPanel, SIGNAL(controlValueSelected(int, bool)), SLOT(onControlValueSelected(int)));
}
MethodResultScreen::~MethodResultScreen()
{
}
void MethodResultScreen
::showEvent(QShowEvent *showEvent
) {
updateView();
BasicScreen::showEvent(showEvent);
}
void MethodResultScreen::updateView(void)
{
Q_ASSERT(m_journalModel);
Q_ASSERT(m_filterControl);
//some implementations here regarding filter
m_journalModel->reload();
configurePlot();
}
void MethodResultScreen::configurePlot(void)
{
Q_ASSERT(m_plotPanel);
qDebug("Start configuring plot"); // 140515
time.restart();
PlotControlLimitSet controlLimitSet = PlotControlLimitSet();
if( m_journalModel->chartRows().size() > 0 )
{
QModelIndex valueIndex
= m_chartModel
->index
( m_journalModel
->chartRows
().
at(0),
0 );
if( valueIndex.isValid() && m_journalModel->isMethodVersionCurrent( valueIndex ) )
{
controlLimitSet = m_controlLimitSet;
}
}
// calculate y-axis scale
ChartScaleCalculator chartScaleCalculator;
chartScaleCalculator.calculate(&m_plotDataAdapter, &controlLimitSet);
//TODO:add minimal border gap on maximum.
double minimum = chartScaleCalculator.minimum();
double maximum = chartScaleCalculator.maximum();
m_plotPanel->setControlLimitSet(controlLimitSet);
m_plotPanel->plot()->setAxisScale(Y_AXIS, minimum, maximum);
int sampleCount = m_plotDataAdapter.size();
// calculate x-axis scale
QwtScaleDiv scaleDiv
= DiscreteScaleDivFactory
::create(sampleCount
);
m_plotPanel->plot()->setAxisScaleDiv(X_AXIS, scaleDiv);
// add control values
//initialize controlValues here
m_plotPanel->setControlValues(controlValues, true);
if (controlValues.size() > 0)
{
m_plotPanel->selectControlValue(controlValues.last());
}
// set unit label
m_plotPanel->setAxisLabel(Y_AXIS, m_resultUnit);
// trigger axis update
m_plotPanel->plot()->updateAxes();
qDebug("Finished configuring plot in: %d ms", time.elapsed()); // 140515
}
//includes here
//namespace here
MethodResultScreen::MethodResultScreen(PMT::ItfResultMngmt::IResultReader::SPtr resultReader, QWidget *parent) :
BasicScreen(parent),
m_journalModel(0),
m_journalView(0),
m_plotPanel(0),
m_journalTab(0),
m_chartTab(0),
m_filterControl(0),
m_backButton(0),
m_printButton(0),
m_deleteButton(0),
m_exportButton(0),
m_advancedFilterSettingsScreen(0),
m_filterSelection(DEFAULT_FILTER),
m_isNavigationFromAdvanceFilter(false)
{
Q_ASSERT(resultReader);
//intialize journal view here
// create chart view
m_plotPanel = new PMT::GuiBase::PlotPanel(DISCRETE_PLOT, REDUCED_RULER, this);
m_plotPanel->enableLimitText(true);
m_plotDataAdapter.setModel(m_chartModel);
PlotCurve *curve = new PlotCurve(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
curve->setAxes(X_AXIS, Y_AXIS);
curve->attach(m_plotPanel->plot());
//Upcast needed. The QwtSeriesStore<QPointF>::setData needs the parameter of QwtSeriesData<QPointF> *param
//PlotDataAdapter inherits from QwtSeriesData
QwtSeriesData<QPointF> *parentData = &m_plotDataAdapter;
curve->setData(parentData);
// intialize tabs and buttons here
connect(m_plotPanel, SIGNAL(controlValueSelected(int, bool)), SLOT(onControlValueSelected(int)));
}
MethodResultScreen::~MethodResultScreen()
{
}
void MethodResultScreen::showEvent(QShowEvent *showEvent)
{
updateView();
BasicScreen::showEvent(showEvent);
}
void MethodResultScreen::updateView(void)
{
Q_ASSERT(m_journalModel);
Q_ASSERT(m_filterControl);
//some implementations here regarding filter
m_journalModel->reload();
configurePlot();
}
void MethodResultScreen::configurePlot(void)
{
Q_ASSERT(m_plotPanel);
qDebug("Start configuring plot"); // 140515
static QTime time;
time.restart();
PlotControlLimitSet controlLimitSet = PlotControlLimitSet();
if( m_journalModel->chartRows().size() > 0 )
{
QModelIndex valueIndex = m_chartModel->index( m_journalModel->chartRows().at(0), 0 );
if( valueIndex.isValid() && m_journalModel->isMethodVersionCurrent( valueIndex ) )
{
controlLimitSet = m_controlLimitSet;
}
}
// calculate y-axis scale
ChartScaleCalculator chartScaleCalculator;
chartScaleCalculator.calculate(&m_plotDataAdapter, &controlLimitSet);
//TODO:add minimal border gap on maximum.
double minimum = chartScaleCalculator.minimum();
double maximum = chartScaleCalculator.maximum();
m_plotPanel->setControlLimitSet(controlLimitSet);
m_plotPanel->plot()->setAxisScale(Y_AXIS, minimum, maximum);
int sampleCount = m_plotDataAdapter.size();
// calculate x-axis scale
QwtScaleDiv scaleDiv = DiscreteScaleDivFactory::create(sampleCount);
m_plotPanel->plot()->setAxisScaleDiv(X_AXIS, scaleDiv);
// add control values
//initialize controlValues here
m_plotPanel->setControlValues(controlValues, true);
if (controlValues.size() > 0)
{
m_plotPanel->selectControlValue(controlValues.last());
}
// set unit label
m_plotPanel->setAxisLabel(Y_AXIS, m_resultUnit);
// trigger axis update
m_plotPanel->plot()->updateAxes();
qDebug("Finished configuring plot in: %d ms", time.elapsed()); // 140515
}
To copy to clipboard, switch view to plain text mode
And simplified PlotPanel class
//some includes here
//namespace
const qreal PlotPanel::TEXT_OPACITY = 0.4;
PlotPanel
::PlotPanel(PlotStyle plotStyle, RulerType rulerType,
QWidget *parent
) : m_plot(0),
m_plotBackground(0),
m_plotGrid(0),
m_plotRulerPanel(0),
m_leftButton(0),
m_rightButton(0),
m_showLeftLabel(true),
m_showRightLabel(false),
m_showBottomLabel(true),
m_predResultUncertainty(0.0)
{
setFixedSize(StyleInfo::PLOT_PANEL_WIDTH, StyleInfo::PLOT_PANEL_HEIGHT);
m_plot = new Plot(plotStyle, this);
m_plot->move(PLOT_HORIZONTAL_BORDER, PLOT_TOP_BORDER);
m_plotBackground = new PlotBackground;
m_plotBackground->attach(m_plot);
m_plotGrid = new PlotGrid;
m_plotGrid->attach(m_plot);
}
PlotPanel::~PlotPanel()
{
}
void PlotPanel::setControlLimitSet(const PlotControlLimitSet &controlLimitSet)
{
Q_ASSERT(m_plotGrid);
m_plotGrid->setControlLimitSet(controlLimitSet);
}
void PlotPanel::enableLimitText(bool enable)
{
Q_ASSERT(m_plotGrid);
m_plotGrid->enableLimitText(enable);
}
void PlotPanel::setControlValues(const QList< ControlValue > &controlValues, bool chartModel)
{
m_plot->replot();
//some implementations here regarding control values and plot markers
m_plot->replot();
}
void PlotPanel::showAxis(Axis axis, bool show)
{
Q_ASSERT(m_plot);
m_plot
->showAxis
((QwtPlot::Axis)axis, show
);
switch (axis)
{
{
m_showLeftLabel = show;
break;
}
{
m_showRightLabel = show;
break;
}
{
m_showBottomLabel = show;
break;
}
default:
{
break;
}
}
update();
}
{
Q_ASSERT(m_plot);
painter.setFont(StyleInfo::font(StyleInfo::FONT_SIZE_SMALL));
painter.fillRect(rect(), Qt::white);
painter.setOpacity(TEXT_OPACITY);
if (m_showLeftLabel)
{
drawLeftLabel(&painter);
}
if (m_showRightLabel)
{
drawRightLabel(&painter);
}
if (m_showBottomLabel)
{
drawBottomLabel(&painter);
}
}
//some includes here
//namespace
const qreal PlotPanel::TEXT_OPACITY = 0.4;
PlotPanel::PlotPanel(PlotStyle plotStyle, RulerType rulerType, QWidget *parent) :
QWidget(parent),
m_plot(0),
m_plotBackground(0),
m_plotGrid(0),
m_plotRulerPanel(0),
m_leftButton(0),
m_rightButton(0),
m_showLeftLabel(true),
m_showRightLabel(false),
m_showBottomLabel(true),
m_predResultUncertainty(0.0)
{
setFixedSize(StyleInfo::PLOT_PANEL_WIDTH, StyleInfo::PLOT_PANEL_HEIGHT);
m_plot = new Plot(plotStyle, this);
m_plot->move(PLOT_HORIZONTAL_BORDER, PLOT_TOP_BORDER);
m_plotBackground = new PlotBackground;
m_plotBackground->attach(m_plot);
m_plotGrid = new PlotGrid;
m_plotGrid->attach(m_plot);
}
PlotPanel::~PlotPanel()
{
}
void PlotPanel::setControlLimitSet(const PlotControlLimitSet &controlLimitSet)
{
Q_ASSERT(m_plotGrid);
m_plotGrid->setControlLimitSet(controlLimitSet);
}
void PlotPanel::enableLimitText(bool enable)
{
Q_ASSERT(m_plotGrid);
m_plotGrid->enableLimitText(enable);
}
void PlotPanel::setControlValues(const QList< ControlValue > &controlValues, bool chartModel)
{
m_plot->replot();
//some implementations here regarding control values and plot markers
m_plot->replot();
}
void PlotPanel::showAxis(Axis axis, bool show)
{
Q_ASSERT(m_plot);
m_plot->showAxis((QwtPlot::Axis)axis, show);
switch (axis)
{
case QwtPlot::yLeft :
{
m_showLeftLabel = show;
break;
}
case QwtPlot::yRight :
{
m_showRightLabel = show;
break;
}
case QwtPlot::xBottom :
{
m_showBottomLabel = show;
break;
}
default:
{
break;
}
}
update();
}
void PlotPanel::paintEvent(QPaintEvent *)
{
Q_ASSERT(m_plot);
QPainter painter(this);
painter.setFont(StyleInfo::font(StyleInfo::FONT_SIZE_SMALL));
painter.fillRect(rect(), Qt::white);
painter.setOpacity(TEXT_OPACITY);
if (m_showLeftLabel)
{
drawLeftLabel(&painter);
}
if (m_showRightLabel)
{
drawRightLabel(&painter);
}
if (m_showBottomLabel)
{
drawBottomLabel(&painter);
}
}
To copy to clipboard, switch view to plain text mode
PlotBackground implementation is as is
//includes here
//namespace here
{
Q_ASSERT(painter);
if( !m_backgroundText.isEmpty() )
{
painter->viewport();
painter->setOpacity(StyleInfo::opacity(StyleInfo::FONT_INTENSITY_MIDDLE));
painter
->setPen
(QPen(StyleInfo
::fontBaseColor(StyleInfo
::FONT_COLOR_POSITIVE_GREY_ON_LIGHT)));
painter->setFont(StyleInfo::font(StyleInfo::FONT_SIZE_STANDARD));
painter->drawText(rect, Qt::AlignCenter, m_backgroundText);
}
else
{
PixmapDatabase::find(PixmapDatabase::PIXMAP_PLOT_BACKGROUND, &background);
painter->drawPixmap(rect, background);
}
}
void PlotBackground
::setBackgroundText(const QString &text
) {
m_backgroundText = text;
}
} // namespace GuiBase
} // namespace PMT
//includes here
//namespace here
void PlotBackground::draw(QPainter *painter, const QwtScaleMap &,
const QwtScaleMap &, const QRect &rect) const
{
Q_ASSERT(painter);
if( !m_backgroundText.isEmpty() )
{
painter->viewport();
painter->setOpacity(StyleInfo::opacity(StyleInfo::FONT_INTENSITY_MIDDLE));
painter->setPen(QPen(StyleInfo::fontBaseColor(StyleInfo::FONT_COLOR_POSITIVE_GREY_ON_LIGHT)));
painter->setFont(StyleInfo::font(StyleInfo::FONT_SIZE_STANDARD));
painter->drawText(rect, Qt::AlignCenter, m_backgroundText);
}
else
{
QPixmap background;
PixmapDatabase::find(PixmapDatabase::PIXMAP_PLOT_BACKGROUND, &background);
painter->drawPixmap(rect, background);
}
}
void PlotBackground::setBackgroundText(const QString &text)
{
m_backgroundText = text;
}
} // namespace GuiBase
} // namespace PMT
To copy to clipboard, switch view to plain text mode
And lastly the PlotGrid class
PlotGrid::PlotGrid() :
m_enableLimitText(false)
{
}
{
Q_ASSERT(painter);
painter->save();
painter->setOpacity(0.2);
painter
->setPen
(QPen(StyleInfo
::skinColor(StyleInfo
::SKIN_COLOR_PLOT_THREE)));
drawLines(painter, rect, Qt::Vertical, xMap,
painter
->setPen
(QPen(StyleInfo
::skinColor(StyleInfo
::SKIN_COLOR_PLOT_ONE)));
drawLines(painter, rect, Qt::Horizontal, yMap,
painter->setOpacity(1.0);
// paint scale backbones
painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());
painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE));
painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
painter->restore();
}
{
m_xScaleDiv = xScaleDiv;
m_yScaleDiv = yScaleDiv;
}
void PlotGrid::update(void)
{
// todo: is there a better way to force an update??
{
if (plotCanvas)
{
plotCanvas->invalidateBackingStore();
plotCanvas->update();
}
}
}
PlotGrid::PlotGrid() :
QwtPlotGrid(),
m_enableLimitText(false)
{
}
void PlotGrid::draw(QPainter *painter, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRect &rect) const
{
Q_ASSERT(painter);
painter->save();
painter->setOpacity(0.2);
painter->setPen(QPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE)));
drawLines(painter, rect, Qt::Vertical, xMap,
m_xScaleDiv.ticks(QwtScaleDiv::MajorTick));
painter->setPen(QPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE)));
drawLines(painter, rect, Qt::Horizontal, yMap,
m_yScaleDiv.ticks(QwtScaleDiv::MajorTick));
painter->setOpacity(1.0);
// paint scale backbones
painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());
painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE));
painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
painter->restore();
}
void PlotGrid::updateScaleDiv(const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv)
{
m_xScaleDiv = xScaleDiv;
m_yScaleDiv = yScaleDiv;
}
void PlotGrid::update(void)
{
// todo: is there a better way to force an update??
QwtPlot *qwtPlot = plot();
if (qwtPlot)
{
QwtPlotCanvas *plotCanvas = (QwtPlotCanvas*)qwtPlot->canvas();
if (plotCanvas)
{
plotCanvas->invalidateBackingStore();
plotCanvas->update();
}
}
}
To copy to clipboard, switch view to plain text mode
The previous implementation in PlotGrid::update() is plotCanvas->invalidatePaintCache() and it is replaced now by plotCanvas->invalidateBackingStore().
Attached is the Plot view (top is using qwt 5.2.3 and bottom where grid, background and markers are missing with 6.1.6)
Thanks and sorry if this is still not enough
Bookmarks