##// END OF EJS Templates
Added Vertical and Horizontal QXYModelMapper
Marek Rosa -
r1252:4e92004ccd6b
parent child
Show More
@@ -0,0 +1,32
1 #include "qhxymodelmapper.h"
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
6 QXYModelMapper(parent)
7 {
8 }
9
10 int QHXYModelMapper::xRow() const
11 {
12 return QXYModelMapper::xSection();
13 }
14
15 void QHXYModelMapper::setXRow(int xRow)
16 {
17 return QXYModelMapper::setXSection(xRow);
18 }
19
20 int QHXYModelMapper::yRow() const
21 {
22 return QXYModelMapper::ySection();
23 }
24
25 void QHXYModelMapper::setYRow(int yRow)
26 {
27 return QXYModelMapper::setYSection(yRow);
28 }
29
30 #include "moc_qhxymodelmapper.cpp"
31
32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,27
1 #ifndef QHXYMODELMAPPER_H
2 #define QHXYMODELMAPPER_H
3
4 #include <QXYModelMapper>
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8 class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper
9 {
10 Q_OBJECT
11 Q_PROPERTY(int xRow READ xRow WRITE setXRow)
12 Q_PROPERTY(int yRow READ yRow WRITE setYRow)
13
14 public:
15 explicit QHXYModelMapper(QObject *parent = 0);
16
17 int xRow() const;
18 void setXRow(int xRow);
19
20 int yRow() const;
21 void setYRow(int yRow);
22
23 };
24
25 QTCOMMERCIALCHART_END_NAMESPACE
26
27 #endif // QHXYMODELMAPPER_H
@@ -0,0 +1,32
1 #include "qvxymodelmapper.h"
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
6 QXYModelMapper(parent)
7 {
8 }
9
10 int QVXYModelMapper::xColumn() const
11 {
12 return QXYModelMapper::xSection();
13 }
14
15 void QVXYModelMapper::setXColumn(int xColumn)
16 {
17 return QXYModelMapper::setXSection(xColumn);
18 }
19
20 int QVXYModelMapper::yColumn() const
21 {
22 return QXYModelMapper::ySection();
23 }
24
25 void QVXYModelMapper::setYColumn(int yColumn)
26 {
27 return QXYModelMapper::setYSection(yColumn);
28 }
29
30 #include "moc_qvxymodelmapper.cpp"
31
32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,27
1 #ifndef QVXYMODELMAPPER_H
2 #define QVXYMODELMAPPER_H
3
4 #include <QXYModelMapper>
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8 class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper
9 {
10 Q_OBJECT
11 Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn)
12 Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn)
13
14 public:
15 explicit QVXYModelMapper(QObject *parent = 0);
16
17 int xColumn() const;
18 void setXColumn(int xColumn);
19
20 int yColumn() const;
21 void setYColumn(int yColumn);
22
23 };
24
25 QTCOMMERCIALCHART_END_NAMESPACE
26
27 #endif // QVXYMODELMAPPER_H
@@ -101,8 +101,9 void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoi
101 {
101 {
102 // qDebug() << "DeclarativeTableModel::appendPoint:" << point;
102 // qDebug() << "DeclarativeTableModel::appendPoint:" << point;
103 QVariantList values;
103 QVariantList values;
104 values.insert(mapper->mapX(), point->x());
104 // TODO: XYModelMapper implementation has change, this code has to be updated.
105 values.insert(mapper->mapY(), point->y());
105 // values.insert(mapper->mapX(), point->x());
106 // values.insert(mapper->mapY(), point->y());
106 append(values);
107 append(values);
107 }
108 }
108
109
@@ -29,15 +29,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 DeclarativeXySeries::DeclarativeXySeries()
30 DeclarativeXySeries::DeclarativeXySeries()
31 {
31 {
32 // TODO: XYModelMapper implementation has changed, this code has to be updated
33
32 // All the inherited objects must be of type QXYSeries, so it is safe to cast
34 // All the inherited objects must be of type QXYSeries, so it is safe to cast
33 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
35 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
34 // TODO: mapper should be available on the series by default
36 // // TODO: mapper should be available on the series by default
35 QXYModelMapper *mapper = new QXYModelMapper(series);
37 // QXYModelMapper *mapper = new QXYModelMapper(series);
36 mapper->setMapX(0);
38 // mapper->setMapX(0);
37 mapper->setMapY(1);
39 // mapper->setMapY(1);
38 mapper->setFirst(0);
40 // mapper->setFirst(0);
39 mapper->setCount(-1);
41 // mapper->setCount(-1);
40 mapper->setOrientation(Qt::Vertical);
42 // mapper->setOrientation(Qt::Vertical);
41 // series->setModelMapper(mapper);
43 // series->setModelMapper(mapper);
42 }
44 }
43
45
@@ -46,20 +46,19 QPieSeries* QPieModelMapper::series() const
46
46
47 void QPieModelMapper::setSeries(QPieSeries *series)
47 void QPieModelMapper::setSeries(QPieSeries *series)
48 {
48 {
49 if (series == 0)
50 return;
51
52 Q_D(QPieModelMapper);
49 Q_D(QPieModelMapper);
53 if (d->m_series) {
50 if (d->m_series) {
54 disconnect(d->m_series, 0, d, 0);
51 disconnect(d->m_series, 0, d, 0);
55 }
52 }
56
53
54 if (series == 0)
55 return;
56
57 d->m_series = series;
57 d->m_series = series;
58 d->initializePieFromModel();
58 d->initializePieFromModel();
59 // connect the signals from the series
59 // connect the signals from the series
60 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
60 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
61 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
61 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
62 // connect(d->m_model, SIGNAL(), d, SLOT());
63 }
62 }
64
63
65 int QPieModelMapper::first() const
64 int QPieModelMapper::first() const
@@ -7,8 +7,8 QXYModelMapper::QXYModelMapper(QObject *parent):
7 m_first(0),
7 m_first(0),
8 m_count(-1),
8 m_count(-1),
9 m_orientation(Qt::Vertical),
9 m_orientation(Qt::Vertical),
10 m_mapX(-1),
10 m_xSection(-1),
11 m_mapY(-1)
11 m_ySection(-1)
12 {
12 {
13 }
13 }
14
14
@@ -20,7 +20,7 int QXYModelMapper::first() const
20 void QXYModelMapper::setFirst(int first)
20 void QXYModelMapper::setFirst(int first)
21 {
21 {
22 m_first = qMax(first, 0);
22 m_first = qMax(first, 0);
23 emit updated();
23 // emit updated();
24 }
24 }
25
25
26 int QXYModelMapper::count() const
26 int QXYModelMapper::count() const
@@ -31,7 +31,7 int QXYModelMapper::count() const
31 void QXYModelMapper::setCount(int count)
31 void QXYModelMapper::setCount(int count)
32 {
32 {
33 m_count = qMax(count, -1);
33 m_count = qMax(count, -1);
34 emit updated();
34 // emit updated();
35 }
35 }
36
36
37 Qt::Orientation QXYModelMapper::orientation() const
37 Qt::Orientation QXYModelMapper::orientation() const
@@ -42,29 +42,29 Qt::Orientation QXYModelMapper::orientation() const
42 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
42 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
43 {
43 {
44 m_orientation = orientation;
44 m_orientation = orientation;
45 emit updated();
45 // emit updated();
46 }
46 }
47
47
48 int QXYModelMapper::mapX() const
48 int QXYModelMapper::xSection() const
49 {
49 {
50 return m_mapX;
50 return m_xSection;
51 }
51 }
52
52
53 void QXYModelMapper::setMapX(int mapX)
53 void QXYModelMapper::setXSection(int xSection)
54 {
54 {
55 m_mapX = mapX;
55 m_xSection = xSection;
56 emit updated();
56 // emit updated();
57 }
57 }
58
58
59 int QXYModelMapper::mapY() const
59 int QXYModelMapper::ySection() const
60 {
60 {
61 return m_mapY;
61 return m_ySection;
62 }
62 }
63
63
64 void QXYModelMapper::setMapY(int mapY)
64 void QXYModelMapper::setYSection(int ySection)
65 {
65 {
66 m_mapY = mapY;
66 m_ySection = ySection;
67 emit updated();
67 // emit updated();
68 }
68 }
69
69
70 void QXYModelMapper::reset()
70 void QXYModelMapper::reset()
@@ -72,8 +72,8 void QXYModelMapper::reset()
72 m_first = 0;
72 m_first = 0;
73 m_count = -1;
73 m_count = -1;
74 m_orientation = Qt::Vertical;
74 m_orientation = Qt::Vertical;
75 m_mapX = -1;
75 m_xSection = -1;
76 m_mapY = -1;
76 m_ySection = -1;
77 }
77 }
78
78
79 #include "moc_qxymodelmapper.cpp"
79 #include "moc_qxymodelmapper.cpp"
@@ -9,30 +9,31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject
9 class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject
10 {
10 {
11 Q_OBJECT
11 Q_OBJECT
12 Q_PROPERTY(int mapX READ mapX WRITE setMapX)
12 Q_PROPERTY(int xSection READ xSection WRITE setXSection)
13 Q_PROPERTY(int mapY READ mapY WRITE setMapY)
13 Q_PROPERTY(int ySection READ ySection WRITE setYSection)
14 Q_PROPERTY(int first READ first WRITE setFirst)
14 Q_PROPERTY(int first READ first WRITE setFirst)
15 Q_PROPERTY(int count READ count WRITE setCount)
15 Q_PROPERTY(int count READ count WRITE setCount)
16 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
16 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
17 Q_ENUMS(Qt::Orientation)
17 Q_ENUMS(Qt::Orientation)
18
18
19 public:
19 public:
20 explicit QXYModelMapper(QObject *parent = 0);
21
22 int first() const;
20 int first() const;
23 void setFirst(int first);
21 void setFirst(int first);
24
22
25 int count() const;
23 int count() const;
26 void setCount(int count);
24 void setCount(int count);
27
25
26 protected:
27 explicit QXYModelMapper(QObject *parent = 0);
28
28 Qt::Orientation orientation() const;
29 Qt::Orientation orientation() const;
29 void setOrientation(Qt::Orientation orientation);
30 void setOrientation(Qt::Orientation orientation);
30
31
31 int mapX() const;
32 int xSection() const;
32 void setMapX(int mapX);
33 void setXSection(int xSection);
33
34
34 int mapY() const;
35 int ySection() const;
35 void setMapY(int mapY);
36 void setYSection(int ySection);
36
37
37 void reset();
38 void reset();
38
39
@@ -43,8 +44,8 private:
43 int m_first;
44 int m_first;
44 int m_count;
45 int m_count;
45 Qt::Orientation m_orientation;
46 Qt::Orientation m_orientation;
46 int m_mapX;
47 int m_xSection;
47 int m_mapY;
48 int m_ySection;
48 };
49 };
49
50
50 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -4,7 +4,9 DEPENDPATH += $$PWD
4 SOURCES += \
4 SOURCES += \
5 $$PWD/xychart.cpp \
5 $$PWD/xychart.cpp \
6 $$PWD/qxyseries.cpp \
6 $$PWD/qxyseries.cpp \
7 $$PWD/qxymodelmapper.cpp
7 $$PWD/qxymodelmapper.cpp \
8 $$PWD/qvxymodelmapper.cpp \
9 $$PWD/qhxymodelmapper.cpp
8
10
9 PRIVATE_HEADERS += \
11 PRIVATE_HEADERS += \
10 $$PWD/xychart_p.h \
12 $$PWD/xychart_p.h \
@@ -13,4 +15,7 PRIVATE_HEADERS += \
13
15
14 PUBLIC_HEADERS += \
16 PUBLIC_HEADERS += \
15 $$PWD/qxyseries.h \
17 $$PWD/qxyseries.h \
16 $$PWD/qxymodelmapper.h
18 $$PWD/qxymodelmapper.h \
19 $$PWD/qvxymodelmapper.h \
20 $$PWD/qhxymodelmapper.h
21
@@ -253,12 +253,15 void tst_piemodelmapper::seriesUpdated()
253 mapper->setModel(otherModel);
253 mapper->setModel(otherModel);
254 mapper->setSeries(m_series);
254 mapper->setSeries(m_series);
255 QCOMPARE(m_series->count(), m_modelRowCount);
255 QCOMPARE(m_series->count(), m_modelRowCount);
256 QCOMPARE(mapper->count(), -1);
256
257
257 m_series->append("1000", 1000);
258 m_series->append("1000", 1000);
258 QCOMPARE(m_series->count(), m_modelRowCount + 1);
259 QCOMPARE(m_series->count(), m_modelRowCount + 1);
260 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
259
261
260 m_series->remove(m_series->slices().last());
262 m_series->remove(m_series->slices().last());
261 QCOMPARE(m_series->count(), m_modelRowCount);
263 QCOMPARE(m_series->count(), m_modelRowCount);
264 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
262
265
263 otherModel->clear();
266 otherModel->clear();
264 delete otherModel;
267 delete otherModel;
General Comments 0
You need to be logged in to leave comments. Login now