##// END OF EJS Templates
Refactor , move dataset legend presentr connections to one place
Michal Klocek -
r871:b32d31ef1d27
parent child
Show More
@@ -83,8 +83,8 m_index(-1),m_chart(chart)
83 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
83 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
84 }
84 }
85 //![4]
85 //![4]
86 QTimer::singleShot(0,this,SLOT(handleTimeout()));
87 m_timer.start();
86 m_timer.start();
87 handleTimeout();
88 }
88 }
89
89
90 ChartView::~ChartView()
90 ChartView::~ChartView()
@@ -64,7 +64,6 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char
64 m_marginTiny(10),
64 m_marginTiny(10),
65 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
65 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
66 {
66 {
67 createConnections();
68 }
67 }
69
68
70 ChartPresenter::~ChartPresenter()
69 ChartPresenter::~ChartPresenter()
@@ -72,14 +71,6 ChartPresenter::~ChartPresenter()
72 delete m_chartTheme;
71 delete m_chartTheme;
73 }
72 }
74
73
75 void ChartPresenter::createConnections()
76 {
77 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
78 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
79 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
80 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
81 }
82
83 void ChartPresenter::setGeometry(const QRectF& rect)
74 void ChartPresenter::setGeometry(const QRectF& rect)
84 {
75 {
85 m_rect = rect;
76 m_rect = rect;
@@ -506,12 +497,14 void ChartPresenter::updateLayout()
506
497
507 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
498 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
508
499
500 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
501
509 if(m_chartRect!=chartRect){
502 if(m_chartRect!=chartRect){
510 m_chartRect=chartRect;
503 m_chartRect=chartRect;
511 emit geometryChanged(m_chartRect);
504 emit geometryChanged(m_chartRect);
512 }
505 }
513
506
514 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
507
515 }
508 }
516
509
517 void ChartPresenter::createChartBackgroundItem()
510 void ChartPresenter::createChartBackgroundItem()
@@ -81,7 +81,6 public:
81 qreal minimumBottomMargin() const { return m_minBottomMargin; }
81 qreal minimumBottomMargin() const { return m_minBottomMargin; }
82
82
83 public: //TODO: fix me
83 public: //TODO: fix me
84 void createConnections();
85 void resetAllElements();
84 void resetAllElements();
86 void createChartBackgroundItem();
85 void createChartBackgroundItem();
87 void createChartTitleItem();
86 void createChartTitleItem();
@@ -72,9 +72,8 d_ptr(new QChartPrivate())
72 d_ptr->m_dataset = new ChartDataSet(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
75 d_ptr->createConnections();
75 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
76 //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3);
76 connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
77 connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*)));
78 }
77 }
79
78
80 /*!
79 /*!
@@ -346,6 +345,16 QChartPrivate::~QChartPrivate()
346
345
347 }
346 }
348
347
348 void QChartPrivate::createConnections()
349 {
350 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*)));
351 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*)));
352 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*)));
353 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*)));
354 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
355 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*)));
356 }
357
349 #include "moc_qchart.cpp"
358 #include "moc_qchart.cpp"
350
359
351 QTCOMMERCIALCHART_END_NAMESPACE
360 QTCOMMERCIALCHART_END_NAMESPACE
@@ -47,6 +47,8 struct QChartPrivate
47 ChartDataSet *m_dataset;
47 ChartDataSet *m_dataset;
48 ChartPresenter *m_presenter;
48 ChartPresenter *m_presenter;
49
49
50 void createConnections();
51
50 };
52 };
51
53
52 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
@@ -100,8 +100,7 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
100 m_minHeight(0),
100 m_minHeight(0),
101 m_width(0),
101 m_width(0),
102 m_height(0),
102 m_height(0),
103 m_visible(false),
103 m_visible(false)
104 m_dirty(false)
105 {
104 {
106 setZValue(ChartPresenter::LegendZValue);
105 setZValue(ChartPresenter::LegendZValue);
107 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
106 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
@@ -247,11 +246,7 void QLegend::handleSeriesAdded(QSeries *series, Domain *domain)
247 }
246 }
248 }
247 }
249
248
250 // wait for all series added
249 updateLayout();
251 if(!m_dirty){
252 QTimer::singleShot(0,this,SLOT(updateLayout()));
253 m_dirty=true;
254 }
255 }
250 }
256
251
257 /*!
252 /*!
@@ -428,7 +423,6 QPointF QLegend::offset() const
428 // this function runs first to set min max values
423 // this function runs first to set min max values
429 void QLegend::updateLayout()
424 void QLegend::updateLayout()
430 {
425 {
431 m_dirty=false;
432 m_offsetX=0;
426 m_offsetX=0;
433 QList<QGraphicsItem *> items = m_markers->childItems();
427 QList<QGraphicsItem *> items = m_markers->childItems();
434
428
@@ -106,11 +106,6 private:
106 void appendMarkers(QBarSeries *series);
106 void appendMarkers(QBarSeries *series);
107 void appendMarkers(QPieSeries *series);
107 void appendMarkers(QPieSeries *series);
108 void deleteMarkers(QSeries *series);
108 void deleteMarkers(QSeries *series);
109
110
111
112
113 private Q_SLOTS:
114 void updateLayout();
109 void updateLayout();
115
110
116 private:
111 private:
@@ -136,7 +131,6 private:
136 qreal m_width;
131 qreal m_width;
137 qreal m_height;
132 qreal m_height;
138 bool m_visible;
133 bool m_visible;
139 bool m_dirty;
140 friend class ScrolledQLegend;
134 friend class ScrolledQLegend;
141 // <--- PIMPL
135 // <--- PIMPL
142 };
136 };
General Comments 0
You need to be logged in to leave comments. Login now