NOISSUE First step towards 10000 instances

This commit is contained in:
Petr Mrázek 2019-12-17 22:00:41 +01:00
parent 3581f5384f
commit c4919bab25
8 changed files with 72 additions and 40 deletions

View File

@ -32,10 +32,17 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
m_settings = settings;
m_rootDir = rootDir;
m_id = QFileInfo(instanceRoot()).fileName();
m_settings->registerSetting("name", "Unnamed Instance");
m_name = m_settings->get("name").toString();
m_settings->registerSetting("iconKey", "default");
m_settings->registerSetting("notes", "");
m_settings->registerSetting("lastLaunchTime", 0);
m_lastlaunch = m_settings->get("lastLaunchTime").value<qint64>();
m_settings->registerSetting("totalTimePlayed", 0);
// Custom Commands
@ -117,9 +124,9 @@ BaseInstance::Status BaseInstance::currentStatus() const
return m_status;
}
QString BaseInstance::id() const
const QString &BaseInstance::id() const
{
return QFileInfo(instanceRoot()).fileName();
return m_id;
}
bool BaseInstance::isRunning() const
@ -192,13 +199,19 @@ bool BaseInstance::reloadSettings()
qint64 BaseInstance::lastLaunch() const
{
return m_settings->get("lastLaunchTime").value<qint64>();
return m_lastlaunch;
}
void BaseInstance::setLastLaunch(qint64 val)
{
//FIXME: if no change, do not set. setting involves saving a file.
if(m_lastlaunch == val) {
return;
}
// FIXME: there is no single source of truth.
m_lastlaunch = val;
m_settings->set("lastLaunchTime", val);
emit propertiesChanged(this);
}
@ -227,14 +240,20 @@ QString BaseInstance::iconKey() const
void BaseInstance::setName(QString val)
{
//FIXME: if no change, do not set. setting involves saving a file.
if(m_name == val) {
return;
}
// FIXME: there is no single source of truth.
m_name = val;
m_settings->set("name", val);
emit propertiesChanged(this);
}
QString BaseInstance::name() const
{
return m_settings->get("name").toString();
return m_name;
}
QString BaseInstance::windowTitle() const

View File

@ -80,7 +80,7 @@ public:
/// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to
/// be unique.
virtual QString id() const;
const QString &id() const;
void setRunning(bool running);
bool isRunning() const;
@ -250,6 +250,10 @@ protected slots:
protected: /* data */
QString m_rootDir;
QString m_id;
QString m_name;
qint64 m_lastlaunch = 0;
SettingsObjectPtr m_settings;
// InstanceFlags m_flags;
bool m_isRunning = false;

View File

@ -115,7 +115,7 @@ QVariant InstanceList::data(const QModelIndex &index, int role) const
// HACK: see GroupView.h in gui!
case GroupRole:
{
return getInstanceGroup(pdata->id());
return getInstanceGroup(pdata);
}
default:
break;
@ -153,6 +153,16 @@ Qt::ItemFlags InstanceList::flags(const QModelIndex &index) const
return f;
}
GroupId InstanceList::getInstanceGroup(BaseInstance * inst) const
{
auto iter = m_instanceGroupIndex.find(inst->id());
if(iter != m_instanceGroupIndex.end())
{
return *iter;
}
return GroupId();
}
GroupId InstanceList::getInstanceGroup(const InstanceId& id) const
{
auto inst = getInstanceById(id);
@ -160,12 +170,7 @@ GroupId InstanceList::getInstanceGroup(const InstanceId& id) const
{
return GroupId();
}
auto iter = m_instanceGroupIndex.find(inst->id());
if(iter != m_instanceGroupIndex.end())
{
return *iter;
}
return GroupId();
return getInstanceGroup(inst.get());
}
void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name)

View File

@ -144,6 +144,7 @@ private slots:
void instanceDirContentsChanged(const QString &path);
private:
GroupId getInstanceGroup(BaseInstance * inst) const;
int getInstIndex(BaseInstance *inst) const;
void suspendWatch();
void resumeWatch();

View File

@ -17,8 +17,7 @@ QVariant InstanceProxyModel::data(const QModelIndex & index, int role) const
return data;
}
bool InstanceProxyModel::subSortLessThan(const QModelIndex &left,
const QModelIndex &right) const
bool InstanceProxyModel::subSortLessThan(const QModelIndex &left, const QModelIndex &right) const
{
BaseInstance *pdataLeft = static_cast<BaseInstance *>(left.internalPointer());
BaseInstance *pdataRight = static_cast<BaseInstance *>(right.internalPointer());

View File

@ -679,6 +679,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
proxymodel = new InstanceProxyModel(this);
proxymodel->setSourceModel(MMC->instances().get());
auto sortMode = MMC->settings()->getSetting("InstSortMode");
connect(sortMode.get(), &Setting::SettingChanged, [](const Setting &setting, QVariant value){
auto StrValue = value.toString();
});
proxymodel->sort(0);
connect(proxymodel, &InstanceProxyModel::dataChanged, this, &MainWindow::instanceDataChanged);
@ -1370,15 +1375,17 @@ void MainWindow::finalizeInstance(InstancePtr inst)
{
view->updateGeometries();
setSelectedInstanceById(inst->id());
if (MMC->accounts()->anyAccountIsValid())
{
if (MMC->accounts()->anyAccountIsValid()) {
ProgressDialog loadDialog(this);
auto update = inst->createUpdateTask(Net::Mode::Online);
connect(update.get(), &Task::failed, [this](QString reason)
{
QString error = QString("Instance load failed: %1").arg(reason);
CustomMessageBox::selectable(this, tr("Error"), error, QMessageBox::Warning)->show();
});
connect(
update.get(),
&Task::failed,
[this](QString reason) {
QString error = QString("Instance load failed: %1").arg(reason);
CustomMessageBox::selectable(this, tr("Error"), error, QMessageBox::Warning)->show();
}
);
if(update)
{
loadDialog.setSkipButton(true, tr("Abort"));
@ -1387,10 +1394,12 @@ void MainWindow::finalizeInstance(InstancePtr inst)
}
else
{
CustomMessageBox::selectable(this, tr("Error"), tr("MultiMC cannot download Minecraft or update instances unless you have at least "
"one account added.\nPlease add your Mojang or Minecraft account."),
QMessageBox::Warning)
->show();
CustomMessageBox::selectable(
this,
tr("Error"),
tr("MultiMC cannot download Minecraft or update instances unless you have at least one account added.\nPlease add your Mojang or Minecraft account."),
QMessageBox::Warning
)->show();
}
}

View File

@ -36,6 +36,7 @@ void VisualGroup::update()
{
auto temp_items = items();
auto itemsPerRow = view->itemsPerRow();
m_itemLookup.clear();
int numRows = qMax(1, qCeil((qreal)temp_items.size() / (qreal)itemsPerRow));
rows = QVector<VisualRow>(numRows);
@ -61,6 +62,7 @@ void VisualGroup::update()
maxRowHeight = itemHeight;
}
rows[currentRow].items.append(item);
m_itemLookup[item] = QPair<int, int>(positionInRow, currentRow);
positionInRow++;
}
rows[currentRow].height = maxRowHeight;
@ -69,20 +71,12 @@ void VisualGroup::update()
QPair<int, int> VisualGroup::positionOf(const QModelIndex &index) const
{
int y = 0;
for (auto & row: rows)
{
for(auto x = 0; x < row.items.size(); x++)
{
if(row.items[x] == index)
{
return qMakePair(x,y);
}
}
y++;
auto iter = m_itemLookup.find(index);
if(iter == m_itemLookup.end()) {
qWarning() << "Item" << index.row() << index.data(Qt::DisplayRole).toString() << "not found in visual group" << text;
return qMakePair(0, 0);
}
qWarning() << "Item" << index.row() << index.data(Qt::DisplayRole).toString() << "not found in visual group" << text;
return qMakePair(0, 0);
return *iter;
}
int VisualGroup::rowTopOf(const QModelIndex &index) const

View File

@ -50,6 +50,7 @@ struct VisualGroup
QString text;
bool collapsed = false;
QVector<VisualRow> rows;
QMap<QModelIndex, QPair<int, int>> m_itemLookup;
int firstItemIndex = 0;
int m_verticalPosition = 0;