diff --git a/demos/chartviewer/charts/axis/barcategoryaxisx.cpp b/demos/chartviewer/charts/axis/barcategoryaxisx.cpp index 2f9119b..e66f93e 100644 --- a/demos/chartviewer/charts/axis/barcategoryaxisx.cpp +++ b/demos/chartviewer/charts/axis/barcategoryaxisx.cpp @@ -51,8 +51,10 @@ public: int count = series->barSets().first()->count(); - for (int i = 0; i < count; i++) - barcategory->append(QString::number(i)); + + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } chart->setAxisY(valueaxis, series); chart->setAxisX(barcategory, series); diff --git a/demos/chartviewer/charts/axis/barcategoryaxisy.cpp b/demos/chartviewer/charts/axis/barcategoryaxisy.cpp index e788e3c..7c27fff 100644 --- a/demos/chartviewer/charts/axis/barcategoryaxisy.cpp +++ b/demos/chartviewer/charts/axis/barcategoryaxisy.cpp @@ -51,8 +51,9 @@ public: int count = series->barSets().first()->count(); - for (int i = 0; i < count; i++) - barcategory->append(QString::number(i)); + for (int i = 0; i < count; i++) { + barcategory->append("BarSet " + QString::number(i)); + } chart->setAxisX(valueaxis, series); chart->setAxisY(barcategory, series); diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp index 1201ed6..1460665 100644 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp +++ b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp @@ -40,30 +40,30 @@ ChartBarCategoryAxisX::~ChartBarCategoryAxisX() QVector ChartBarCategoryAxisX::calculateLayout() const { - int count = m_categoriesAxis->d_ptr->count(); + QVector points; - Q_ASSERT(count >= 1); + const QRectF& gridRect = gridGeometry(); + qreal range = max() - min(); - QVector points; - points.resize(count + 2); + const qreal delta = gridRect.width()/range; - const QRectF &gridRect = gridGeometry(); + if(delta<2) return points; + + qreal offset =-min()-0.5; + + offset = int(offset * delta)%int(delta); - const qreal delta = gridRect.width() / (count); - qreal offset = -min() - 0.5; + int count = qFloor(range); - if (delta < 1) - return points; + if(count < 1 ) return points; - if (offset < 0) - offset = int(offset * gridRect.width() / (max() - min())) % int(delta) + delta; - else - offset = int(offset * gridRect.width() / (max() - min())) % int(delta); + points.resize(count+2); - for (int i = -1; i < count + 1; ++i) { + for (int i = 0; i < count+2; ++i) { qreal x = offset + i * delta + gridRect.left(); - points[i + 1] = x; + points[i] = x; } + return points; } @@ -114,34 +114,35 @@ QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra QSizeF sh; QSizeF base = ChartAxis::sizeHint(which, constraint); QStringList ticksList = createCategoryLabels(ChartAxis::layout()); - qreal width = 0; - qreal height = 0; - - switch (which) { - case Qt::MinimumSize: - width = fn.boundingRect("...").width(); - height = fn.height() + labelPadding(); - width = qMax(width, base.width()); - height += base.height(); - sh = QSizeF(width, height); - break; - case Qt::PreferredSize: { - - for (int i = 0; i < ticksList.size(); ++i) { - QRectF rect = fn.boundingRect(ticksList.at(i)); - width += rect.width(); - height = qMax(rect.height() + labelPadding(), height); - } - width = qMax(width, base.width()); - height += base.height(); - sh = QSizeF(width, height); - break; - } - default: - break; - } - return sh; + qreal width=0; + qreal height=0; + + switch (which) { + case Qt::MinimumSize: + width = fn.boundingRect("...").width(); + height = fn.height()+labelPadding(); + width=qMax(width,base.width()); + height += base.height(); + sh = QSizeF(width,height); + break; + case Qt::PreferredSize:{ + + for (int i = 0; i < ticksList.size(); ++i) + { + QRectF rect = fn.boundingRect(ticksList.at(i)); + width += rect.width(); + } + height = fn.height()+labelPadding(); + width = qMax(width,base.width()); + height += base.height(); + sh = QSizeF(width,height); + break; + } + default: + break; + } + return sh; } QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp index f7f07c6..213dfe6 100644 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp +++ b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp @@ -23,6 +23,7 @@ #include "qbarcategoryaxis_p.h" #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -111,34 +112,35 @@ QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra QSizeF sh; QSizeF base = ChartAxis::sizeHint(which, constraint); QStringList ticksList = createCategoryLabels(ChartAxis::layout()); - qreal width = 0; - qreal height = 0; - - switch (which) { - case Qt::MinimumSize: - width = fn.boundingRect("...").width() + labelPadding(); - height = fn.height(); - width += base.width(); - height = qMax(height, base.height()); - sh = QSizeF(width, height); - break; - case Qt::PreferredSize: { - - for (int i = 0; i < ticksList.size(); ++i) { - QRectF rect = fn.boundingRect(ticksList.at(i)); - height += rect.height(); - width = qMax(rect.width() + labelPadding(), width); - } - height = qMax(height, base.height()); - width += base.width(); - sh = QSizeF(width, height); - break; - } - default: - break; - } - return sh; + qreal width=0; + qreal height=0; + + switch (which) { + case Qt::MinimumSize: + width = fn.boundingRect("...").width() + labelPadding(); + height = fn.height(); + width+=base.width(); + height=qMax(height,base.height()); + sh = QSizeF(width,height); + break; + case Qt::PreferredSize:{ + + for (int i = 0; i < ticksList.size(); ++i) + { + QRectF rect = fn.boundingRect(ticksList.at(i)); + height+=rect.height(); + width=qMax(rect.width()+labelPadding() +1 ,width); //one pixel torelance + } + height=qMax(height,base.height()); + width+=base.width(); + sh = QSizeF(width,height); + break; + } + default: + break; + } + return sh; } QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/axis/chartaxis.cpp b/src/axis/chartaxis.cpp index 67fd6df..fee2ba6 100644 --- a/src/axis/chartaxis.cpp +++ b/src/axis/chartaxis.cpp @@ -301,9 +301,8 @@ void ChartAxis::handleDomainUpdated() QVector layout = calculateLayout(); updateLayout(layout); - QSizeF before = effectiveSizeHint(Qt::MinimumSize); - - QSizeF after = sizeHint(Qt::MinimumSize); + QSizeF before = effectiveSizeHint(Qt::PreferredSize); + QSizeF after = sizeHint(Qt::PreferredSize); if (before != after) { QGraphicsLayoutItem::updateGeometry(); diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index 16cd1c1..d013929 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -21,6 +21,7 @@ #include "horizontalaxis_p.h" #include "qabstractaxis.h" #include +#include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -41,15 +42,15 @@ void HorizontalAxis::updateGeometry() if (layout.isEmpty()) return; - QStringList ticksList = labels(); + QStringList labelList = labels(); QList lines = lineItems(); QList labels = labelItems(); QList shades = shadeItems(); QList axis = arrowItems(); - Q_ASSERT(labels.size() == ticksList.size()); - Q_ASSERT(layout.size() == ticksList.size()); + Q_ASSERT(labels.size() == labelList.size()); + Q_ASSERT(layout.size() == labelList.size()); const QRectF &axisRect = axisGeometry(); const QRectF &gridRect = gridGeometry(); @@ -63,19 +64,39 @@ void HorizontalAxis::updateGeometry() arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top()); qreal width = 0; + QFontMetrics fn(font()); for (int i = 0; i < layout.size(); ++i) { - QGraphicsLineItem *gridItem = static_cast(lines.at(i)); - QGraphicsLineItem *tickItem = static_cast(axis.at(i + 1)); + //items + QGraphicsLineItem *gridItem = static_cast(lines.at(i)); + QGraphicsLineItem *tickItem = static_cast(axis.at(i + 1)); QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); //grid line gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom()); - //label text - labelItem->setText(ticksList.at(i)); - const QRectF &rect = labelItem->boundingRect(); + //label text wrapping + if(intervalAxis()&& i+1!=layout.size()) { + //wrapping in case of interval axis + const qreal delta = layout[i+1] - layout[i]; + QString text = labelList.at(i); + if (fn.boundingRect(text).width() > delta ) + { + QString label = text + "..."; + while (fn.boundingRect(label).width() > delta && label.length() > 3) + label.remove(label.length() - 4, 1); + labelItem->setText(label); + } + else { + labelItem->setText(text); + } + }else{ + labelItem->setText(labelList.at(i)); + } + + //label transformation origin point + const QRectF& rect = labelItem->boundingRect(); QPointF center = rect.center(); labelItem->setTransformOriginPoint(center.x(), center.y()); @@ -88,23 +109,21 @@ void HorizontalAxis::updateGeometry() tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); } - if (intervalAxis() && i + 1 != layout.size()) { - const qreal delta = (layout[i + 1] - layout[i]) / 2; + //label in beetwen + if(intervalAxis()&& i+1!=layout.size()) { + const qreal delta = (layout[i+1] - layout[i])/2; labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); } - //overlap detection - if (labelItem->pos().x() <= width || + //label overlap detection + if(labelItem->pos().x() <= width || labelItem->pos().x() < axisRect.left() || labelItem->pos().x() + rect.width() > axisRect.right()) { labelItem->setVisible(false); - gridItem->setVisible(false); - tickItem->setVisible(false); - } else { + } + else { labelItem->setVisible(true); - gridItem->setVisible(true); - tickItem->setVisible(true); - width = rect.width() + labelItem->pos().x(); + width=rect.width()+labelItem->pos().x(); } //shades @@ -118,8 +137,9 @@ void HorizontalAxis::updateGeometry() if (x < gridRect.left() || x > gridRect.right()) { gridItem->setVisible(false); tickItem->setVisible(false); - if (intervalAxis() && (labelItem->pos().x() < gridRect.left() || labelItem->pos().x() + rect.width() > gridRect.right())) - labelItem->setVisible(false); + }else{ + gridItem->setVisible(true); + tickItem->setVisible(true); } } @@ -129,8 +149,10 @@ void HorizontalAxis::updateGeometry() QGraphicsLineItem *gridLine; gridLine = static_cast(lines.at(layout.size())); gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom()); - gridLine = static_cast(lines.at(layout.size() + 1)); + gridLine->setVisible(true); + gridLine = static_cast(lines.at(layout.size()+1)); gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom()); + gridLine->setVisible(true); } } diff --git a/src/axis/valueaxis/chartvalueaxisx.cpp b/src/axis/valueaxis/chartvalueaxisx.cpp index fb25c19..9635bd9 100644 --- a/src/axis/valueaxis/chartvalueaxisx.cpp +++ b/src/axis/valueaxis/chartvalueaxisx.cpp @@ -88,23 +88,23 @@ QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c qreal height = 0; switch (which) { - case Qt::MinimumSize: { - int count = qMax(ticksList.last().count(), ticksList.first().count()); + case Qt::MinimumSize:{ + int count = qMax(ticksList.last().count(),ticksList.first().count()); + count = qMin(count,5); width = fn.averageCharWidth() * count; height = fn.height() + labelPadding(); - width = qMax(width, base.width()); + width = qMax(width,base.width()); height += base.height(); - sh = QSizeF(width, height); + sh = QSizeF(width,height); break; } - case Qt::PreferredSize: { - for (int i = 0; i < ticksList.size(); ++i) { - width += fn.averageCharWidth() * ticksList.at(i).count(); - } - height = fn.height() + labelPadding(); - width = qMax(width, base.width()); - height += base.height(); - sh = QSizeF(width, height); + case Qt::PreferredSize:{ + int count = qMax(ticksList.last().count(),ticksList.first().count()); + width=fn.averageCharWidth() * count; + height=fn.height()+labelPadding(); + width=qMax(width,base.width()); + height+=base.height(); + sh = QSizeF(width,height); break; } default: diff --git a/src/axis/valueaxis/chartvalueaxisy.cpp b/src/axis/valueaxis/chartvalueaxisy.cpp index 24bde9c..407fa94 100644 --- a/src/axis/valueaxis/chartvalueaxisy.cpp +++ b/src/axis/valueaxis/chartvalueaxisy.cpp @@ -26,6 +26,7 @@ #include #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -90,22 +91,21 @@ QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c switch (which) { case Qt::MinimumSize: { - int count = qMax(ticksList.first().count() , ticksList.last().count()); - width = fn.averageCharWidth() * count + labelPadding(); - height = fn.height(); - height = qMax(height, base.height()); + width = fn.boundingRect("...").width() + labelPadding(); width += base.width(); - sh = QSizeF(width, height); + height = fn.height(); + height = qMax(height,base.height()); + sh = QSizeF(width,height); break; } - case Qt::PreferredSize: { - for (int i = 0; i < ticksList.size(); ++i) { - width = qMax(qreal(fn.averageCharWidth() * ticksList.at(i).count()) + labelPadding(), width); - height += fn.height(); - } - height = qMax(height, base.height()); + case Qt::PreferredSize: + { + int count = qMax(ticksList.first().count() , ticksList.last().count()); + width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance width += base.width(); - sh = QSizeF(width, height); + height = fn.height() * ticksList.count(); + height = qMax(height,base.height()); + sh = QSizeF(width,height); break; } default: diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 8d8162d..dc1e888 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -57,17 +57,21 @@ void VerticalAxis::updateGeometry() qreal height = axisRect.bottom(); - QGraphicsLineItem *lineItem = static_cast(axis.at(0)); - if (alignment() == Qt::AlignLeft) - lineItem->setLine(axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom()); - else if (alignment() == Qt::AlignRight) - lineItem->setLine(axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom()); + //arrow + QGraphicsLineItem *arrowItem = static_cast(axis.at(0)); + + //arrow position + if (alignment()==Qt::AlignLeft) + arrowItem->setLine( axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom()); + else if(alignment()==Qt::AlignRight) + arrowItem->setLine( axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom()); QFontMetrics fn(font()); for (int i = 0; i < layout.size(); ++i) { + //items QGraphicsLineItem *gridItem = static_cast(lines.at(i)); QGraphicsLineItem *tickItem = static_cast(axis.at(i + 1)); QGraphicsSimpleTextItem *labelItem = static_cast(labels.at(i)); @@ -75,7 +79,7 @@ void VerticalAxis::updateGeometry() //grid line gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]); - //label text + //label text wrapping QString text = labelList.at(i); if (fn.boundingRect(text).width() > axisRect.right() - axisRect.left() - labelPadding()) { QString label = text + "..."; @@ -85,7 +89,9 @@ void VerticalAxis::updateGeometry() } else { labelItem->setText(text); } + //label transformation origin point const QRectF &rect = labelItem->boundingRect(); + QPointF center = rect.center(); labelItem->setTransformOriginPoint(center.x(), center.y()); @@ -97,22 +103,22 @@ void VerticalAxis::updateGeometry() labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y()); tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); } - if (intervalAxis() && i + 1 != layout.size()) { - const qreal delta = (layout[i + 1] - layout[i]) / 2; + + //label in beetwen + if(intervalAxis()&& i+1!=layout.size()) { + const qreal delta = (layout[i+1] - layout[i])/2; labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); } - //overlap detection - if (labelItem->pos().y() + rect.height() > height || - labelItem->pos().y() + rect.height() > axisRect.bottom() || - labelItem->pos().y() < axisRect.top()) { + //label overlap detection + if(labelItem->pos().y() + rect.height() > height || + labelItem->pos().y() + rect.height()/2 > gridRect.bottom() || + labelItem->pos().y() + rect.height()/2 < gridRect.top()) { labelItem->setVisible(false); - gridItem->setVisible(false); - tickItem->setVisible(false); - } else { + } + else { labelItem->setVisible(true); - gridItem->setVisible(true); - height = labelItem->pos().y(); + height=labelItem->pos().y(); } //shades @@ -123,11 +129,13 @@ void VerticalAxis::updateGeometry() // check if the grid line and the axis tick should be shown qreal y = gridItem->line().p1().y(); - if (y < gridRect.top() || y > gridRect.bottom()) { + if ((y < gridRect.top() || y > gridRect.bottom())) + { gridItem->setVisible(false); tickItem->setVisible(false); - if (intervalAxis() && (labelItem->pos().y() < gridRect.top() || labelItem->pos().y() + rect.height() > gridRect.bottom())) - labelItem->setVisible(false); + }else{ + gridItem->setVisible(true); + tickItem->setVisible(true); } } @@ -136,8 +144,10 @@ void VerticalAxis::updateGeometry() QGraphicsLineItem *gridLine; gridLine = static_cast(lines.at(layout.size())); gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top()); - gridLine = static_cast(lines.at(layout.size() + 1)); + gridLine->setVisible(true); + gridLine = static_cast(lines.at(layout.size()+1)); gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom()); + gridLine->setVisible(true); } } diff --git a/src/chartlayout.cpp b/src/chartlayout.cpp index ac19e53..12003b6 100644 --- a/src/chartlayout.cpp +++ b/src/chartlayout.cpp @@ -29,7 +29,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -static const qreal golden_ratio = 0.25; +static const qreal golden_ratio = 0.4; ChartLayout::ChartLayout(ChartPresenter *presenter) : m_presenter(presenter), @@ -103,10 +103,14 @@ QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList& axes) const { - QSizeF left; - QSizeF right; - QSizeF bottom; - QSizeF top; + QSizeF left(0,0); + QSizeF minLeft(0,0); + QSizeF right(0,0); + QSizeF minRight(0,0); + QSizeF bottom(0,0); + QSizeF minBottom(0,0); + QSizeF top(0,0); + QSizeF minTop(0,0); int leftCount = 0; int rightCount = 0; int topCount = 0; @@ -117,64 +121,80 @@ QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QListisVisible()) continue; - QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); + QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); + //this is used to get single thick font size + QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize); switch (axis->alignment()) { case Qt::AlignLeft: - left.setWidth(left.width() + size.width()); - left.setHeight(qMax(left.height(), size.height())); - leftCount++; - break; + left.setWidth(left.width()+size.width()); + left.setHeight(qMax(left.height(),size.height())); + minLeft.setWidth(minLeft.width()+minSize.width()); + minLeft.setHeight(qMax(minLeft.height(),minSize.height())); + leftCount++; + break; case Qt::AlignRight: - right.setWidth(right.width() + size.width()); - right.setHeight(qMax(right.height(), size.height())); + right.setWidth(right.width()+size.width()); + right.setHeight(qMax(right.height(),size.height())); + minRight.setWidth(minRight.width()+minSize.width()); + minRight.setHeight(qMax(minRight.height(),minSize.height())); rightCount++; break; case Qt::AlignTop: - top.setWidth(qMax(top.width(), size.width())); - top.setHeight(top.height() + size.height()); + top.setWidth(qMax(top.width(),size.width())); + top.setHeight(top.height()+size.height()); + minTop.setWidth(qMax(minTop.width(),minSize.width())); + minTop.setHeight(minTop.height()+minSize.height()); topCount++; break; case Qt::AlignBottom: bottom.setWidth(qMax(bottom.width(), size.width())); bottom.setHeight(bottom.height() + size.height()); + minBottom.setWidth(qMax(minBottom.width(),minSize.width())); + minBottom.setHeight(minBottom.height() + minSize.height()); bottomCount++; break; } } - left.setWidth(qMax(qMax(top.width() / 2, bottom.width() / 2), left.width())); - left.setWidth(qMin(left.width(), golden_ratio * geometry.width())); - right.setWidth(qMax(qMax(top.width() / 2, bottom.width() / 2), right.width())); - right.setWidth(qMin(right.width(), golden_ratio * geometry.width())); - top.setHeight(qMax(qMax(left.height() / 2, right.height() / 2), top.height())); - bottom.setHeight(qMax(qMax(left.height() / 2, right.height() / 2), bottom.height())); + int horizontal = leftCount + rightCount; + qreal hratio = 0 ; + if(horizontal>0) + hratio = (golden_ratio*geometry.width())/horizontal; + + if(leftCount>0) + left.setWidth(qMin(left.width(),hratio*leftCount)); + if(rightCount>0) + right.setWidth(qMin(right.width(),hratio*rightCount)); - QRectF chartRect = geometry.adjusted(left.width(), top.height(), -right.width(), -bottom.height()); + qreal minHeight = qMax(minLeft.height(),minRight.height()); + qreal minWidth = qMax(minTop.width(),minBottom.width()); + + QRectF chartRect = geometry.adjusted(qMax(left.width(),minWidth/2), qMax(top.height(), minHeight/2),-qMax(right.width(),minWidth/2),-qMax(bottom.height(),minHeight/2)); qreal leftOffset = 0; qreal rightOffset = 0; qreal topOffset = 0; qreal bottomOffset = 0; - foreach(ChartAxis * axis , axes) { + foreach(ChartAxis* axis , axes) { if (!axis->isVisible()) continue; - QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize); + QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize); - switch (axis->alignment()) { - case Qt::AlignLeft: { - qreal width = qMin(size.width(), left.width() / leftCount); - leftOffset += width; - axis->setGeometry(QRect(chartRect.left() - leftOffset, chartRect.top() - (size.height() + 1) / 2, width, chartRect.height() + size.height() + 2), chartRect); + switch(axis->alignment()){ + case Qt::AlignLeft:{ + qreal width = qMin(size.width(),(left.width()/leftCount)); + leftOffset+=width; + axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect); break; } - case Qt::AlignRight: { - qreal width = qMin(size.width(), right.width() / rightCount); - axis->setGeometry(QRect(chartRect.right() + rightOffset, chartRect.top() - (size.height() + 1) / 2, width, chartRect.height() + size.height() + 2), chartRect); - rightOffset += width; + case Qt::AlignRight:{ + qreal width = qMin(size.width(),(right.width()/rightCount)); + axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect); + rightOffset+=width; break; } case Qt::AlignTop: @@ -287,8 +307,8 @@ QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *t { title->setGeometry(geometry); QPointF center = geometry.center() - title->boundingRect().center(); - title->setPos(center.x(), title->pos().y()); - return geometry.adjusted(0, title->boundingRect().height(), 0, 0); + title->setPos(center.x(),title->pos().y()); + return geometry.adjusted(0,title->boundingRect().height()+1,0,0); } QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const diff --git a/src/charttitle.cpp b/src/charttitle.cpp index c1f6dff..3ceedc6 100644 --- a/src/charttitle.cpp +++ b/src/charttitle.cpp @@ -76,10 +76,10 @@ QSizeF ChartTitle::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const sh = QSizeF(fn.boundingRect("...").width(), fn.height()); break; case Qt::PreferredSize: - sh = QSizeF(fn.boundingRect(m_text).width(), fn.height()); + sh = fn.boundingRect(m_text).size(); break; case Qt::MaximumSize: - sh = QSizeF(fn.boundingRect(m_text).width(), fn.height()); + sh = fn.boundingRect(m_text).size(); break; case Qt::MinimumDescent: sh = QSizeF(0, fn.descent());