diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-03-18 23:00:46 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-03-18 23:00:46 +0100 |
commit | 65faabeed48584c461ca21d784c3f1d46f67f832 (patch) | |
tree | e814006279d0c56246e61e5c8f3bd29bc0e1c541 /gui/instancemodel.cpp | |
parent | b84dfddd1b24e82dccb5a20d9c30570d26846e76 (diff) | |
download | MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar.gz MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar.lz MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar.xz MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.zip |
Connect instance list to model.
Diffstat (limited to 'gui/instancemodel.cpp')
-rw-r--r-- | gui/instancemodel.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp index 73d0dbc1..49909940 100644 --- a/gui/instancemodel.cpp +++ b/gui/instancemodel.cpp @@ -6,8 +6,33 @@ InstanceModel::InstanceModel ( const InstanceList& instances, QObject *parent ) : QAbstractListModel ( parent ), m_instances ( &instances ) { cachedIcon = QIcon(":/icons/multimc/scalable/apps/multimc.svg"); + currentInstancesNumber = m_instances->count(); + connect(m_instances,SIGNAL(instanceAdded(int)),this,SLOT(onInstanceAdded(int))); + connect(m_instances,SIGNAL(instanceChanged(int)),this,SLOT(onInstanceChanged(int))); + connect(m_instances,SIGNAL(invalidated()),this,SLOT(onInvalidated())); } +void InstanceModel::onInstanceAdded ( int index ) +{ + beginInsertRows(QModelIndex(), index, index); + currentInstancesNumber ++; + endInsertRows(); +} + +// TODO: this doesn't trigger yet +void InstanceModel::onInstanceChanged ( int index ) +{ + +} + +void InstanceModel::onInvalidated() +{ + beginResetModel(); + currentInstancesNumber = m_instances->count(); + endResetModel(); +} + + int InstanceModel::rowCount ( const QModelIndex& parent ) const { Q_UNUSED ( parent ); @@ -17,7 +42,7 @@ int InstanceModel::rowCount ( const QModelIndex& parent ) const QModelIndex InstanceModel::index ( int row, int column, const QModelIndex& parent ) const { Q_UNUSED ( parent ); - if ( row < 0 || row >= m_instances->count() ) + if ( row < 0 || row >= currentInstancesNumber ) return QModelIndex(); return createIndex ( row, column, ( void* ) m_instances->at ( row ).data() ); } |