31 if(sourceModel==m_sourceModel) {
37 disconnect(m_sourceModel, SIGNAL(destroyed(
QObject*)),
38 this, SLOT(sourceDestroyed(
QObject*)));
40 disconnect(m_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
41 this, SLOT(considerDataChanged(QModelIndex,QModelIndex)));
42 disconnect(m_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,
int,
int)),
43 this, SLOT(considerRowsAboutToBeInserted(QModelIndex,
int,
int)));
44 disconnect(m_sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,
int,
int,QModelIndex,
int)),
45 this, SLOT(considerRowsAboutToBeMoved(QModelIndex,
int,
int,QModelIndex,
int)));
46 disconnect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,
int,
int)),
47 this, SLOT(considerRowsAboutToBeRemoved(QModelIndex,
int,
int)));
48 disconnect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,
int,
int)),
49 this, SLOT(considerRowsInserted(QModelIndex,
int,
int)));
50 disconnect(m_sourceModel, SIGNAL(rowsMoved(QModelIndex,
int,
int,QModelIndex,
int)),
51 this, SLOT(considerRowsMoved(QModelIndex,
int,
int,QModelIndex,
int)));
52 disconnect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
53 this, SLOT(considerRowsRemoved(QModelIndex,
int,
int)));
55 disconnect(m_sourceModel, SIGNAL(modelAboutToBeReset()),
56 this, SIGNAL(modelAboutToBeReset()));
57 disconnect(m_sourceModel, SIGNAL(modelReset()),
58 this, SIGNAL(modelReset()));
59 disconnect(m_sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,
int,
int)),
60 this, SIGNAL(headerDataChanged(Qt::Orientation,
int,
int)));
61 disconnect(m_sourceModel, SIGNAL(layoutAboutToBeChanged()),
62 this, SIGNAL(layoutAboutToBeChanged()));
63 disconnect(m_sourceModel, SIGNAL(layoutChanged()),
64 this, SIGNAL(layoutChanged()));
68 setRoleNames(m_sourceModel->roleNames());
69 connect(m_sourceModel, SIGNAL(destroyed(
QObject*)),
70 this, SLOT(sourceDestroyed(
QObject*)));
72 connect(m_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
73 this, SLOT(considerDataChanged(QModelIndex,QModelIndex)));
74 connect(m_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,
int,
int)),
75 this, SLOT(considerRowsAboutToBeInserted(QModelIndex,
int,
int)));
76 connect(m_sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,
int,
int,QModelIndex,
int)),
77 this, SLOT(considerRowsAboutToBeMoved(QModelIndex,
int,
int,QModelIndex,
int)));
78 connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,
int,
int)),
79 this, SLOT(considerRowsAboutToBeRemoved(QModelIndex,
int,
int)));
80 connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,
int,
int)),
81 this, SLOT(considerRowsInserted(QModelIndex,
int,
int)));
82 connect(m_sourceModel, SIGNAL(rowsMoved(QModelIndex,
int,
int,QModelIndex,
int)),
83 this, SLOT(considerRowsMoved(QModelIndex,
int,
int,QModelIndex,
int)));
84 connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,
int,
int)),
85 this, SLOT(considerRowsRemoved(QModelIndex,
int,
int)));
87 connect(m_sourceModel, SIGNAL(modelAboutToBeReset()),
88 this, SIGNAL(modelAboutToBeReset()));
89 connect(m_sourceModel, SIGNAL(modelReset()),
90 this, SIGNAL(modelReset()));
91 connect(m_sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,
int,
int)),
92 this, SIGNAL(headerDataChanged(Qt::Orientation,
int,
int)));
93 connect(m_sourceModel, SIGNAL(layoutAboutToBeChanged()),
94 this, SIGNAL(layoutAboutToBeChanged()));
95 connect(m_sourceModel, SIGNAL(layoutChanged()),
96 this, SIGNAL(layoutChanged()));
120 if(index.isValid()) {
132 return model ? model->index(row, column, parent) : QModelIndex();
137 return m_sourceModel ? m_sourceModel->data(sourceIndex(index), role) : QVariant();
142 return m_sourceModel ? m_sourceModel->headerData(section, orientation, role) : QVariant();
145 QModelIndex ColumnProxyModel::sourceIndex(
const QModelIndex& proxyIndex)
const
147 return m_sourceModel ? m_sourceModel->index(proxyIndex.row(), m_column, m_index) : QModelIndex();
152 return (!m_sourceModel || parent.isValid()) ? 0 : m_sourceModel->rowCount(m_index);
155 QModelIndex ColumnProxyModel::proxyIndex(
const QModelIndex& sourceIndex)
const
157 if(sourceIndex.parent()==m_index)
158 return index(sourceIndex.row(), sourceIndex.column(), QModelIndex());
160 return QModelIndex();
163 void ColumnProxyModel::sourceDestroyed(
QObject* source)
165 Q_ASSERT(source==m_sourceModel);
174 return m_sourceModel ? m_sourceModel->index(row, m_column, parent) : QModelIndex();
179 void ColumnProxyModel::considerDataChanged(
const QModelIndex& idxA,
const QModelIndex& idxB)
181 if(idxA.parent()==m_index && idxB.parent()==m_index) {
182 emit dataChanged(proxyIndex(idxA), proxyIndex(idxB));
186 void ColumnProxyModel::considerRowsAboutToBeInserted(
const QModelIndex& parent,
int rA,
int rB)
188 if(parent==m_index) {
189 beginInsertRows(QModelIndex(), rA, rB);
193 void ColumnProxyModel::considerRowsAboutToBeMoved(
const QModelIndex &sourceParent,
int rA,
int rB,
const QModelIndex& destParent,
int rD)
195 if(sourceParent==m_index && destParent==m_index) {
196 beginMoveRows(QModelIndex(), rA, rB, QModelIndex(), rD);
197 }
else if(sourceParent==m_index) {
198 beginRemoveRows(sourceParent, rA, rB);
199 }
else if(destParent==m_index) {
200 beginInsertRows(destParent, rD, rD+(rB-rA));
204 void ColumnProxyModel::considerRowsAboutToBeRemoved(
const QModelIndex& parent,
int rA,
int rB)
206 if(parent==m_index) {
207 beginRemoveRows(QModelIndex(), rA, rB);
211 void ColumnProxyModel::considerRowsInserted(
const QModelIndex& parent,
int ,
int )
213 if(parent==m_index) {
218 void ColumnProxyModel::considerRowsMoved(
const QModelIndex& sourceParent,
int ,
int ,
const QModelIndex& destParent,
int )
220 if(sourceParent==m_index && destParent==m_index) {
222 }
else if(sourceParent==m_index) {
224 }
else if(destParent==m_index) {
229 void ColumnProxyModel::considerRowsRemoved(
const QModelIndex& parent,
int ,
int )
231 if(parent==m_index) {
236 #include "columnproxymodel.moc"
void setSourceModel(QAbstractItemModel *sourceModel)
void setRootIndex(const QModelIndex &idx)
QModelIndex rootIndex() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Q_SCRIPTABLE QModelIndex indexAt(int row, const QModelIndex &parent=QModelIndex()) const
static Q_SCRIPTABLE QModelIndex indexFromModel(QAbstractItemModel *model, int row, int column=0, const QModelIndex &parent=QModelIndex())
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
ColumnProxyModel(QObject *parent=0)
QAbstractItemModel * sourceModel() const