From f0ebc1456fe55b1b734e3933ae4143e6db093211 2012-12-07 14:55:41 From: Michal Klocek Date: 2012-12-07 14:55:41 Subject: [PATCH] test better layout calcuation --- diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index f90188c..73cc55f 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -145,8 +145,8 @@ void HorizontalAxis::updateGeometry() //label overlap detection if(labelItem->pos().x() < width || - labelItem->pos().x() < axisRect.left() || - labelItem->pos().x() + rect.width() - 1 > axisRect.right()) { + labelItem->pos().x() < axisRect.left() || + labelItem->pos().x() + rect.width() -1 > axisRect.right()){ labelItem->setVisible(false); } else { labelItem->setVisible(true); diff --git a/src/axis/valueaxis/chartvalueaxisx.cpp b/src/axis/valueaxis/chartvalueaxisx.cpp index 8de1878..10b67ce 100644 --- a/src/axis/valueaxis/chartvalueaxisx.cpp +++ b/src/axis/valueaxis/chartvalueaxisx.cpp @@ -95,31 +95,31 @@ QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c qreal width = 0; qreal height = 0; - int count = 1; - - if(!ticksList.empty()) { - count = qMax(ticksList.last().count(),ticksList.first().count()); - } switch (which) { - case Qt::MinimumSize:{ - count = qMin(count,5); - width = fn.averageCharWidth() * count; - height = fn.height() + labelPadding(); - width = qMax(width,base.width()); - height += base.height(); - sh = QSizeF(width,height); - break; - } - case Qt::PreferredSize:{ - width=fn.averageCharWidth() * count; - height=fn.height()+labelPadding(); - width=qMax(width,base.width()); - height+=base.height(); - sh = QSizeF(width,height); - break; - } - default: + case Qt::MinimumSize: { + if(!ticksList.empty()) { + width = qMax(fn.boundingRect(ticksList.last()).width(),fn.boundingRect(ticksList.first()).width()); + } + height = fn.height() + labelPadding(); + width = qMax(width,base.width()); + height += base.height(); + sh = QSizeF(width,height); + break; + } + case Qt::PreferredSize: { + if(!ticksList.empty()) { + foreach(QString label,ticksList) { + width+=fn.boundingRect(label).width(); + } + } + height=fn.height()+labelPadding(); + width=qMax(width,base.width()); + height+=base.height(); + sh = QSizeF(width,height); + break; + } + default: break; }