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