##// END OF EJS Templates
Implemented QPieSeries::take()
Implemented QPieSeries::take()

File last commit:

r1395:33102af7bf20
r1798:4447e4e83da1
Show More
customtablemodel.cpp
136 lines | 3.8 KiB | text/x-c | CppLexer
Tero Ahola
Draft version for QML PieSeries model API
r1130 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 #include "customtablemodel.h"
Tero Ahola
Draft version for QML PieSeries model API
r1130 #include <QVector>
#include <QRect>
#include <QColor>
Tero Ahola
Header data to QML custom model demo
r1387 #include <QDebug>
Tero Ahola
Draft version for QML PieSeries model API
r1130
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 CustomTableModel::CustomTableModel(QObject *parent) :
Tero Ahola
Fixed QML pie model mapper API
r1265 QAbstractTableModel(parent),
m_columnCount(0),
m_rowCount(0)
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 int CustomTableModel::rowCount(const QModelIndex & parent) const
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
Q_UNUSED(parent)
return m_data.count();
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 int CustomTableModel::columnCount(const QModelIndex & parent) const
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
Q_UNUSED(parent)
return m_columnCount;
}
Tero Ahola
Header data to QML custom model demo
r1387 QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
if (role != Qt::DisplayRole)
return QVariant();
Tero Ahola
Fixed Qml Custom Model demo header data
r1395 if (orientation == Qt::Vertical) {
if (m_verticalHeaders.count() > section)
return m_verticalHeaders[section];
Tero Ahola
Draft version for QML PieSeries model API
r1130 else
Tero Ahola
Header data to QML custom model demo
r1387 return QAbstractTableModel::headerData(section, orientation, role);
Tero Ahola
Added declarative model for bar series
r1162 } else {
Tero Ahola
Header data to QML custom model demo
r1387 return QAbstractTableModel::headerData(section, orientation, role);
Tero Ahola
Added declarative model for bar series
r1162 }
Tero Ahola
Draft version for QML PieSeries model API
r1130 }
Tero Ahola
Header data to QML custom model demo
r1387 bool CustomTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
{
Tero Ahola
Fixed Qml Custom Model demo header data
r1395 if (orientation == Qt::Vertical) {
while (m_verticalHeaders.count() <= section)
m_verticalHeaders.append(QVariant());
m_verticalHeaders.replace(section, value);
Tero Ahola
Header data to QML custom model demo
r1387 } else {
return QAbstractTableModel::setHeaderData(section, orientation, value, role);
}
emit headerDataChanged(orientation, section, section);
return true;
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 QVariant CustomTableModel::data(const QModelIndex &index, int role) const
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
if (role == Qt::DisplayRole) {
return m_data[index.row()]->at(index.column());
} else if (role == Qt::EditRole) {
return m_data[index.row()]->at(index.column());
}
return QVariant();
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
if (index.isValid() && role == Qt::EditRole) {
m_data[index.row()]->replace(index.column(), value);
emit dataChanged(index, index);
return true;
}
return false;
}
Tero Ahola
Removed DeclarativePieSlice; properties in QPieSlice now
r1329 QVariant CustomTableModel::at(int row, int column)
{
return data(index(row, column));
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 void CustomTableModel::insertColumn(int column, const QModelIndex &parent)
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
Tero Ahola
Now using only one declarative model
r1169 beginInsertColumns(parent, column, column);
m_columnCount++;
endInsertColumns();
}
Tero Ahola
Draft version for QML PieSeries model API
r1130
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 void CustomTableModel::insertRow(int row, const QModelIndex &parent)
Tero Ahola
Now using only one declarative model
r1169 {
beginInsertRows(parent, row, row);
Tero Ahola
Draft version for QML PieSeries model API
r1130 QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount);
m_data.insert(row, dataVec);
endInsertRows();
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 bool CustomTableModel::removeRow(int row, const QModelIndex &parent)
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
return QAbstractTableModel::removeRow(row, parent);
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 bool CustomTableModel::removeRows(int row, int count, const QModelIndex &parent)
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
beginRemoveRows(parent, row, row + count - 1);
bool removed(false);
for (int i(row); i < (row + count); i++) {
m_data.removeAt(i);
removed = true;
}
endRemoveRows();
return removed;
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
Tero Ahola
Draft version for QML PieSeries model API
r1130 {
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
Tero Ahola
QML custom model demo now implements it's own QAbstractItemModel based model
r1272 #include "moc_customtablemodel.cpp"