diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index cde40f5..77b6a77 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -49,13 +49,14 @@ int main(int argc, char *argv[]) //! [4] // Enable tooltip series->setToolTipEnabled(); + series->setSeparatorsVisible(true); // Connect clicked signal of set to toggle floating values of set. - // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values. QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); + QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); //! [4] //! [5] @@ -68,9 +69,7 @@ int main(int argc, char *argv[]) //! [5] //! [6] - chartView->axisX()->setAxisVisible(false); chartView->axisX()->setGridVisible(false); - chartView->axisX()->setLabelsVisible(false); //! [6] window.setCentralWidget(chartView); diff --git a/examples/stackedbarchart/main.cpp b/examples/stackedbarchart/main.cpp index bc10109..1521dd7 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/stackedbarchart/main.cpp @@ -50,11 +50,11 @@ int main(int argc, char *argv[]) series->setToolTipEnabled(); // Connect clicked signal of set to toggle floating values of set. - // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values. QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); + QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); //! [4] //! [5] @@ -67,9 +67,7 @@ int main(int argc, char *argv[]) //! [5] //! [6] - chartView->axisX()->setAxisVisible(false); chartView->axisX()->setGridVisible(false); - chartView->axisX()->setLabelsVisible(false); //! [6] window.setCentralWidget(chartView); diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index 858c6c4..d6d61fb 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -1,6 +1,7 @@ #include "barpresenter_p.h" #include "bar_p.h" #include "barvalue_p.h" +#include "separator_p.h" #include "qbarset.h" #include @@ -34,12 +35,12 @@ void BarPresenter::layoutChanged() qreal tM = mSeries->max(); qreal scale = (tH/tM); qreal tC = categoryCount + 1; - mBarWidth = tW / ((categoryCount * setCount) + tC); - qreal xStepPerCategory = (tW/tC) + mBarWidth; + qreal categoryWidth = tW/tC; + mBarWidth = categoryWidth / (setCount+1); int itemIndex(0); for (int category=0; category < categoryCount; category++) { - qreal xPos = xStepPerCategory * category; + qreal xPos = categoryWidth * category + categoryWidth /2; qreal yPos = mHeight; for (int set = 0; set < setCount; set++) { qreal barHeight = mSeries->valueAt(set,category) * scale; @@ -54,10 +55,19 @@ void BarPresenter::layoutChanged() } } + // Position separators + qreal xPos = categoryWidth + categoryWidth/2 - mBarWidth /2; + for (int s=0; s < mSeparators.count(); s++) { + Separator* sep = mSeparators.at(s); + sep->setPos(xPos,0); + sep->setSize(QSizeF(1,mHeight)); + xPos += categoryWidth; + } + // Position floating values itemIndex = 0; for (int category=0; category < mSeries->categoryCount(); category++) { - qreal xPos = xStepPerCategory * category + mBarWidth/2; + qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth/2; qreal yPos = mHeight; for (int set=0; set < mSeries->barsetCount(); set++) { qreal barHeight = mSeries->valueAt(set,category) * scale; diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index 7f37928..fc41f1c 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -15,11 +15,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) : ChartItem(parent) ,mLayoutSet(false) - ,mSeparatorsEnabled(false) ,mSeries(series) ,mChart(parent) { connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); + connect(series,SIGNAL(enableSeparators(bool)),this,SLOT(enableSeparators(bool))); + enableSeparators(series->separatorsVisible()); initAxisLabels(); dataChanged(); } @@ -27,6 +28,7 @@ BarPresenterBase::BarPresenterBase(QBarSeries *series, QChart *parent) BarPresenterBase::~BarPresenterBase() { disconnect(this,SLOT(showToolTip(QPoint,QString))); + disconnect(this,SLOT(enableSeparators(bool))); } void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -77,7 +79,7 @@ void BarPresenterBase::dataChanged() for (int i=0; isetColor(QColor(255,0,0,255)); // TODO: color for separations from theme - sep->setVisible(mSeparatorsEnabled); + sep->setVisible(mSeries->separatorsVisible()); childItems().append(sep); mSeparators.append(sep); } @@ -170,7 +172,6 @@ void BarPresenterBase::enableSeparators(bool enabled) for (int i=0; isetVisible(enabled); } - mSeparatorsEnabled = enabled; } #include "moc_barpresenterbase_p.cpp" diff --git a/src/barchart/barpresenterbase_p.h b/src/barchart/barpresenterbase_p.h index 6b55fbe..62cdc94 100644 --- a/src/barchart/barpresenterbase_p.h +++ b/src/barchart/barpresenterbase_p.h @@ -53,7 +53,6 @@ protected: qreal mBarWidth; bool mLayoutSet; // True, if component has been laid out. - bool mSeparatorsEnabled; // Not owned. QBarSeries* mSeries; diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index d182fb7..eaa0572 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -137,10 +137,10 @@ void QBarSeries::setToolTipEnabled(bool enabled) Separators are visual elements that are drawn between categories. Calling without parameter \a enabled, enables the separators */ -void QBarSeries::setSeparatorsEnabled(bool enabled) +void QBarSeries::setSeparatorsVisible(bool visible) { - // TODO: toggle -// emit separatorsEnabled(enabled); + mSeparatorsVisible = visible; + emit enableSeparators(visible); } @@ -217,6 +217,11 @@ BarChartModel& QBarSeries::model() return *mModel; } +bool QBarSeries::separatorsVisible() +{ + return mSeparatorsVisible; +} + #include "moc_qbarseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 930ba4e..61b6575 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -39,6 +39,7 @@ public: qreal categorySum(int category); qreal maxCategorySum(); BarChartModel& model(); + bool separatorsVisible(); // <--- TO PIMPL signals: @@ -48,12 +49,13 @@ signals: // TODO: internal signals, these to private implementation. // TODO: TO PIMPL ---> + void enableSeparators(bool enable); void showToolTip(QPoint pos, QString tip); // <--- TO PIMPL public Q_SLOTS: void setToolTipEnabled(bool enabled=true); // enables tooltips - void setSeparatorsEnabled(bool enabled=true); // enables separators between categories + void setSeparatorsVisible(bool visible=true); // enables separators between categories // TODO: TO PIMPL ---> void barsetClicked(QString category); @@ -62,6 +64,7 @@ public Q_SLOTS: protected: BarChartModel* mModel; + bool mSeparatorsVisible; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index cf72b52..94bf96c 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -272,7 +272,7 @@ void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS // TODO: new implementation of setFloatingValuesEnabled with signals //series->setFloatingValuesEnabled(true); series->setToolTipEnabled(true); - series->setSeparatorsEnabled(false); + series->setSeparatorsVisible(false); m_chartView->addSeries(series); setCurrentSeries(series); } else if (seriesName == "Spline") {