@@ -50,6 +50,8 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const | |||
|
50 | 50 | const qreal delta = m_rect.width()/(count); |
|
51 | 51 | qreal offset =-m_min-0.5; |
|
52 | 52 | |
|
53 | if(delta<1) return points; | |
|
54 | ||
|
53 | 55 | if(offset<=0) { |
|
54 | 56 | offset = int(offset * m_rect.width()/(m_max - m_min))%int(delta) + delta; |
|
55 | 57 | } |
@@ -22,6 +22,7 | |||
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "qbarcategoryaxis_p.h" |
|
24 | 24 | #include <qmath.h> |
|
25 | #include <QDebug> | |
|
25 | 26 | |
|
26 | 27 | static int label_padding = 5; |
|
27 | 28 | |
@@ -48,6 +49,8 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const | |||
|
48 | 49 | const qreal delta = m_rect.height()/(count); |
|
49 | 50 | qreal offset = - m_min - 0.5; |
|
50 | 51 | |
|
52 | if(delta<1) return points; | |
|
53 | ||
|
51 | 54 | if(offset<=0) { |
|
52 | 55 | offset = int(offset * m_rect.height()/(m_max - m_min))%int(delta) + delta; |
|
53 | 56 | } |
@@ -132,8 +135,8 void ChartCategoriesAxisY::updateGeometry() | |||
|
132 | 135 | height=labelItem->pos().y(); |
|
133 | 136 | } |
|
134 | 137 | |
|
135 |
m_minWidth |
|
|
136 |
m_minHeight= |
|
|
138 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); | |
|
139 | m_minHeight+=rect.height(); | |
|
137 | 140 | |
|
138 | 141 | if ((i+1)%2 && i>1) { |
|
139 | 142 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
@@ -110,7 +110,7 void ChartCategoryAxisX::updateGeometry() | |||
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | m_minWidth += rect.width(); |
|
113 | m_minHeight = qMax(rect.height(), m_minHeight); | |
|
113 | m_minHeight = qMax(rect.height()+ label_padding, m_minHeight); | |
|
114 | 114 | |
|
115 | 115 | if ((i + 1) % 2 && i > 1) { |
|
116 | 116 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i / 2 - 1)); |
@@ -26,7 +26,6 | |||
|
26 | 26 | #include <QFontMetrics> |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | ||
|
30 | 29 | static int label_padding = 5; |
|
31 | 30 | |
|
32 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -69,7 +68,9 void ChartCategoryAxisY::updateGeometry() | |||
|
69 | 68 | m_minWidth = 0; |
|
70 | 69 | m_minHeight = 0; |
|
71 | 70 | |
|
72 |
if(layout.isEmpty()) |
|
|
71 | if(layout.isEmpty()) { | |
|
72 | return; | |
|
73 | } | |
|
73 | 74 | |
|
74 | 75 | QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis); |
|
75 | 76 |
@@ -52,6 +52,7 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartEleme | |||
|
52 | 52 | |
|
53 | 53 | QGraphicsSimpleTextItem item; |
|
54 | 54 | m_font = item.font(); |
|
55 | ||
|
55 | 56 | } |
|
56 | 57 | |
|
57 | 58 | ChartAxis::~ChartAxis() |
@@ -20,8 +20,8 | |||
|
20 | 20 | |
|
21 | 21 | #include "chartlayout_p.h" |
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | #include "qlegend_p.h" | |
|
23 | 24 | #include "chartaxis_p.h" |
|
24 | #include <QDebug> | |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
@@ -30,7 +30,8 m_presenter(presenter), | |||
|
30 | 30 | m_marginBig(60), |
|
31 | 31 | m_marginSmall(20), |
|
32 | 32 | m_marginTiny(10), |
|
33 | m_chartMargins(QPointF(m_marginBig,m_marginBig),QPointF(m_marginBig,m_marginBig)) | |
|
33 | m_chartMargins(QPointF(m_marginBig,m_marginBig),QPointF(m_marginBig,m_marginBig)), | |
|
34 | m_intialized(false) | |
|
34 | 35 | { |
|
35 | 36 | |
|
36 | 37 | } |
@@ -47,6 +48,11 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
47 | 48 | |
|
48 | 49 | QGraphicsLayout::setGeometry(rect); |
|
49 | 50 | |
|
51 | if(!m_intialized){ | |
|
52 | m_presenter->setGeometry(rect); | |
|
53 | m_intialized=true; | |
|
54 | } | |
|
55 | ||
|
50 | 56 | // check title size |
|
51 | 57 | |
|
52 | 58 | QSize titleSize = QSize(0,0); |
@@ -69,12 +75,14 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
69 | 75 | |
|
70 | 76 | QLegend* legend = m_presenter->legend(); |
|
71 | 77 | |
|
78 | Q_ASSERT(legend); | |
|
79 | ||
|
72 | 80 | qreal titlePadding = m_chartMargins.top()/2; |
|
73 | 81 | |
|
74 | 82 | QRectF chartMargins = m_chartMargins; |
|
75 | 83 | |
|
76 | 84 | // recalculate legend position |
|
77 | if (legend != 0 && legend->isVisible() && legend->isAttachedToChart()) { | |
|
85 | if ((legend->isAttachedToChart() && legend->isVisible())) { | |
|
78 | 86 | |
|
79 | 87 | // Reserve some space for legend |
|
80 | 88 | switch (legend->alignment()) { |
@@ -89,7 +97,7 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
89 | 97 | } |
|
90 | 98 | case Qt::AlignBottom: { |
|
91 | 99 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(rect.width(),-1)); |
|
92 |
int bottomMargin = m_marginTiny + |
|
|
100 | int bottomMargin = m_marginTiny + legendSize.height() + m_marginTiny + axisHeight; | |
|
93 | 101 | chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomMargin)); |
|
94 | 102 | m_legendMargins = QRect(QPoint(chartMargins.left(),rect.height()-bottomMargin + m_marginTiny + axisHeight),QPoint(chartMargins.right(),m_marginTiny + m_marginSmall)); |
|
95 | 103 | titlePadding = chartMargins.top()/2; |
@@ -97,7 +105,8 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
97 | 105 | } |
|
98 | 106 | case Qt::AlignLeft: { |
|
99 | 107 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height())); |
|
100 |
int leftPadding = m_marginTiny |
|
|
108 | int leftPadding = m_marginTiny + legendSize.width() + m_marginTiny + axisWidth; | |
|
109 | ||
|
101 | 110 | chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); |
|
102 | 111 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,chartMargins.top()),QPoint(rect.width()-leftPadding + m_marginTiny + axisWidth,chartMargins.bottom())); |
|
103 | 112 | titlePadding = chartMargins.top()/2; |
@@ -105,7 +114,7 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
105 | 114 | } |
|
106 | 115 | case Qt::AlignRight: { |
|
107 | 116 | QSizeF legendSize = legend->effectiveSizeHint(Qt::PreferredSize,QSizeF(-1,rect.height())); |
|
108 |
int rightPadding = m_marginTiny |
|
|
117 | int rightPadding = m_marginTiny + legendSize.width() + m_marginTiny; | |
|
109 | 118 | chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); |
|
110 | 119 | m_legendMargins = QRect(QPoint(rect.width()- rightPadding+ m_marginTiny ,chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,chartMargins.bottom())); |
|
111 | 120 | titlePadding = chartMargins.top()/2; |
@@ -137,7 +146,6 void ChartLayout::setGeometry(const QRectF& rect) | |||
|
137 | 146 | }else if(chartRect.size().isEmpty()){ |
|
138 | 147 | m_presenter->setGeometry(QRect(rect.width()/2,rect.height()/2,1,1)); |
|
139 | 148 | } |
|
140 | ||
|
141 | 149 | } |
|
142 | 150 | |
|
143 | 151 |
@@ -50,10 +50,9 private: | |||
|
50 | 50 | int m_marginBig; |
|
51 | 51 | int m_marginSmall; |
|
52 | 52 | int m_marginTiny; |
|
53 | ||
|
54 | 53 | QRectF m_chartMargins; |
|
55 | 54 | QRectF m_legendMargins; |
|
56 | ||
|
55 | bool m_intialized; | |
|
57 | 56 | |
|
58 | 57 | |
|
59 | 58 | }; |
@@ -22,7 +22,6 | |||
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "legendmarker_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | #include <QDebug> | |
|
26 | 25 | |
|
27 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 27 | |
@@ -86,15 +85,17 QPointF LegendLayout::offset() const | |||
|
86 | 85 | |
|
87 | 86 | void LegendLayout::setGeometry(const QRectF& rect) |
|
88 | 87 | { |
|
89 | ||
|
90 | QGraphicsLayout::setGeometry(rect); | |
|
88 | m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); | |
|
91 | 89 | |
|
92 | 90 | if(m_legend->isAttachedToChart()) { |
|
91 | ||
|
93 | 92 | setAttachedGeometry(rect); |
|
94 | 93 | } |
|
95 | 94 | else { |
|
96 | 95 | setDettachedGeometry(rect); |
|
97 | 96 | } |
|
97 | ||
|
98 | QGraphicsLayout::setGeometry(rect); | |
|
98 | 99 | } |
|
99 | 100 | |
|
100 | 101 | void LegendLayout::setAttachedGeometry(const QRectF& rect) |
@@ -403,8 +403,8 bool QLegend::isBackgroundVisible() const | |||
|
403 | 403 | */ |
|
404 | 404 | void QLegend::hideEvent(QHideEvent *event) |
|
405 | 405 | { |
|
406 | QGraphicsWidget::hideEvent(event); | |
|
407 | d_ptr->m_presenter->layout()->invalidate(); | |
|
406 | d_ptr->m_presenter->layout()->invalidate(); | |
|
407 | QGraphicsWidget::hideEvent(event); | |
|
408 | 408 | } |
|
409 | 409 | |
|
410 | 410 | /*! |
@@ -412,8 +412,8 void QLegend::hideEvent(QHideEvent *event) | |||
|
412 | 412 | */ |
|
413 | 413 | void QLegend::showEvent(QShowEvent *event) |
|
414 | 414 | { |
|
415 | QGraphicsWidget::showEvent(event); | |
|
416 | d_ptr->m_presenter->layout()->invalidate(); | |
|
415 | d_ptr->m_presenter->layout()->invalidate(); | |
|
416 | QGraphicsWidget::showEvent(event); | |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
General Comments 0
You need to be logged in to leave comments.
Login now