--- /dev/null
+#include "chartmodel2qwtseriesdata.h"
+
+ChartModel2QwtSeriesData::ChartModel2QwtSeriesData(ChartModel *model, int column)
+ : m_model(model), m_column(column)
+{
+ updateBoundingRect();
+}
+
+void ChartModel2QwtSeriesData::updateBoundingRect()
+{
+ int rows = m_model->rowCount();
+ if (rows > 0)
+ {
+ m_boundingRect.setLeft(m_model->data(m_model->index(0, 0)).toDouble());
+ m_boundingRect.setTop(m_model->data(m_model->index(0, m_column)).toDouble());
+ m_boundingRect.setRight(m_model->data(m_model->index(rows - 1, 0)).toDouble());
+ qreal maxCost = -1E9;
+ for (int row = 0; row < rows; ++row)
+ {
+ qreal cost = m_model->data(m_model->index(row, m_column)).toDouble();
+ if (cost > maxCost)
+ {
+ maxCost = cost;
+ }
+ }
+ m_boundingRect.setBottom(maxCost);
+ }
+}
+
+QPointF ChartModel2QwtSeriesData::sample(size_t i) const
+{
+ int row = (int)i;
+ qreal timeStamp = m_model->data(m_model->index(row, 0)).toDouble();
+ qreal cost = m_model->data(m_model->index(row, m_column)).toDouble();
+ return QPointF(timeStamp, cost);
+}
+
+QRectF ChartModel2QwtSeriesData::boundingRect() const
+{
+ return m_boundingRect;
+}
#include <QVBoxLayout>
-#ifdef KChart_FOUND
+#if defined(KChart_FOUND)
#include <KChartChart>
#include <KChartPlotter>
#include <KChartGridAttributes>
#include <KChartHeaderFooter>
#include <KChartLegend>
+#elif defined(QWT_FOUND)
+#include <qwt_plot.h>
+#include <qwt_plot_curve.h>
+#include <qwt_plot_grid.h>
+#include <qwt_symbol.h>
+#include <qwt_legend.h>
#endif
#ifdef NO_K_LIB
ChartWidget::ChartWidget(QWidget* parent)
: QWidget(parent)
-#ifdef KChart_FOUND
+#if defined(KChart_FOUND)
, m_chart(new Chart(this))
+#elif defined(QWT_FOUND)
+ , m_model(nullptr)
+ , m_plot(new QwtPlot(this))
+#endif
+#ifdef SHOW_TABLES
+ , m_tableViewTotal(new QTableView(this))
+ , m_tableViewNoTotal(new QTableView(this))
#endif
{
auto layout = new QVBoxLayout(this);
-#ifdef KChart_FOUND
+#if defined(KChart_FOUND)
layout->addWidget(m_chart);
+#elif defined(QWT_FOUND)
+ layout->addWidget(m_plot);
+#endif
+#ifdef SHOW_TABLES
+ auto hLayout = new QHBoxLayout();
+ hLayout->addWidget(m_tableViewTotal);
+ hLayout->addWidget(m_tableViewNoTotal);
+ layout->addLayout(hLayout);
+ layout->setStretch(0, 100);
+ layout->setStretch(1, 100);
#endif
setLayout(layout);
break;
}
-#ifdef KChart_FOUND
+#if defined(KChart_FOUND) || defined(SHOW_TABLES)
+ ChartProxy *totalProxy, *proxy;
+#endif
+#if defined(KChart_FOUND)
{
auto totalPlotter = new Plotter(this);
totalPlotter->setAntiAliasing(true);
- auto totalProxy = new ChartProxy(true, this);
+ totalProxy = new ChartProxy(true, this);
totalProxy->setSourceModel(model);
totalPlotter->setModel(totalProxy);
totalPlotter->setType(Plotter::Stacked);
plotter->setAntiAliasing(true);
plotter->setType(Plotter::Stacked);
- auto proxy = new ChartProxy(false, this);
+ proxy = new ChartProxy(false, this);
proxy->setSourceModel(model);
plotter->setModel(proxy);
coordinatePlane->addDiagram(plotter);
}
+#elif defined(QWT_FOUND)
+ connect(model, SIGNAL(modelReset()), this, SLOT(modelReset()));
+ m_model = model;
+
+//!! m_plot->setTitle( "Plot Demo" );
+ m_plot->setCanvasBackground(Qt::white);
+ m_plot->enableAxis(QwtPlot::yRight);
+ m_plot->enableAxis(QwtPlot::yLeft, false);
+// m_plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
+// m_plot->insertLegend( new QwtLegend() );
+
+ QwtPlotGrid *grid = new QwtPlotGrid();
+ grid->attach(m_plot);
+
+#ifdef SHOW_TABLES
+ totalProxy = new ChartProxy(true, this);
+ totalProxy->setSourceModel(model);
+
+ proxy = new ChartProxy(false, this);
+ proxy->setSourceModel(model);
+#endif // SHOW_TABLES
+#endif // QWT_FOUND
+#ifdef SHOW_TABLES
+ m_tableViewTotal->setModel(totalProxy);
+ m_tableViewNoTotal->setModel(proxy);
#endif
}
return {400, 50};
}
+#ifdef QWT_FOUND
+void ChartWidget::modelReset()
+{
+ updateQwtChart();
+}
+
+void ChartWidget::updateQwtChart()
+{
+ int columns = m_model->columnCount();
+// int rows = m_model->rowCount();
+// qDebug() << "rows: " << rows << "; columns: " << columns;
+/*
+ QwtPlotCurve *curve = new QwtPlotCurve();
+ curve->setTitle( "Some Points" );
+ QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
+ QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
+ curve->setSymbol( symbol );
+ QPolygonF points;
+ points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
+ << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
+ << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
+ curve->setSamples( points );
+ curve->attach( m_plot );
+*/
+ m_plot->detachItems();
+
+ m_plot->setAxisTitle(QwtPlot::xBottom, m_model->headerData(0).toString());
+ m_plot->setAxisTitle(QwtPlot::yRight, m_model->headerData(1).toString());
+
+ for (int column = 1; column < columns ; column += 2)
+ {
+ auto curve = new QwtPlotCurve();
+ curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
+ curve->setYAxis(QwtPlot::yRight);
+
+ curve->setPen(m_model->getColumnDataSetPen(column));
+ curve->setBrush(m_model->getColumnDataSetBrush(column));
+
+ auto adapter = new ChartModel2QwtSeriesData(m_model, column);
+ curve->setSamples(adapter);
+/*
+ QPolygonF points;
+ for (int row = 0; row < rows; ++row)
+ {
+ QModelIndex index = m_model->index(row, 0); // time
+ qreal timeStamp = m_model->data(index).toDouble();
+ qreal cost = m_model->data(m_model->index(row, column)).toDouble();
+ points << QPointF(timeStamp, cost);
+ }
+ curve->setSamples(points);
+*/
+ curve->attach(m_plot);
+ }
+
+ m_plot->replot();
+}
+#endif
+
#include "chartwidget.moc"
#CONFIG *= NO_K_LIB
#DEFINES *= NO_K_LIB
-QWT_CHART {
- # QMAKEFEATURES and QWT_ROOT environment variables must be set (e.g. to d:\Qwt\Qwt-6.2).
- # This is the directory where qwt.prf and qwt*.pri files reside.
- CONFIG *= USE_CHART QWT
- DEFINES *= USE_CHART
-}
-
SOURCES += \
analyze/accumulatedtracedata.cpp \
analyze/gui/gui.cpp \
analyze/gui/util.h \
util/config.h
-!NO_K_LIB {
- QT += KCoreAddons # for KFormat
- QT += KI18n
-
- QT += KIOCore
- QT += KIOFileWidgets
-
- QT += KConfigWidgets
- QT += KIOWidgets
+QWT_CHART {
+ # QMAKEFEATURES and QWT_ROOT environment variables must be set (e.g. to d:\Qwt\Qwt-6.2).
+ # This is the directory where qwt.prf and qwt*.pri files reside.
+ CONFIG *= USE_CHART QWT
+ DEFINES *= USE_CHART QWT
- QT += KItemModels
+ SOURCES += \
+ analyze/gui/chartmodel2qwtseriesdata.cpp
- QT += ThreadWeaver
+ HEADERS += \
+ analyze/gui/chartmodel2qwtseriesdata.h
}
USE_CHART {
SOURCES += \
analyze/gui/chartmodel.cpp \
-# analyze/gui/chartproxy.cpp \
+ analyze/gui/chartproxy.cpp \
analyze/gui/chartwidget.cpp \
analyze/gui/histogrammodel.cpp \
# analyze/gui/histogramwidget.cpp
HEADERS += \
analyze/gui/chartmodel.h \
-# analyze/gui/chartproxy.h \
+ analyze/gui/chartproxy.h \
analyze/gui/chartwidget.h \
analyze/gui/histogrammodel.h \
# analyze/gui/histogramwidget.h
}
+!NO_K_LIB {
+ QT += KCoreAddons # for KFormat
+ QT += KI18n
+
+ QT += KIOCore
+ QT += KIOFileWidgets
+
+ QT += KConfigWidgets
+ QT += KIOWidgets
+
+ QT += KItemModels
+
+ QT += ThreadWeaver
+}
+
!NO_K_CHART {
QT += KChart
SOURCES += \
-# analyze/gui/chartmodel.cpp \
- analyze/gui/chartproxy.cpp \
-# analyze/gui/chartwidget.cpp \
-# analyze/gui/histogrammodel.cpp \
analyze/gui/histogramwidget.cpp
HEADERS += \
-# analyze/gui/chartmodel.h \
- analyze/gui/chartproxy.h \
-# analyze/gui/chartwidget.h \
-# analyze/gui/histogrammodel.h \
analyze/gui/histogramwidget.h
FORMS += \