Property change propagation, changing instance groups, icon preview
This commit is contained in:
parent
d67d58e662
commit
7d7e4034f4
@ -5,7 +5,6 @@
|
|||||||
InstanceModel::InstanceModel ( const InstanceList& instances, QObject *parent )
|
InstanceModel::InstanceModel ( const InstanceList& instances, QObject *parent )
|
||||||
: QAbstractListModel ( parent ), m_instances ( &instances )
|
: QAbstractListModel ( parent ), m_instances ( &instances )
|
||||||
{
|
{
|
||||||
cachedIcon = QIcon(":/icons/multimc/scalable/apps/multimc.svg");
|
|
||||||
currentInstancesNumber = m_instances->count();
|
currentInstancesNumber = m_instances->count();
|
||||||
connect(m_instances,SIGNAL(instanceAdded(int)),this,SLOT(onInstanceAdded(int)));
|
connect(m_instances,SIGNAL(instanceAdded(int)),this,SLOT(onInstanceAdded(int)));
|
||||||
connect(m_instances,SIGNAL(instanceChanged(int)),this,SLOT(onInstanceChanged(int)));
|
connect(m_instances,SIGNAL(instanceChanged(int)),this,SLOT(onInstanceChanged(int)));
|
||||||
@ -19,10 +18,10 @@ void InstanceModel::onInstanceAdded ( int index )
|
|||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this doesn't trigger yet
|
|
||||||
void InstanceModel::onInstanceChanged ( int index )
|
void InstanceModel::onInstanceChanged ( int index )
|
||||||
{
|
{
|
||||||
|
QModelIndex mx = InstanceModel::index(index);
|
||||||
|
dataChanged(mx,mx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstanceModel::onInvalidated()
|
void InstanceModel::onInvalidated()
|
||||||
@ -71,8 +70,12 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
|
|||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
{
|
{
|
||||||
// FIXME: replace with an icon cache
|
// FIXME: replace with an icon cache/renderer
|
||||||
return cachedIcon;
|
QString path = ":/icons/instances/";
|
||||||
|
path += pdata->iconKey();
|
||||||
|
QIcon icon(path);
|
||||||
|
return icon;
|
||||||
|
//else return QIcon(":/icons/multimc/scalable/apps/multimc.svg");
|
||||||
}
|
}
|
||||||
// for now.
|
// for now.
|
||||||
case KCategorizedSortFilterProxyModel::CategorySortRole:
|
case KCategorizedSortFilterProxyModel::CategorySortRole:
|
||||||
|
@ -29,7 +29,6 @@ public slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const InstanceList* m_instances;
|
const InstanceList* m_instances;
|
||||||
QIcon cachedIcon;
|
|
||||||
int currentInstancesNumber;
|
int currentInstancesNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,6 +116,11 @@ MainWindow::MainWindow ( QWidget *parent ) :
|
|||||||
|
|
||||||
// Load the instances.
|
// Load the instances.
|
||||||
instList.loadList();
|
instList.loadList();
|
||||||
|
// just a test
|
||||||
|
/*
|
||||||
|
instList.at(0)->setGroup("TEST GROUP");
|
||||||
|
instList.at(0)->setName("TEST ITEM");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -140,6 +145,18 @@ void MainWindow::on_actionAddInstance_triggered()
|
|||||||
newInstDlg->exec();
|
newInstDlg->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionChangeInstGroup_triggered()
|
||||||
|
{
|
||||||
|
Instance* inst = selectedInstance();
|
||||||
|
if(inst)
|
||||||
|
{
|
||||||
|
QString name ( inst->group() );
|
||||||
|
name = QInputDialog::getText ( this, tr ( "Group name" ), tr ( "Enter a new group name." ), QLineEdit::Normal, name );
|
||||||
|
inst->setGroup(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_actionViewInstanceFolder_triggered()
|
void MainWindow::on_actionViewInstanceFolder_triggered()
|
||||||
{
|
{
|
||||||
openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() );
|
openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() );
|
||||||
@ -210,8 +227,7 @@ void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos
|
|||||||
instContextMenu->exec ( view->mapToGlobal ( pos ) );
|
instContextMenu->exec ( view->mapToGlobal ( pos ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Instance* MainWindow::selectedInstance()
|
||||||
void MainWindow::on_actionLaunchInstance_triggered()
|
|
||||||
{
|
{
|
||||||
QAbstractItemView * iv = view;
|
QAbstractItemView * iv = view;
|
||||||
auto smodel = iv->selectionModel();
|
auto smodel = iv->selectionModel();
|
||||||
@ -224,7 +240,18 @@ void MainWindow::on_actionLaunchInstance_triggered()
|
|||||||
|
|
||||||
if(mindex.isValid())
|
if(mindex.isValid())
|
||||||
{
|
{
|
||||||
Instance * inst = (Instance *) mindex.data(InstanceModel::InstancePointerRole).value<void *>();
|
return (Instance *) mindex.data(InstanceModel::InstancePointerRole).value<void *>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_actionLaunchInstance_triggered()
|
||||||
|
{
|
||||||
|
Instance* inst = selectedInstance();
|
||||||
|
if(inst)
|
||||||
|
{
|
||||||
doLogin(inst->id());
|
doLogin(inst->id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,11 +45,16 @@ public:
|
|||||||
// Browser Dialog
|
// Browser Dialog
|
||||||
void openWebPage(QUrl url);
|
void openWebPage(QUrl url);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Instance *selectedInstance();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionAbout_triggered();
|
void on_actionAbout_triggered();
|
||||||
|
|
||||||
void on_actionAddInstance_triggered();
|
void on_actionAddInstance_triggered();
|
||||||
|
|
||||||
|
void on_actionChangeInstGroup_triggered();
|
||||||
|
|
||||||
void on_actionViewInstanceFolder_triggered();
|
void on_actionViewInstanceFolder_triggered();
|
||||||
|
|
||||||
void on_actionRefresh_triggered();
|
void on_actionRefresh_triggered();
|
||||||
|
@ -176,16 +176,28 @@ public:
|
|||||||
|
|
||||||
//// General Info ////
|
//// General Info ////
|
||||||
virtual QString name() { return settings().get("name").toString(); }
|
virtual QString name() { return settings().get("name").toString(); }
|
||||||
virtual void setName(QString val) { settings().set("name", val); }
|
virtual void setName(QString val)
|
||||||
|
{
|
||||||
|
settings().set("name", val);
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
virtual QString iconKey() const { return settings().get("iconKey").toString(); }
|
virtual QString iconKey() const { return settings().get("iconKey").toString(); }
|
||||||
virtual void setIconKey(QString val) { settings().set("iconKey", val); }
|
virtual void setIconKey(QString val)
|
||||||
|
{
|
||||||
|
settings().set("iconKey", val);
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
virtual QString notes() const { return settings().get("notes").toString(); }
|
virtual QString notes() const { return settings().get("notes").toString(); }
|
||||||
virtual void setNotes(QString val) { settings().set("notes", val); }
|
virtual void setNotes(QString val) { settings().set("notes", val); }
|
||||||
|
|
||||||
virtual QString group() const { return m_group; }
|
virtual QString group() const { return m_group; }
|
||||||
virtual void setGroup(QString val) { m_group = val; }
|
virtual void setGroup(QString val)
|
||||||
|
{
|
||||||
|
m_group = val;
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
|
virtual bool shouldRebuild() const { return settings().get("NeedsRebuild").toBool(); }
|
||||||
virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
|
virtual void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
|
||||||
@ -208,7 +220,10 @@ public:
|
|||||||
|
|
||||||
virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value<qint64>(); }
|
virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value<qint64>(); }
|
||||||
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
|
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
|
||||||
{ settings().set("lastLaunchTime", val); }
|
{
|
||||||
|
settings().set("lastLaunchTime", val);
|
||||||
|
emit propertiesChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////// Directories //////
|
////// Directories //////
|
||||||
@ -283,6 +298,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual SettingsObject &settings() const;
|
virtual SettingsObject &settings() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/*!
|
||||||
|
* \brief Signal emitted when properties relevant to the instance view change
|
||||||
|
*/
|
||||||
|
void propertiesChanged(Instance * inst);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_rootDir;
|
QString m_rootDir;
|
||||||
QString m_group;
|
QString m_group;
|
||||||
|
@ -78,6 +78,9 @@ signals:
|
|||||||
void instanceChanged(int index);
|
void instanceChanged(int index);
|
||||||
void invalidated();
|
void invalidated();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void propertiesChanged(Instance * inst);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_instDir;
|
QString m_instDir;
|
||||||
QList< InstancePtr > m_instances;
|
QList< InstancePtr > m_instances;
|
||||||
|
@ -185,6 +185,7 @@ InstanceList::InstListError InstanceList::loadList()
|
|||||||
qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
|
qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
|
||||||
inst->setParent(this);
|
inst->setParent(this);
|
||||||
m_instances.append(inst);
|
m_instances.append(inst);
|
||||||
|
connect(instPtr, SIGNAL(propertiesChanged(Instance*)),this, SLOT(propertiesChanged(Instance*)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,3 +223,15 @@ InstancePtr InstanceList::getInstanceById(QString instId)
|
|||||||
else
|
else
|
||||||
return iter.peekPrevious();
|
return iter.peekPrevious();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InstanceList::propertiesChanged(Instance * inst)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < m_instances.count(); i++)
|
||||||
|
{
|
||||||
|
if(inst == m_instances[i].data())
|
||||||
|
{
|
||||||
|
emit instanceChanged(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user