refactoring (preparing to enable use of QWT instead of KChart)
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Fri, 2 Mar 2018 17:20:36 +0000 (20:20 +0300)
committerAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Fri, 2 Mar 2018 17:20:36 +0000 (20:20 +0300)
src/analyze/gui/chartmodel.cpp
src/analyze/gui/chartwidget.cpp
src/analyze/gui/chartwidget.h
src/analyze/gui/histogrammodel.cpp
src/analyze/gui/mainwindow.cpp
src/heaptrack_gui.pro

index 8778819a32447cb1440ac0c8cb00a9fe1d12b674..61456f9c015fe1e4fac10d1815e6715f16e1fba6 100644 (file)
 
 #include "chartmodel.h"
 
+#include "gui_config.h"
+
+#ifdef KChart_FOUND
 #include <KChartGlobal>
 #include <KChartLineAttributes>
+#endif
 #ifdef NO_K_LIB
 #include "noklib.h"
 #else
@@ -58,12 +62,13 @@ QVariant ChartModel::headerData(int section, Qt::Orientation orientation, int ro
 {
     Q_ASSERT(orientation == Qt::Horizontal || section < columnCount());
     if (orientation == Qt::Horizontal) {
+#ifdef KChart_FOUND
         if (role == KChart::DatasetPenRole) {
             return QVariant::fromValue(m_columnDataSetPens.at(section));
         } else if (role == KChart::DatasetBrushRole) {
             return QVariant::fromValue(m_columnDataSetBrushes.at(section));
         }
-
+#endif
         if (role == Qt::DisplayRole || role == Qt::ToolTipRole) {
             if (section == 0) {
                 return i18n("Elapsed Time");
@@ -94,6 +99,7 @@ QVariant ChartModel::data(const QModelIndex& index, int role) const
     Q_ASSERT(index.column() >= 0 && index.column() < columnCount(index.parent()));
     Q_ASSERT(!index.parent().isValid());
 
+#ifdef KChart_FOUND
     if (role == KChart::LineAttributesRole) {
         KChart::LineAttributes attributes;
         attributes.setDisplayArea(true);
@@ -110,6 +116,7 @@ QVariant ChartModel::data(const QModelIndex& index, int role) const
     } else if (role == KChart::DatasetBrushRole) {
         return QVariant::fromValue(m_columnDataSetBrushes.at(index.column()));
     }
+#endif
 
     if (role != Qt::DisplayRole && role != Qt::ToolTipRole) {
         return {};
index 8dc2b709e3f8279b15a414d873671f28ea56bde4..f61b8ab501aa28af7164a1ac7dcf4a032486c1ba 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <QVBoxLayout>
 
+#ifdef KChart_FOUND
 #include <KChartChart>
 #include <KChartPlotter>
 
@@ -30,6 +31,7 @@
 #include <KChartGridAttributes>
 #include <KChartHeaderFooter>
 #include <KChartLegend>
+#endif
 
 #ifdef NO_K_LIB
 #include "noklib.h"
@@ -43,6 +45,7 @@
 #include "chartproxy.h"
 #include "util.h"
 
+#ifdef KChart_FOUND
 using namespace KChart;
 
 namespace {
@@ -77,25 +80,33 @@ public:
     }
 };
 }
+#endif
 
 ChartWidget::ChartWidget(QWidget* parent)
     : QWidget(parent)
+#ifdef KChart_FOUND
     , m_chart(new Chart(this))
+#endif
 {
     auto layout = new QVBoxLayout(this);
+#ifdef KChart_FOUND
     layout->addWidget(m_chart);
+#endif
     setLayout(layout);
 
+#ifdef KChart_FOUND
     auto* coordinatePlane = dynamic_cast<CartesianCoordinatePlane*>(m_chart->coordinatePlane());
     Q_ASSERT(coordinatePlane);
     coordinatePlane->setRubberBandZoomingEnabled(true);
     coordinatePlane->setAutoAdjustGridToZoom(true);
+#endif
 }
 
 ChartWidget::~ChartWidget() = default;
 
 void ChartWidget::setModel(ChartModel* model, bool minimalMode)
 {
+#ifdef KChart_FOUND
     auto* coordinatePlane = dynamic_cast<CartesianCoordinatePlane*>(m_chart->coordinatePlane());
     Q_ASSERT(coordinatePlane);
     foreach (auto diagram, coordinatePlane->diagrams()) {
@@ -108,6 +119,7 @@ void ChartWidget::setModel(ChartModel* model, bool minimalMode)
         grid.setSubGridVisible(false);
         coordinatePlane->setGlobalGridAttributes(grid);
     }
+#endif
 
     switch (model->type()) {
     case ChartModel::Consumed:
@@ -132,6 +144,7 @@ void ChartWidget::setModel(ChartModel* model, bool minimalMode)
         break;
     }
 
+#ifdef KChart_FOUND
     {
         auto totalPlotter = new Plotter(this);
         totalPlotter->setAntiAliasing(true);
@@ -190,6 +203,7 @@ void ChartWidget::setModel(ChartModel* model, bool minimalMode)
         plotter->setModel(proxy);
         coordinatePlane->addDiagram(plotter);
     }
+#endif
 }
 
 QSize ChartWidget::sizeHint() const
index dcf64eacc58530233a66de68ab77e98500728501..bb8e6d2c8d6ac352116bed7318aa250d77b7f142 100644 (file)
 #ifndef CHARTWIDGET_H
 #define CHARTWIDGET_H
 
+#include "gui_config.h"
+
 #include <QWidget>
 
 class ChartModel;
 
+#ifdef KChart_FOUND
 namespace KChart {
 class Chart;
 }
+#endif
 
 class QAbstractItemModel;
 
@@ -41,7 +45,9 @@ public:
     QSize sizeHint() const override;
 
 private:
+#ifdef KChart_FOUND
     KChart::Chart* m_chart;
+#endif
 };
 
 #endif // CHARTWIDGET_H
index 5cdd7a58b48262b56affeeabe1953ac0ffa1b69d..0944ab55caa45b4645ae9508d20d79f1698c59d7 100644 (file)
 
 #include "histogrammodel.h"
 
+#include "gui_config.h"
+
+#ifdef KChart_FOUND
 #include <KChartGlobal>
+#endif
 
 #ifdef NO_K_LIB
 #include "noklib.h"
@@ -61,11 +65,13 @@ QVariant HistogramModel::data(const QModelIndex& index, int role) const
     if (!hasIndex(index.row(), index.column(), index.parent())) {
         return {};
     }
+#ifdef KChart_FOUND
     if (role == KChart::DatasetBrushRole) {
         return QVariant::fromValue(QBrush(colorForColumn(index.column(), columnCount())));
     } else if (role == KChart::DatasetPenRole) {
         return QVariant::fromValue(QPen(Qt::black));
     }
+#endif
 
     if (role != Qt::DisplayRole && role != Qt::ToolTipRole) {
         return {};
index 5ecef666f6fc0b67cf694726109da227e3bf80e9..1a9dd00edd2e21c8484b93de337f165e4a944157 100644 (file)
 
 #include "gui_config.h"
 
-#if KChart_FOUND
+#if USE_CHART
 #include "chartmodel.h"
-#include "chartproxy.h"
 #include "chartwidget.h"
 #include "histogrammodel.h"
+#endif
+#if KChart_FOUND
+//!!#include "chartmodel.h"
+#include "chartproxy.h"
+//!!#include "chartwidget.h"
+//!!#include "histogrammodel.h"
 #include "histogramwidget.h"
 #endif
 
@@ -113,7 +118,7 @@ void setupTopView(TreeModel* source, QTreeView* view, TopProxy::Type type)
     addContextMenu(view, TreeModel::LocationRole);
 }
 
-#if KChart_FOUND
+#if USE_CHART
 void addChartTab(QTabWidget* tabWidget, const QString& title, ChartModel::Type type, const Parser* parser,
                  void (Parser::*dataReady)(const ChartData&), MainWindow* window)
 {
@@ -436,7 +441,7 @@ MainWindow::MainWindow(QWidget* parent)
     });
     m_ui->messages->hide();
 
-#if KChart_FOUND
+#if USE_CHART
     addChartTab(m_ui->tabWidget, i18n("Consumed"), ChartModel::Consumed, m_parser, &Parser::consumedChartDataAvailable,
                 this);
 
@@ -458,6 +463,7 @@ MainWindow::MainWindow(QWidget* parent)
                         &Parser::temporaryChartDataAvailable, this);
         }
 
+#ifdef KChart_FOUND
         auto sizesTab = new HistogramWidget(this);
         m_ui->tabWidget->addTab(sizesTab, i18n("Sizes"));
         m_ui->tabWidget->setTabEnabled(m_ui->tabWidget->indexOf(sizesTab), false);
@@ -469,6 +475,7 @@ MainWindow::MainWindow(QWidget* parent)
                 sizeHistogramModel->resetData(data);
                 m_ui->tabWidget->setTabEnabled(m_ui->tabWidget->indexOf(sizesTab), true);
                 });
+#endif
     }
 #endif
 
index e891fbf8ba3fa330ca4de26bc80328a9c8ebd132..fd024f52c770285b93f220937f0297ab7a0c61a6 100644 (file)
@@ -10,7 +10,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
 INCLUDEPATH += $$PWD/analyze/gui
 
 win32 {
-    CONFIG += NO_K_LIB NO_K_CHART
+    CONFIG += NO_K_LIB NO_K_CHART QWT_CHART
     DEFINES += NO_K_LIB NO_K_CHART
     INCLUDEPATH += $$(BOOST_LIB)
     LIBS += -L$$(BOOST_LIB)/stage/lib
@@ -19,6 +19,7 @@ win32 {
 unix {
 #    QMAKE_CXXFLAGS += -std=c++0x
 #    QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter # disable 'unused parameter' warning
+    DEFINES *= USE_CHART
     LIBS += -lboost_program_options -lboost_iostreams -lpthread
 }
 
@@ -26,6 +27,13 @@ unix {
 #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 \
@@ -76,21 +84,37 @@ HEADERS += \
     QT += ThreadWeaver
 }
 
-!NO_K_CHART {
-    QT += KChart
-
+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
+#        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_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 += \