@@ -37,6 +37,7 Rectangle { | |||
|
37 | 37 | |
|
38 | 38 | PieSeries { |
|
39 | 39 | id: wheelOfFortune |
|
40 | horizontalPosition: 0.3 | |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | SplineSeries { |
@@ -48,9 +48,9 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, | |||
|
48 | 48 | if (role != Qt::DisplayRole) |
|
49 | 49 | return QVariant(); |
|
50 | 50 | |
|
51 |
if (orientation == Qt:: |
|
|
52 |
if (m_ |
|
|
53 |
return m_ |
|
|
51 | if (orientation == Qt::Vertical) { | |
|
52 | if (m_verticalHeaders.count() > section) | |
|
53 | return m_verticalHeaders[section]; | |
|
54 | 54 | else |
|
55 | 55 | return QAbstractTableModel::headerData(section, orientation, role); |
|
56 | 56 | } else { |
@@ -60,10 +60,10 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, | |||
|
60 | 60 | |
|
61 | 61 | bool CustomTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) |
|
62 | 62 | { |
|
63 |
if (orientation == Qt:: |
|
|
64 |
while (m_ |
|
|
65 |
m_ |
|
|
66 |
m_ |
|
|
63 | if (orientation == Qt::Vertical) { | |
|
64 | while (m_verticalHeaders.count() <= section) | |
|
65 | m_verticalHeaders.append(QVariant()); | |
|
66 | m_verticalHeaders.replace(section, value); | |
|
67 | 67 | } else { |
|
68 | 68 | return QAbstractTableModel::setHeaderData(section, orientation, value, role); |
|
69 | 69 | } |
@@ -48,7 +48,7 public: | |||
|
48 | 48 | |
|
49 | 49 | private: |
|
50 | 50 | QList<QVector<QVariant> * > m_data; |
|
51 |
QList<QVariant> m_ |
|
|
51 | QList<QVariant> m_verticalHeaders; | |
|
52 | 52 | int m_columnCount; |
|
53 | 53 | int m_rowCount; |
|
54 | 54 | }; |
@@ -20,6 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "declarativemodel.h" |
|
22 | 22 | #include <qdeclarativelist.h> |
|
23 | #include <QStringList> | |
|
23 | 24 | #include <QDebug> |
|
24 | 25 | |
|
25 | 26 | ////////////// Table model element /////////////////// |
@@ -29,16 +30,6 DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent) | |||
|
29 | 30 | { |
|
30 | 31 | } |
|
31 | 32 | |
|
32 | QString DeclarativeTableModelElement::rowHeader() | |
|
33 | { | |
|
34 | return m_rowHeader; | |
|
35 | } | |
|
36 | ||
|
37 | void DeclarativeTableModelElement::setRowHeader(QString header) | |
|
38 | { | |
|
39 | m_rowHeader = header; | |
|
40 | } | |
|
41 | ||
|
42 | 33 | QVariantList DeclarativeTableModelElement::values() |
|
43 | 34 | { |
|
44 | 35 | return m_values; |
@@ -66,11 +57,21 void DeclarativeTableModel::componentComplete() | |||
|
66 | 57 | if (qobject_cast<DeclarativeTableModelElement *>(child)) { |
|
67 | 58 | DeclarativeTableModelElement *element = qobject_cast<DeclarativeTableModelElement *>(child); |
|
68 | 59 | append(element->values()); |
|
69 | setHeaderData(rowCount() - 1, Qt::Horizontal, element->rowHeader()); | |
|
70 | 60 | } |
|
71 | 61 | } |
|
72 | 62 | } |
|
73 | 63 | |
|
64 | void DeclarativeTableModel::setVerticalHeaders(QStringList headers) | |
|
65 | { | |
|
66 | for (int i(0); i < headers.count(); i++) | |
|
67 | setHeaderData(i, Qt::Vertical, headers.at(i)); | |
|
68 | } | |
|
69 | ||
|
70 | QStringList DeclarativeTableModel::verticalHeaders() | |
|
71 | { | |
|
72 | return QStringList(); | |
|
73 | } | |
|
74 | ||
|
74 | 75 | QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren() |
|
75 | 76 | { |
|
76 | 77 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild); |
@@ -29,17 +29,13 | |||
|
29 | 29 | class DeclarativeTableModelElement : public QObject |
|
30 | 30 | { |
|
31 | 31 | Q_OBJECT |
|
32 | Q_PROPERTY(QString rowHeader READ rowHeader WRITE setRowHeader) | |
|
33 | 32 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
34 | 33 | |
|
35 | 34 | public: |
|
36 | 35 | explicit DeclarativeTableModelElement(QObject *parent = 0); |
|
37 | QString rowHeader(); | |
|
38 | void setRowHeader(QString header); | |
|
39 | 36 | QVariantList values(); |
|
40 | 37 | void setValues(QVariantList values); |
|
41 | 38 | private: |
|
42 | QString m_rowHeader; | |
|
43 | 39 | QVariantList m_values; |
|
44 | 40 | }; |
|
45 | 41 | |
@@ -48,11 +44,14 class DeclarativeTableModel : public CustomTableModel, public QDeclarativeParser | |||
|
48 | 44 | Q_OBJECT |
|
49 | 45 | Q_INTERFACES(QDeclarativeParserStatus) |
|
50 | 46 | Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren) |
|
47 | Q_PROPERTY(QStringList verticalHeaders READ verticalHeaders WRITE setVerticalHeaders) | |
|
51 | 48 | Q_CLASSINFO("DefaultProperty", "modelChildren") |
|
52 | 49 | |
|
53 | 50 | public: |
|
54 | 51 | explicit DeclarativeTableModel(QObject *parent = 0); |
|
55 | 52 | QDeclarativeListProperty<QObject> modelChildren(); |
|
53 | void setVerticalHeaders(QStringList headers); | |
|
54 | QStringList verticalHeaders(); | |
|
56 | 55 | |
|
57 | 56 | public: // from QDeclarativeParserStatus |
|
58 | 57 | void classBegin(); |
@@ -42,13 +42,14 Rectangle { | |||
|
42 | 42 | //![2] |
|
43 | 43 | CustomModel { |
|
44 | 44 | id: customModel |
|
45 | CustomModelElement { rowHeader: ""; values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
|
46 |
CustomModelElement { |
|
|
47 |
CustomModelElement { |
|
|
48 |
CustomModelElement { |
|
|
49 |
CustomModelElement { |
|
|
50 |
CustomModelElement { |
|
|
51 |
CustomModelElement { |
|
|
45 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] | |
|
46 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
|
47 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } | |
|
48 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } | |
|
49 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } | |
|
50 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } | |
|
51 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } | |
|
52 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } | |
|
52 | 53 | } |
|
53 | 54 | //![2] |
|
54 | 55 |
|
1 | NO CONTENT: modified file, binary diff hidden |
General Comments 0
You need to be logged in to leave comments.
Login now