From 82b904eaae07389d28aeaaa16b6837c6d461f6f0 2012-02-27 14:48:17 From: sauimone Date: 2012-02-27 14:48:17 Subject: [PATCH] review fix: Removed iterator from barseries. Remove const from brush and pen. Renamed setters for tooltip, floating values and separators --- diff --git a/example/barchart/main.cpp b/example/barchart/main.cpp index 1cd392c..148d48c 100644 --- a/example/barchart/main.cpp +++ b/example/barchart/main.cpp @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) //! [4] // Enable some features - series->enableToolTip(); + series->setToolTipEnabled(); series->enableFloatingValues(); //! [4] diff --git a/example/percentbarchart/main.cpp b/example/percentbarchart/main.cpp index bb238ea..aab3437 100644 --- a/example/percentbarchart/main.cpp +++ b/example/percentbarchart/main.cpp @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) //! [4] // Enable features - series->enableToolTip(); + series->setToolTipEnabled(); series->enableFloatingValues(); //! [4] diff --git a/example/stackedbarchart/main.cpp b/example/stackedbarchart/main.cpp index 18d21ac..6c8754e 100644 --- a/example/stackedbarchart/main.cpp +++ b/example/stackedbarchart/main.cpp @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) //! [4] // Enable features - series->enableToolTip(); + series->setToolTipEnabled(); series->enableFloatingValues(); //! [4] diff --git a/src/barchart/barchartmodel.cpp b/src/barchart/barchartmodel.cpp index eea1e47..611228d 100644 --- a/src/barchart/barchartmodel.cpp +++ b/src/barchart/barchartmodel.cpp @@ -36,24 +36,14 @@ void BarChartModel::removeBarSet(QBarSet *set) } } -QBarSet* BarChartModel::nextSet(bool getFirst) +QBarSet* BarChartModel::setAt(int index) { - if (getFirst) { - mCurrentSet = 0; - } - - if ((mDataModel.count() <= 0) || (mDataModel.count() <= mCurrentSet)) { - return 0; - } - - QBarSet* set = mDataModel.at(mCurrentSet); - mCurrentSet++; - return set; + return mDataModel.at(index); } -QBarSet* BarChartModel::setAt(int index) +QList BarChartModel::barSets() { - return mDataModel.at(index); + return mDataModel; } QList BarChartModel::legend() diff --git a/src/barchart/barchartmodel_p.h b/src/barchart/barchartmodel_p.h index 4c33392..c7881b9 100644 --- a/src/barchart/barchartmodel_p.h +++ b/src/barchart/barchartmodel_p.h @@ -22,8 +22,9 @@ public: QBarCategory& category(); void addBarSet(QBarSet *set); void removeBarSet(QBarSet *set); - QBarSet* nextSet(bool getFirst); QBarSet *setAt(int index); + QList barSets(); + QList legend(); int countSets(); // Number of sets in model diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index 89b9fd7..201751c 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -52,7 +52,7 @@ void BarPresenter::layoutChanged() // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mSeries->setAt(set)->brush()); + bar->setBrush(mSeries->barsetAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; xPos += mBarDefaultWidth; diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index 07e9337..5a0cbca 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -70,7 +70,7 @@ void BarPresenterBase::dataChanged() // Create new graphic items for bars for (int c=0; ccountCategories(); c++) { for (int s=0; scountSets(); s++) { - QBarSet *set = mSeries->setAt(s); + QBarSet *set = mSeries->barsetAt(s); Bar *bar = new Bar(this); childItems().append(bar); mBars.append(bar); @@ -102,7 +102,7 @@ void BarPresenterBase::dataChanged() // Create floating values for (int category=0; categorycountCategories(); category++) { for (int s=0; scountSets(); s++) { - QBarSet *set = mSeries->setAt(s); + QBarSet *set = mSeries->barsetAt(s); BarValue *value = new BarValue(*set, this); childItems().append(value); mFloatingValues.append(value); diff --git a/src/barchart/percentbarpresenter.cpp b/src/barchart/percentbarpresenter.cpp index 5480f7e..dca32ac 100644 --- a/src/barchart/percentbarpresenter.cpp +++ b/src/barchart/percentbarpresenter.cpp @@ -50,7 +50,7 @@ void PercentBarPresenter::layoutChanged() // TODO: width settable per bar? bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mSeries->setAt(set)->brush()); + bar->setBrush(mSeries->barsetAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; yPos -= barHeight; diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index e0dcfe5..bb50016 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -17,21 +17,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \mainclass - Example on how to create category: - \snippet ../example/barchart/main.cpp 1 - - Example on how to create sets of data: - \snippet ../example/barchart/main.cpp 2 - - Example on how to add sets to bar chart: - \snippet ../example/barchart/main.cpp 3 - - Example on how to enable tooltip and floating values: - \snippet ../example/barchart/main.cpp 4 - - Example on how to create view and apply theme: - \snippet ../example/barchart/main.cpp 5 - \sa QBarCategory, QBarSet, QStackedBarSeries, QPercentBarSeries */ @@ -105,22 +90,17 @@ int QBarSeries::countCategories() } /*! - Simple iterator for set. Returns pointer to next set in series. - Returns first set, if parameter \a getFirst is true. - If series is empty, returns 0. - Returns 0 after last set. -*/ -QBarSet* QBarSeries::nextSet(bool getFirst) + Returns a list of sets in series. Keeps ownership of sets. + */ +QList QBarSeries::barSets() { - return mModel->nextSet(getFirst); + return mModel->barSets(); } /*! - Returns set indexed by \a index. Doesn't check for index bounds. - Assumes that \a index is between 0 and number of sets. Use countSets() to get valid index bound. - \sa countSets() + \internal \a index */ -QBarSet* QBarSeries::setAt(int index) +QBarSet* QBarSeries::barsetAt(int index) { return mModel->setAt(index); } @@ -146,7 +126,7 @@ QString QBarSeries::label(int category) Floating values are bar values, that are displayed on top of each bar. Calling without parameter \a enabled, enables the floating values */ -void QBarSeries::enableFloatingValues(bool enabled) +void QBarSeries::setFloatingValuesEnabled(bool enabled) { if (enabled) { for (int i=0; icountSets(); i++) { @@ -166,7 +146,7 @@ void QBarSeries::enableFloatingValues(bool enabled) Tooltip shows the name of set, when mouse is hovering on top of bar. Calling without parameter \a enabled, enables the tooltip */ -void QBarSeries::enableToolTip(bool enabled) +void QBarSeries::setToolTipEnabled(bool enabled) { if (enabled) { for (int i=0; icountSets(); i++) { @@ -186,7 +166,7 @@ void QBarSeries::enableToolTip(bool enabled) Separators are visual elements that are drawn between categories. Calling without parameter \a enabled, enables the separators */ -void QBarSeries::enableSeparators(bool enabled) +void QBarSeries::setSeparatorsEnabled(bool enabled) { emit separatorsEnabled(enabled); } diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 575e30f..a85bfa4 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -22,8 +22,7 @@ public: void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set int countSets(); int countCategories(); - QBarSet* nextSet(bool getFirst=false); // Returns first set, if called with true - QBarSet *setAt(int index); + QList barSets(); QList legend(); // Returns legend of series (ie. names of all sets in series) @@ -31,6 +30,7 @@ public: // TODO: Functions below this are not part of api and will be moved // to private implementation, when we start using it // TODO: TO PIMPL ---> + QBarSet *barsetAt(int index); QString label(int category); qreal min(); qreal max(); @@ -53,9 +53,9 @@ signals: // <--- TO PIMPL public Q_SLOTS: - void enableFloatingValues(bool enabled=true); // enables floating values on top of bars - void enableToolTip(bool enabled=true); // enables tooltips - void enableSeparators(bool enabled=true); // enables separators between categories + void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars + void setToolTipEnabled(bool enabled=true); // enables tooltips + void setSeparatorsEnabled(bool enabled=true); // enables separators between categories protected: BarChartModel* mModel; diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index 2c88969..5be0715 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -104,7 +104,7 @@ void QBarSet::setValue(int index, qreal value) /*! Sets pen for set. Bars of this set are drawn using \a pen */ -void QBarSet::setPen(const QPen& pen) +void QBarSet::setPen(QPen pen) { mPen = pen; } @@ -112,7 +112,7 @@ void QBarSet::setPen(const QPen& pen) /*! Returns pen of the set. */ -const QPen& QBarSet::pen() const +QPen QBarSet::pen() { return mPen; } @@ -120,7 +120,7 @@ const QPen& QBarSet::pen() const /*! Sets brush for the set. Bars of this set are drawn using \a brush */ -void QBarSet::setBrush(const QBrush& brush) +void QBarSet::setBrush(QBrush brush) { mBrush = brush; } @@ -128,7 +128,7 @@ void QBarSet::setBrush(const QBrush& brush) /*! Returns brush of the set. */ -const QBrush& QBarSet::brush() const +QBrush QBarSet::brush() { return mBrush; } diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 3c35e5c..6d89792 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -21,11 +21,11 @@ public: qreal valueAt(int index); // for modifying individual values void setValue(int index, qreal value); // setter for individual value - void setPen(const QPen& pen); - const QPen& pen() const; + void setPen(QPen pen); + QPen pen(); - void setBrush(const QBrush& brush); - const QBrush& brush() const; + void setBrush(QBrush brush); + QBrush brush(); Q_SIGNALS: void clicked(); // Clicked and hover signals exposed to user diff --git a/src/barchart/stackedbarpresenter.cpp b/src/barchart/stackedbarpresenter.cpp index 0397f93..4769ff3 100644 --- a/src/barchart/stackedbarpresenter.cpp +++ b/src/barchart/stackedbarpresenter.cpp @@ -55,7 +55,7 @@ void StackedBarPresenter::layoutChanged() Bar* bar = mBars.at(itemIndex); bar->resize(mBarDefaultWidth, barHeight); - bar->setBrush(mSeries->setAt(set)->brush()); + bar->setBrush(mSeries->barsetAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; yPos -= barHeight; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index b0a5155..38616c2 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -143,22 +143,25 @@ void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) { + QList sets = series->barSets(); for (int i=0; icountSets(); i++) { - series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); + sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); } } void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count) { + QList sets = series->barSets(); for (int i=0; icountSets(); i++) { - series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); + sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); } } void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count) { + QList sets = series->barSets(); for (int i=0; icountSets(); i++) { - series->nextSet(0==i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); + sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count()))); } } diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 539a23b..869dee4 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 series->addBarSet(set); } series->enableFloatingValues(); - series->enableToolTip(); + series->setToolTipEnabled(); series->enableSeparators(false); m_chartWidget->addSeries(series); setCurrentSeries(series);