From 597882065a5ee5d0dfa39a452780708895eba072 2012-03-07 15:13:15 From: Jani Honkonen Date: 2012-03-07 15:13:15 Subject: [PATCH] Renamed the "factor" stuff from pie series API. --- diff --git a/examples/customcolors/mainwindow.cpp b/examples/customcolors/mainwindow.cpp index 5a11b84..4892d4b 100644 --- a/examples/customcolors/mainwindow.cpp +++ b/examples/customcolors/mainwindow.cpp @@ -45,8 +45,8 @@ MainWindow::MainWindow(QWidget *parent) m_pie->add(1.1, "1"); m_pie->add(2.1, "2"); m_pie->add(3.0, "3"); - m_pie->setPositionFactors(0.7, 0.7); - m_pie->setSizeFactor(0.5); + m_pie->setPiePosition(0.7, 0.7); + m_pie->setPieSize(0.5); m_chartView->addSeries(m_pie); connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); diff --git a/examples/piechartcustomization/main.cpp b/examples/piechartcustomization/main.cpp index 73baa81..ab13c65 100644 --- a/examples/piechartcustomization/main.cpp +++ b/examples/piechartcustomization/main.cpp @@ -70,30 +70,30 @@ public: m_hPosition->setMinimum(0.0); m_hPosition->setMaximum(1.0); m_hPosition->setSingleStep(0.1); - m_hPosition->setValue(m_series->horizontalPositionFactor()); + m_hPosition->setValue(m_series->pieHorizontalPosition()); m_vPosition = new QDoubleSpinBox(); m_vPosition->setMinimum(0.0); m_vPosition->setMaximum(1.0); m_vPosition->setSingleStep(0.1); - m_vPosition->setValue(m_series->verticalPositionFactor()); + m_vPosition->setValue(m_series->pieVerticalPosition()); m_sizeFactor = new QDoubleSpinBox(); m_sizeFactor->setMinimum(0.0); m_sizeFactor->setMaximum(1.0); m_sizeFactor->setSingleStep(0.1); - m_sizeFactor->setValue(m_series->sizeFactor()); + m_sizeFactor->setValue(m_series->pieSize()); m_startAngle = new QDoubleSpinBox(); m_startAngle->setMinimum(0.0); m_startAngle->setMaximum(360); - m_startAngle->setValue(m_series->startAngle()); + m_startAngle->setValue(m_series->pieStartAngle()); m_startAngle->setSingleStep(1); m_endAngle = new QDoubleSpinBox(); m_endAngle->setMinimum(0.0); m_endAngle->setMaximum(360); - m_endAngle->setValue(m_series->endAngle()); + m_endAngle->setValue(m_series->pieEndAngle()); m_endAngle->setSingleStep(1); QFormLayout* seriesSettingsLayout = new QFormLayout(); @@ -153,12 +153,10 @@ public Q_SLOTS: void updateSerieSettings() { - m_series->setPositionFactors(m_vPosition->value(), m_hPosition->value()); - - m_series->setSizeFactor(m_sizeFactor->value()); - - m_series->setStartAngle(m_startAngle->value()); - m_series->setEndAngle(m_endAngle->value()); + m_series->setPiePosition(m_vPosition->value(), m_hPosition->value()); + m_series->setPieSize(m_sizeFactor->value()); + m_series->setPieStartAngle(m_startAngle->value()); + m_series->setPieEndAngle(m_endAngle->value()); } void updateSliceSettings() diff --git a/src/piechart/piepresenter.cpp b/src/piechart/piepresenter.cpp index 88ea7bd..286bc2c 100644 --- a/src/piechart/piepresenter.cpp +++ b/src/piechart/piepresenter.cpp @@ -15,8 +15,8 @@ PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) { Q_ASSERT(series); connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&))); - connect(series, SIGNAL(sizeFactorChanged()), this, SLOT(updateGeometry())); - connect(series, SIGNAL(positionChanged()), this, SLOT(updateGeometry())); + connect(series, SIGNAL(piePositionChanged()), this, SLOT(updateGeometry())); + connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateGeometry())); if (m_series->count()) { QPieSeries::ChangeSet changeSet; @@ -80,8 +80,8 @@ void PiePresenter::updateGeometry() // find pie center coordinates QPointF center; - center.setX(m_rect.left() + (m_rect.width() * m_series->m_hPositionFactor)); - center.setY(m_rect.top() + (m_rect.height() * m_series->m_vPositionFactor)); + center.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition())); + center.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition())); // find maximum radius for pie qreal radius = m_rect.height() / 2; @@ -89,7 +89,7 @@ void PiePresenter::updateGeometry() radius = m_rect.width() / 2; // apply size factor - radius *= m_series->m_pieSizeFactor; + radius *= m_series->pieSize(); // update slices if (m_pieCenter != center || m_pieRadius != radius) { diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index 0f98d0c..d2ef8c7 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -105,9 +105,9 @@ bool QPieSeries::ChangeSet::isEmpty() const */ QPieSeries::QPieSeries(QObject *parent) : QSeries(parent), - m_hPositionFactor(0.5), - m_vPositionFactor(0.5), - m_pieSizeFactor(0.7), + m_pieRelativeHorPos(0.5), + m_pieRelativeVerPos(0.5), + m_pieRelativeSize(0.7), m_pieStartAngle(0), m_pieEndAngle(360), m_total(0) @@ -254,97 +254,98 @@ QList QPieSeries::slices() const } /*! - Sets the center position of the pie by \a horizontalFactor and \a verticalFactor. + Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition. The factors are relative to the chart rectangle where: - \a horizontalFactor 0.0 means the absolute left. - \a horizontalFactor 1.0 means the absolute right. - \a verticalFactor 0.0 means the absolute top. - \a verticalFactor 1.0 means the absolute bottom. + \a relativeHorizontalPosition 0.0 means the absolute left. + \a relativeHorizontalPosition 1.0 means the absolute right. + \a relativeVerticalPosition 0.0 means the absolute top. + \a relativeVerticalPosition 1.0 means the absolute bottom. - By default \a horizontalFactor and \a verticalFactor are 0.5 which puts the pie in the middle of the chart rectangle. + By default both values are 0.5 which puts the pie in the middle of the chart rectangle. - \sa horizontalPositionFactor(), verticalPositionFactor(), setSizeFactor() + \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize() */ -void QPieSeries::setPositionFactors(qreal horizontalFactor, qreal verticalFactor) +void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) { - if (horizontalFactor < 0.0 || horizontalFactor > 1.0 || verticalFactor < 0.0 || verticalFactor > 1.0) + if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || + relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) return; - if (m_hPositionFactor != horizontalFactor || m_vPositionFactor != verticalFactor) { - m_hPositionFactor = horizontalFactor; - m_vPositionFactor = verticalFactor; - emit positionChanged(); + if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) { + m_pieRelativeHorPos = relativeHorizontalPosition; + m_pieRelativeVerPos = relativeVerticalPosition; + emit piePositionChanged(); } } /*! - Gets the horizontal position factor of the pie. + Gets the horizontal position of the pie. - The factors are relative to the chart rectangle where: + The returned value is relative to the chart rectangle where: - Horizontal factor 0.0 means the absolute left. - Horizontal factor 1.0 means the absolute right. + 0.0 means the absolute left. + 1.0 means the absolute right. - By default horizontal factor is 0.5 which puts the pie in the horizontal middle of the chart rectangle. + By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. - \sa setPositionFactors(), verticalPositionFactor(), setSizeFactor() + \sa setPiePosition(), pieVerticalPosition(), setPieSize() */ -qreal QPieSeries::horizontalPositionFactor() const +qreal QPieSeries::pieHorizontalPosition() const { - return m_hPositionFactor; + return m_pieRelativeHorPos; } /*! - Gets the vertical position factor of the pie. + Gets the vertical position position of the pie. - The factors are relative to the chart rectangle where: + The returned value is relative to the chart rectangle where: - Vertical factor 0.0 means the absolute top. - Vertical factor 1.0 means the absolute bottom. + 0.0 means the absolute top. + 1.0 means the absolute bottom. - By default vertical factor is 0.5 which puts the pie in the vertical middle of the chart rectangle. + By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. - \sa setPositionFactors(), horizontalPositionFactor(), setSizeFactor() + \sa setPiePosition(), pieHorizontalPosition(), setPieSize() */ -qreal QPieSeries::verticalPositionFactor() const +qreal QPieSeries::pieVerticalPosition() const { - return m_vPositionFactor; + return m_pieRelativeVerPos; } /*! - Sets the size \a sizeFactor of the pie. + Sets the relative size of the pie. - The size factor is defined so that the 1.0 is the maximum that can fit the given chart rectangle. + The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. Default value is 0.7. - \sa sizeFactor(), setPositionFactors(), verticalPositionFactor(), horizontalPositionFactor() + \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() */ -void QPieSeries::setSizeFactor(qreal sizeFactor) +void QPieSeries::setPieSize(qreal relativeSize) { - if (sizeFactor < 0.0) + if (relativeSize < 0.0 || relativeSize > 1.0) return; - if (m_pieSizeFactor != sizeFactor) { - m_pieSizeFactor = sizeFactor; - emit sizeFactorChanged(); + if (m_pieRelativeSize != relativeSize) { + m_pieRelativeSize = relativeSize; + emit pieSizeChanged(); } } /*! - Gets the size factor of the pie. + Gets the relative size of the pie. - The size factor is defined so that the 1.0 is the maximum that can fit the given chart rectangle. + The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. Default value is 0.7. - \sa setSizeFactor(), setPositionFactors(), verticalPositionFactor(), horizontalPositionFactor() + \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() */ -qreal QPieSeries::sizeFactor() const +qreal QPieSeries::pieSize() const { - return m_pieSizeFactor; + return m_pieRelativeSize; } @@ -353,14 +354,14 @@ qreal QPieSeries::sizeFactor() const Full pie is 360 degrees where 0 degrees is at 12 a'clock. - \a startAngle must be less than end angle. Default value is 0. + \a angle must be less than pie end angle. Default value is 0. - \sa startAngle(), endAngle(), setEndAngle() + \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() */ -void QPieSeries::setStartAngle(qreal startAngle) +void QPieSeries::setPieStartAngle(qreal angle) { - if (startAngle >= 0 && startAngle <= 360 && startAngle != m_pieStartAngle && startAngle <= m_pieEndAngle) { - m_pieStartAngle = startAngle; + if (angle >= 0 && angle <= 360 && angle != m_pieStartAngle && angle <= m_pieEndAngle) { + m_pieStartAngle = angle; updateDerivativeData(); } } @@ -370,9 +371,9 @@ void QPieSeries::setStartAngle(qreal startAngle) Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. - \sa setStartAngle(), endAngle(), setEndAngle() + \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() */ -qreal QPieSeries::startAngle() const +qreal QPieSeries::pieStartAngle() const { return m_pieStartAngle; } @@ -382,14 +383,14 @@ qreal QPieSeries::startAngle() const Full pie is 360 degrees where 0 degrees is at 12 a'clock. - \a endAngle must be greater than start angle. + \a angle must be greater than start angle. - \sa endAngle(), startAngle(), setStartAngle() + \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() */ -void QPieSeries::setEndAngle(qreal endAngle) +void QPieSeries::setPieEndAngle(qreal angle) { - if (endAngle >= 0 && endAngle <= 360 && endAngle != m_pieEndAngle && endAngle >= m_pieStartAngle) { - m_pieEndAngle = endAngle; + if (angle >= 0 && angle <= 360 && angle != m_pieEndAngle && angle >= m_pieStartAngle) { + m_pieEndAngle = angle; updateDerivativeData(); } } @@ -399,9 +400,9 @@ void QPieSeries::setEndAngle(qreal endAngle) Full pie is 360 degrees where 0 degrees is at 12 a'clock. - \sa setEndAngle(), startAngle(), setStartAngle() + \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() */ -qreal QPieSeries::endAngle() const +qreal QPieSeries::pieEndAngle() const { return m_pieEndAngle; } @@ -461,19 +462,19 @@ qreal QPieSeries::total() const */ /*! - \fn void QPieSeries::sizeFactorChanged() + \fn void QPieSeries::pieSizeChanged() This signal is emitted when size factor has been changed. - \sa sizeFactor(), setSizeFactor() + \sa pieSize(), setPieSize() */ /*! - \fn void QPieSeries::positionChanged() + \fn void QPieSeries::piePositionChanged() This signal is emitted when position of the pie has been changed. - \sa horizontalPositionFactor(), verticalPositionFactor(), setPositionFactors() + \sa pieHorizontalPosition(), pieVerticalPosition(), setPiePosition() */ void QPieSeries::sliceChanged() diff --git a/src/piechart/qpieseries.h b/src/piechart/qpieseries.h index 97d6b86..a2f3c5e 100644 --- a/src/piechart/qpieseries.h +++ b/src/piechart/qpieseries.h @@ -67,15 +67,15 @@ public: qreal total() const; // pie customization - void setPositionFactors(qreal horizontalFactor, qreal verticalFactor); - qreal horizontalPositionFactor() const; - qreal verticalPositionFactor() const; - void setSizeFactor(qreal sizeFactor); - qreal sizeFactor() const; - void setStartAngle(qreal startAngle); - qreal startAngle() const; - void setEndAngle(qreal endAngle); - qreal endAngle() const; + void setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition); + qreal pieHorizontalPosition() const; + qreal pieVerticalPosition() const; + void setPieSize(qreal relativeSize); + qreal pieSize() const; + void setPieStartAngle(qreal startAngle); + qreal pieStartAngle() const; + void setPieEndAngle(qreal endAngle); + qreal pieEndAngle() const; // convenience function QPieSeries& operator << (QPieSlice* slice); @@ -94,15 +94,14 @@ public: // setDropShadows Q_SIGNALS: - - void changed(const QPieSeries::ChangeSet& changeSet); - void clicked(QPieSlice* slice); void hoverEnter(QPieSlice* slice); void hoverLeave(QPieSlice* slice); - void sizeFactorChanged(); - void positionChanged(); + void pieSizeChanged(); + void piePositionChanged(); + + void changed(const QPieSeries::ChangeSet& changeSet); // TODO: hide this in PIMPL private Q_SLOTS: // TODO: should be private and not visible in the interface at all void sliceChanged(); @@ -121,9 +120,9 @@ private: friend class PieSlice; QList m_slices; - qreal m_hPositionFactor; - qreal m_vPositionFactor; - qreal m_pieSizeFactor; + qreal m_pieRelativeHorPos; + qreal m_pieRelativeVerPos; + qreal m_pieRelativeSize; qreal m_pieStartAngle; qreal m_pieEndAngle; qreal m_total;