@@ -21,6 +21,7 | |||||
21 | #include "chartdatetimeaxisx_p.h" |
|
21 | #include "chartdatetimeaxisx_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qdatetimeaxis.h" |
|
23 | #include "qdatetimeaxis.h" | |
|
24 | #include "chartlayout_p.h" | |||
24 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
25 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
26 | #include <QFontMetrics> |
|
27 | #include <QFontMetrics> | |
@@ -65,7 +66,10 void ChartDateTimeAxisX::updateGeometry() | |||||
65 |
|
66 | |||
66 | void ChartDateTimeAxisX::handleAxisUpdated() |
|
67 | void ChartDateTimeAxisX::handleAxisUpdated() | |
67 | { |
|
68 | { | |
68 |
m_tickCount = m_axis->tickCount() |
|
69 | if (m_tickCount != m_axis->tickCount()) { | |
|
70 | m_tickCount = m_axis->tickCount(); | |||
|
71 | presenter()->layout()->invalidate(); | |||
|
72 | } | |||
69 | ChartAxis::handleAxisUpdated(); |
|
73 | ChartAxis::handleAxisUpdated(); | |
70 | } |
|
74 | } | |
71 |
|
75 | |||
@@ -76,26 +80,29 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
76 | QFontMetrics fn(font()); |
|
80 | QFontMetrics fn(font()); | |
77 | QSizeF sh; |
|
81 | QSizeF sh; | |
78 |
|
82 | |||
|
83 | QSizeF base = HorizontalAxis::sizeHint(which, constraint); | |||
|
84 | QStringList ticksList = createDateTimeLabels(m_axis->format(), m_tickCount); | |||
|
85 | qreal width = 0; | |||
|
86 | qreal height = 0; | |||
|
87 | ||||
|
88 | ||||
79 | switch (which) { |
|
89 | switch (which) { | |
80 | case Qt::MinimumSize: |
|
90 | case Qt::MinimumSize:{ | |
81 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); |
|
91 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | |
|
92 | width = fn.averageCharWidth() * count; | |||
|
93 | height = fn.height() + labelPadding(); | |||
|
94 | width = qMax(width,base.width()); | |||
|
95 | height += base.height(); | |||
|
96 | sh = QSizeF(width,height); | |||
82 | break; |
|
97 | break; | |
|
98 | } | |||
83 | case Qt::PreferredSize: { |
|
99 | case Qt::PreferredSize: { | |
84 |
|
100 | int count = qMax(ticksList.last().count(),ticksList.first().count()); | ||
85 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
101 | width=fn.averageCharWidth() * count; | |
86 | if (layout.isEmpty()) |
|
102 | height=fn.height()+labelPadding(); | |
87 | break; |
|
103 | width=qMax(width,base.width()); | |
88 | QStringList ticksList; |
|
104 | height+=base.height(); | |
89 |
|
105 | sh = QSizeF(width,height); | ||
90 | qreal width = 0; |
|
|||
91 | qreal height = 0; |
|
|||
92 |
|
||||
93 | for (int i = 0; i < ticksList.size(); ++i) { |
|
|||
94 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
|||
95 | width += rect.width(); |
|
|||
96 | height += qMax(rect.height() + labelPadding(), height); |
|
|||
97 | } |
|
|||
98 | sh = QSizeF(width, height); |
|
|||
99 | break; |
|
106 | break; | |
100 | } |
|
107 | } | |
101 | default: |
|
108 | default: |
@@ -21,6 +21,7 | |||||
21 | #include "chartdatetimeaxisy_p.h" |
|
21 | #include "chartdatetimeaxisy_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qdatetimeaxis.h" |
|
23 | #include "qdatetimeaxis.h" | |
|
24 | #include "chartlayout_p.h" | |||
24 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
25 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
26 | #include <QDateTime> |
|
27 | #include <QDateTime> | |
@@ -66,7 +67,10 void ChartDateTimeAxisY::updateGeometry() | |||||
66 |
|
67 | |||
67 | void ChartDateTimeAxisY::handleAxisUpdated() |
|
68 | void ChartDateTimeAxisY::handleAxisUpdated() | |
68 | { |
|
69 | { | |
69 |
m_tickCount = m_axis->tickCount() |
|
70 | if (m_tickCount != m_axis->tickCount()) { | |
|
71 | m_tickCount = m_axis->tickCount(); | |||
|
72 | presenter()->layout()->invalidate(); | |||
|
73 | } | |||
70 | ChartAxis::handleAxisUpdated(); |
|
74 | ChartAxis::handleAxisUpdated(); | |
71 | } |
|
75 | } | |
72 |
|
76 | |||
@@ -77,28 +81,30 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint | |||||
77 | QFontMetrics fn(font()); |
|
81 | QFontMetrics fn(font()); | |
78 | QSizeF sh; |
|
82 | QSizeF sh; | |
79 |
|
83 | |||
80 | switch (which) { |
|
84 | QSizeF base = VerticalAxis::sizeHint(which, constraint); | |
81 | case Qt::MinimumSize: |
|
85 | QStringList ticksList = createDateTimeLabels(m_axis->format(),m_tickCount); | |
82 | sh = QSizeF(fn.boundingRect("...").width(), fn.height()); |
|
86 | qreal width = 0; | |
83 | break; |
|
87 | qreal height = 0; | |
84 | case Qt::PreferredSize: { |
|
|||
85 |
|
||||
86 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
|||
87 | if (layout.isEmpty()) break; |
|
|||
88 | QStringList ticksList; |
|
|||
89 |
|
||||
90 | qreal width = 0; |
|
|||
91 | qreal height = 0; |
|
|||
92 |
|
88 | |||
93 | for (int i = 0; i < ticksList.size(); ++i) { |
|
89 | switch (which) { | |
94 | QRectF rect = fn.boundingRect(ticksList.at(i)); |
|
90 | case Qt::MinimumSize: { | |
95 |
width |
|
91 | width = fn.boundingRect("...").width() + labelPadding(); | |
96 | height += qMax(rect.height() + labelPadding(), height); |
|
92 | width += base.width(); | |
|
93 | height = fn.height(); | |||
|
94 | height = qMax(height,base.height()); | |||
|
95 | sh = QSizeF(width,height); | |||
|
96 | break; | |||
97 | } |
|
97 | } | |
98 | sh = QSizeF(width, height); |
|
98 | case Qt::PreferredSize: { | |
99 | break; |
|
99 | int count = qMax(ticksList.first().count() , ticksList.last().count()); | |
100 | } |
|
100 | width = count*fn.averageCharWidth() + labelPadding() + 2; //two pixels of tolerance | |
101 | default: |
|
101 | width += base.width(); | |
|
102 | height = fn.height() * ticksList.count(); | |||
|
103 | height = qMax(height,base.height()); | |||
|
104 | sh = QSizeF(width,height); | |||
|
105 | break; | |||
|
106 | } | |||
|
107 | default: | |||
102 | break; |
|
108 | break; | |
103 | } |
|
109 | } | |
104 |
|
110 |
General Comments 0
You need to be logged in to leave comments.
Login now