Property change propagation, changing instance groups, icon preview

This commit is contained in:
Petr Mrázek 2013-03-19 06:24:34 +01:00
parent d67d58e662
commit 7d7e4034f4
7 changed files with 85 additions and 14 deletions

View File

@ -5,7 +5,6 @@
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)));
@ -19,10 +18,10 @@ void InstanceModel::onInstanceAdded ( int index )
endInsertRows();
}
// TODO: this doesn't trigger yet
void InstanceModel::onInstanceChanged ( int index )
{
QModelIndex mx = InstanceModel::index(index);
dataChanged(mx,mx);
}
void InstanceModel::onInvalidated()
@ -71,8 +70,12 @@ QVariant InstanceModel::data ( const QModelIndex& index, int role ) const
}
case Qt::DecorationRole:
{
// FIXME: replace with an icon cache
return cachedIcon;
// FIXME: replace with an icon cache/renderer
QString path = ":/icons/instances/";
path += pdata->iconKey();
QIcon icon(path);
return icon;
//else return QIcon(":/icons/multimc/scalable/apps/multimc.svg");
}
// for now.
case KCategorizedSortFilterProxyModel::CategorySortRole:

View File

@ -29,7 +29,6 @@ public slots:
private:
const InstanceList* m_instances;
QIcon cachedIcon;
int currentInstancesNumber;
};

View File

@ -116,6 +116,11 @@ MainWindow::MainWindow ( QWidget *parent ) :
// Load the instances.
instList.loadList();
// just a test
/*
instList.at(0)->setGroup("TEST GROUP");
instList.at(0)->setName("TEST ITEM");
*/
}
MainWindow::~MainWindow()
@ -140,6 +145,18 @@ void MainWindow::on_actionAddInstance_triggered()
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()
{
openInDefaultProgram ( globalSettings->get ( "InstanceDir" ).toString() );
@ -210,8 +227,7 @@ void MainWindow::on_instanceView_customContextMenuRequested ( const QPoint &pos
instContextMenu->exec ( view->mapToGlobal ( pos ) );
}
void MainWindow::on_actionLaunchInstance_triggered()
Instance* MainWindow::selectedInstance()
{
QAbstractItemView * iv = view;
auto smodel = iv->selectionModel();
@ -224,7 +240,18 @@ void MainWindow::on_actionLaunchInstance_triggered()
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());
}
}

View File

@ -44,14 +44,19 @@ public:
// Browser Dialog
void openWebPage(QUrl url);
private:
Instance *selectedInstance();
private slots:
void on_actionAbout_triggered();
void on_actionAddInstance_triggered();
void on_actionViewInstanceFolder_triggered();
void on_actionChangeInstGroup_triggered();
void on_actionViewInstanceFolder_triggered();
void on_actionRefresh_triggered();
void on_actionViewCentralModsFolder_triggered();

View File

@ -176,16 +176,28 @@ public:
//// General Info ////
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 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 void setNotes(QString val) { settings().set("notes", val); }
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 void setShouldRebuild(bool val) { settings().set("NeedsRebuild", val); }
@ -208,7 +220,10 @@ public:
virtual qint64 lastLaunch() { return settings().get("lastLaunchTime").value<qint64>(); }
virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch())
{ settings().set("lastLaunchTime", val); }
{
settings().set("lastLaunchTime", val);
emit propertiesChanged(this);
}
////// Directories //////
@ -283,6 +298,12 @@ public:
*/
virtual SettingsObject &settings() const;
signals:
/*!
* \brief Signal emitted when properties relevant to the instance view change
*/
void propertiesChanged(Instance * inst);
private:
QString m_rootDir;
QString m_group;

View File

@ -78,6 +78,9 @@ signals:
void instanceChanged(int index);
void invalidated();
private slots:
void propertiesChanged(Instance * inst);
protected:
QString m_instDir;
QList< InstancePtr > m_instances;

View File

@ -185,6 +185,7 @@ InstanceList::InstListError InstanceList::loadList()
qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8());
inst->setParent(this);
m_instances.append(inst);
connect(instPtr, SIGNAL(propertiesChanged(Instance*)),this, SLOT(propertiesChanged(Instance*)));
}
}
}
@ -221,4 +222,16 @@ InstancePtr InstanceList::getInstanceById(QString instId)
return InstancePtr();
else
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;
}
}
}