Connect instance list to model.
This commit is contained in:
@ -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() );
|
||||
}
|
||||
|
@ -22,9 +22,15 @@ public:
|
||||
QVariant data ( const QModelIndex& index, int role ) const;
|
||||
Qt::ItemFlags flags ( const QModelIndex& index ) const;
|
||||
|
||||
public slots:
|
||||
void onInstanceAdded(int index);
|
||||
void onInstanceChanged(int index);
|
||||
void onInvalidated();
|
||||
|
||||
private:
|
||||
const InstanceList* m_instances;
|
||||
QIcon cachedIcon;
|
||||
int currentInstancesNumber;
|
||||
};
|
||||
|
||||
class InstanceProxyModel : public KCategorizedSortFilterProxyModel
|
||||
|
@ -64,8 +64,6 @@ MainWindow::MainWindow ( QWidget *parent ) :
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
// Create the widget
|
||||
instList.loadList();
|
||||
|
||||
view = new KCategorizedView ( ui->centralWidget );
|
||||
drawer = new KCategoryDrawer ( view );
|
||||
|
||||
@ -100,7 +98,9 @@ MainWindow::MainWindow ( QWidget *parent ) :
|
||||
view->setModel ( proxymodel );
|
||||
connect(view, SIGNAL(doubleClicked(const QModelIndex &)),
|
||||
this, SLOT(instanceActivated(const QModelIndex &)));
|
||||
|
||||
|
||||
// Load the instances.
|
||||
instList.loadList();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
Reference in New Issue
Block a user