summaryrefslogtreecommitdiffstats
path: root/gui/instancemodel.cpp
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-03-28 11:37:12 -0500
committerAndrew <forkk@forkk.net>2013-03-28 11:37:12 -0500
commitebb2c54975e3f0b7b891532e8e72d2ef760f96c4 (patch)
tree973de7066457a1faddffd3834eb0c260d5191ec2 /gui/instancemodel.cpp
parent168ed3e8e58a8e5065ffa720f8d45f4cee0f2069 (diff)
parent1f13f0c665001a1a79f00cdad1e63e6c9802e55f (diff)
downloadMultiMC-ebb2c54975e3f0b7b891532e8e72d2ef760f96c4.tar
MultiMC-ebb2c54975e3f0b7b891532e8e72d2ef760f96c4.tar.gz
MultiMC-ebb2c54975e3f0b7b891532e8e72d2ef760f96c4.tar.lz
MultiMC-ebb2c54975e3f0b7b891532e8e72d2ef760f96c4.tar.xz
MultiMC-ebb2c54975e3f0b7b891532e8e72d2ef760f96c4.zip
Merge branch 'master' of git://github.com/peterix/MultiMC5
Conflicts: CMakeLists.txt gui/mainwindow.cpp
Diffstat (limited to 'gui/instancemodel.cpp')
-rw-r--r--gui/instancemodel.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/gui/instancemodel.cpp b/gui/instancemodel.cpp
index 73d0dbc1..8db985e8 100644
--- a/gui/instancemodel.cpp
+++ b/gui/instancemodel.cpp
@@ -1,13 +1,38 @@
#include "instancemodel.h"
#include <instance.h>
#include <QIcon>
+#include "iconcache.h"
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();
+}
+
+void InstanceModel::onInstanceChanged ( int index )
+{
+ QModelIndex mx = InstanceModel::index(index);
+ dataChanged(mx,mx);
+}
+
+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() );
}
@@ -46,14 +71,22 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
}
case Qt::DecorationRole:
{
- // FIXME: replace with an icon cache
- return cachedIcon;
+ IconCache * ic = IconCache::instance();
+ // FIXME: replace with an icon cache/renderer
+ /*
+ QString path = ":/icons/instances/";
+ path += pdata->iconKey();
+ QIcon icon(path);
+ */
+ QString key = pdata->iconKey();
+ return ic->getIcon(key);
+ //else return QIcon(":/icons/multimc/scalable/apps/multimc.svg");
}
// for now.
case KCategorizedSortFilterProxyModel::CategorySortRole:
case KCategorizedSortFilterProxyModel::CategoryDisplayRole:
{
- return "IT'S A GROUP";
+ return pdata->group();
}
default:
break;