From d11ac5a26e2aac7b7f8e8a49e170859ccaaee68a 2012-02-01 08:47:03 From: Tero Ahola Date: 2012-02-01 08:47:03 Subject: [PATCH] Refactored the test app --- diff --git a/integrated.pri b/integrated.pri index be23145..8eb4658 100644 --- a/integrated.pri +++ b/integrated.pri @@ -4,17 +4,15 @@ integrated_build:{ LIBS += -L $$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR DESTDIR = $$CHART_BUILD_BIN_DIR CONFIG(debug, debug|release) { - LIBS += -lQtCommercialChartd - - #this is ugly hack to work around missing rpath, it simply copies lib - win32:{ - copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll - copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChartd.dll $$CHART_BUILD_BIN_DIR - copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChartd.dll - PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll - QMAKE_EXTRA_TARGETS +=copylib - } - + LIBS += -lQtCommercialChartd + #this is ugly hack to work around missing rpath, it simply copies lib + win32:{ + copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll + copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChartd.dll $$CHART_BUILD_BIN_DIR + copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChartd.dll + PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll + QMAKE_EXTRA_TARGETS +=copylib + } } else { LIBS += -lQtCommercialChart diff --git a/src/charttheme_p.h b/src/charttheme_p.h index a745106..8b6b8a3 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -66,7 +66,7 @@ class ChartTheme : public QObject Q_OBJECT public: explicit ChartTheme(QObject *parent = 0); - explicit ChartTheme(const ChartTheme &other) : d(other.d) {} + explicit ChartTheme(const ChartTheme &other, QObject *parent = 0) : QObject(parent), d(other.d) {} void operator =(const ChartTheme &other) { d = other.d; } void setTheme(int theme); diff --git a/src/pieslice.cpp b/src/pieslice.cpp index 744d026..36b0dba 100644 --- a/src/pieslice.cpp +++ b/src/pieslice.cpp @@ -44,7 +44,7 @@ QPainterPath PieSlice::shape() const return path; } -void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void PieSlice::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { painter->setRenderHint(QPainter::Antialiasing); // TODO: how to map theme settings to a pie slice? Now we diff --git a/src/qchart.cpp b/src/qchart.cpp index b78b697..f00866d 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -26,10 +26,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), m_backgroundItem(0), m_titleItem(0), - m_axisXItem(new AxisItem(AxisItem::X_AXIS,this)), + m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), m_plotDataIndex(0), m_marginSize(0), - m_chartTheme(new ChartTheme()) + m_chartTheme(new ChartTheme(this)) { // TODO: the default theme? setTheme(QChart::ChartThemeDefault); diff --git a/src/qchart.h b/src/qchart.h index a8527de..5dbcd76 100644 --- a/src/qchart.h +++ b/src/qchart.h @@ -50,7 +50,7 @@ public: //from QGraphicsItem QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; + void paint(QPainter */*painter*/, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) {} void addSeries(QChartSeries* series); //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); diff --git a/src/qchartseries.h b/src/qchartseries.h index 9cbceaa..816311b 100644 --- a/src/qchartseries.h +++ b/src/qchartseries.h @@ -34,12 +34,12 @@ public: // Pure virtual virtual QChartSeriesType type() const = 0; - virtual bool setData(QList data) { return false; } - virtual bool setData(QList data) { return false; } - virtual bool setData(QList x, QList y){ return false; } + virtual bool setData(QList /*data*/) { return false; } + virtual bool setData(QList /*data*/) { return false; } + virtual bool setData(QList /*x*/, QList /*y*/){ return false; } // Prototype for data model. TODO: remove the other setData methods and use something like this for now? - virtual bool setData(QAbstractItemModel* model) { return false; } + virtual bool setData(QAbstractItemModel* /*model*/) { return false; } }; diff --git a/src/qscatterseries.cpp b/src/qscatterseries.cpp index cc02270..d3cff7f 100644 --- a/src/qscatterseries.cpp +++ b/src/qscatterseries.cpp @@ -55,7 +55,7 @@ QRectF QScatterSeriesPrivate::boundingRect() const return QRectF(0, 0, 55, 100); } -void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { // TODO: The opacity should be user definable? //brush.setColor(QColor(255, 82, 0, 100)); diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 1c80a72..4f45923 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -25,10 +25,44 @@ MainWidget::MainWidget(QWidget *parent) : { m_chartWidget = new QChartWidget(this); + // GridLayout for the controls for configuring the chart widget + QGridLayout *grid = new QGridLayout(); + QGridLayout *mainLayout = new QGridLayout(); QPushButton *addSeriesButton = new QPushButton("Add series"); connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); + grid->addWidget(addSeriesButton, 0, 1); + initBackroundCombo(grid); + initScaleControls(grid); + initThemeCombo(grid); + QCheckBox *zoomCheckBox = new QCheckBox("Zoom enabled"); + connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); + zoomCheckBox->setChecked(true); + grid->addWidget(zoomCheckBox, grid->rowCount(), 0); + // add row with empty label to make all the other rows static + grid->addWidget(new QLabel(""), grid->rowCount(), 0); + grid->setRowStretch(grid->rowCount() - 1, 1); + mainLayout->addLayout(grid, 0, 0); + + // Init series type specific controls + initPieControls(); + mainLayout->addLayout(m_pieLayout, 2, 0); + // Scatter series specific settings +// m_scatterLayout = new QGridLayout(); +// m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); +// m_scatterLayout->setEnabled(false); +// mainLayout->addLayout(m_scatterLayout, 1, 0); + + // Add layouts and the chart widget to the main layout + mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); + setLayout(mainLayout); + + // force an update to test data + testDataChanged(0); +} - // Chart background +// Combo box for selecting the chart's background +void MainWidget::initBackroundCombo(QGridLayout *grid) +{ QComboBox *backgroundCombo = new QComboBox(this); backgroundCombo->addItem("Color"); backgroundCombo->addItem("Gradient"); @@ -36,8 +70,13 @@ MainWidget::MainWidget(QWidget *parent) : connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(backgroundChanged(int))); - // Axis - // TODO: multiple axes? + grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); + grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); +} + +// Scale related controls (auto-scale vs. manual min-max values) +void MainWidget::initScaleControls(QGridLayout *grid) +{ m_autoScaleCheck = new QCheckBox("Automatic scaling"); connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); // Allow setting also non-sense values (like -2147483648 and 2147483647) @@ -62,6 +101,22 @@ MainWidget::MainWidget(QWidget *parent) : m_yMaxSpin->setValue(10); connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); + grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); + grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); + grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); + grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); + grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); + grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); + grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); + grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); + grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); + + m_autoScaleCheck->setChecked(true); +} + +// Combo box for selecting theme +void MainWidget::initThemeCombo(QGridLayout *grid) +{ QComboBox *chartTheme = new QComboBox(); chartTheme->addItem("Default"); chartTheme->addItem("Vanilla"); @@ -70,45 +125,13 @@ MainWidget::MainWidget(QWidget *parent) : chartTheme->addItem("Unnamed1"); connect(chartTheme, SIGNAL(currentIndexChanged(int)), this, SLOT(changeChartTheme(int))); -// connect(chartTheme, SIGNAL(currentIndexChanged(int)), -// m_signalMapper, SLOT(map())); -// m_signalMapper->setMapping(chartTheme, (QChart::ChartThemeId)chartTheme->currentIndex()); -// connect(m_signalMapper, SIGNAL(mapped(QChart::ChartThemeId)), -// m_chartWidget, SLOT(setTheme(QChart::ChartThemeId))); - - QCheckBox *zoomCheckBox = new QCheckBox("Zoom enabled"); - connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); - zoomCheckBox->setChecked(true); - - QGridLayout *grid = new QGridLayout(); - QGridLayout *mainLayout = new QGridLayout(); - grid->addWidget(addSeriesButton, 0, 1); - grid->addWidget(new QLabel("Background:"), 2, 0); - grid->addWidget(backgroundCombo, 2, 1); - grid->addWidget(m_autoScaleCheck, 3, 0); - grid->addWidget(new QLabel("x min:"), 4, 0); - grid->addWidget(m_xMinSpin, 4, 1); - grid->addWidget(new QLabel("x max:"), 5, 0); - grid->addWidget(m_xMaxSpin, 5, 1); - grid->addWidget(new QLabel("y min:"), 6, 0); - grid->addWidget(m_yMinSpin, 6, 1); - grid->addWidget(new QLabel("y max:"), 7, 0); - grid->addWidget(m_yMaxSpin, 7, 1); grid->addWidget(new QLabel("Chart theme:"), 8, 0); grid->addWidget(chartTheme, 8, 1); - grid->addWidget(zoomCheckBox, 9, 0); - // add row with empty label to make all the other rows static - grid->addWidget(new QLabel(""), 10, 0); - grid->setRowStretch(10, 1); - - mainLayout->addLayout(grid, 0, 0); - - // Scatter specific settings - m_scatterLayout = new QGridLayout(); - m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); - m_scatterLayout->setEnabled(false); +} - // Pie specific settings +void MainWidget::initPieControls() +{ + // Pie series specific settings // Pie size factory QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); pieSizeSpin->setMinimum(LONG_MIN); @@ -131,18 +154,6 @@ MainWidget::MainWidget(QWidget *parent) : m_pieLayout->addWidget(pieSizeSpin, 0, 1); m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); m_pieLayout->addWidget(piePosCombo, 1, 1); - - mainLayout->addLayout(m_scatterLayout, 1, 0); - mainLayout->addLayout(m_pieLayout, 2, 0); - - //m_chartWidget->setColor(Qt::red); - mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); -// hbox->setStretch(1, 1); - - setLayout(mainLayout); - - m_autoScaleCheck->setChecked(true); - testDataChanged(0); } void MainWidget::addSeries() diff --git a/test/chartwidgettest/mainwidget.h b/test/chartwidgettest/mainwidget.h index f5226e0..ca4660b 100644 --- a/test/chartwidgettest/mainwidget.h +++ b/test/chartwidgettest/mainwidget.h @@ -19,6 +19,12 @@ public: signals: +private: + void initBackroundCombo(QGridLayout *grid); + void initScaleControls(QGridLayout *grid); + void initThemeCombo(QGridLayout *grid); + void initPieControls(); + private slots: void addSeries(); void addSeries(QString series, QString data);