mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
Implement some TODO's, fix sonar warnings
This commit is contained in:
parent
5ca65f14bd
commit
879eb2184f
@ -457,7 +457,6 @@ void CModListView::selectMod(const QModelIndex & index)
|
|||||||
//FIXME: this function should be recursive
|
//FIXME: this function should be recursive
|
||||||
//FIXME: ensure that this is also reflected correctly in "Notes" section of mod description
|
//FIXME: ensure that this is also reflected correctly in "Notes" section of mod description
|
||||||
bool hasInvalidDeps = !findInvalidDependencies(modName).empty();
|
bool hasInvalidDeps = !findInvalidDependencies(modName).empty();
|
||||||
//bool hasBlockingMods = !findBlockingMods(modName).empty();
|
|
||||||
bool hasDependentMods = !findDependentMods(modName, true).empty();
|
bool hasDependentMods = !findDependentMods(modName, true).empty();
|
||||||
|
|
||||||
ui->disableButton->setVisible(modStateModel->isModEnabled(mod.getID()));
|
ui->disableButton->setVisible(modStateModel->isModEnabled(mod.getID()));
|
||||||
@ -521,29 +520,6 @@ QStringList CModListView::findInvalidDependencies(QString mod)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList CModListView::findBlockingMods(QString modUnderTest)
|
|
||||||
{
|
|
||||||
QStringList ret;
|
|
||||||
auto required = modStateModel->getMod(modUnderTest).getDependencies();
|
|
||||||
|
|
||||||
for(QString name : modStateModel->getAllMods())
|
|
||||||
{
|
|
||||||
auto mod = modStateModel->getMod(name);
|
|
||||||
|
|
||||||
if(modStateModel->isModEnabled(mod.getID()))
|
|
||||||
{
|
|
||||||
// one of enabled mods have requirement (or this mod) marked as conflict
|
|
||||||
for(const auto & conflict : mod.getConflicts())
|
|
||||||
{
|
|
||||||
if(required.contains(conflict))
|
|
||||||
ret.push_back(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList CModListView::findDependentMods(QString mod, bool excludeDisabled)
|
QStringList CModListView::findDependentMods(QString mod, bool excludeDisabled)
|
||||||
{
|
{
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
@ -691,7 +667,9 @@ void CModListView::manualInstallFile(QString filePath)
|
|||||||
for(const auto widget : qApp->allWidgets())
|
for(const auto widget : qApp->allWidgets())
|
||||||
if(auto settingsView = qobject_cast<CSettingsView *>(widget))
|
if(auto settingsView = qobject_cast<CSettingsView *>(widget))
|
||||||
settingsView->loadSettings();
|
settingsView->loadSettings();
|
||||||
// TODO: rescan local mods
|
|
||||||
|
modStateModel->reloadLocalState();
|
||||||
|
modModel->reloadRepositories();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -879,8 +857,8 @@ void CModListView::installFiles(QStringList files)
|
|||||||
if(futureExtract.get())
|
if(futureExtract.get())
|
||||||
{
|
{
|
||||||
//update
|
//update
|
||||||
CResourceHandler::get("initial")->updateFilteredFiles([](const std::string &){ return true; });
|
modStateModel->reloadLocalState();
|
||||||
// TODO: rescan local mods
|
modModel->reloadRepositories();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1080,7 +1058,6 @@ void CModListView::on_allModsView_doubleClicked(const QModelIndex &index)
|
|||||||
auto mod = modStateModel->getMod(modName);
|
auto mod = modStateModel->getMod(modName);
|
||||||
|
|
||||||
bool hasInvalidDeps = !findInvalidDependencies(modName).empty();
|
bool hasInvalidDeps = !findInvalidDependencies(modName).empty();
|
||||||
bool hasBlockingMods = !findBlockingMods(modName).empty();
|
|
||||||
bool hasDependentMods = !findDependentMods(modName, true).empty();
|
bool hasDependentMods = !findDependentMods(modName, true).empty();
|
||||||
|
|
||||||
if(!hasInvalidDeps && mod.isAvailable() && !mod.isSubmod())
|
if(!hasInvalidDeps && mod.isAvailable() && !mod.isSubmod())
|
||||||
@ -1105,7 +1082,7 @@ void CModListView::on_allModsView_doubleClicked(const QModelIndex &index)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!hasBlockingMods && !hasInvalidDeps && !modStateModel->isModEnabled(modName))
|
if(!hasInvalidDeps && !modStateModel->isModEnabled(modName))
|
||||||
{
|
{
|
||||||
on_enableButton_clicked();
|
on_enableButton_clicked();
|
||||||
return;
|
return;
|
||||||
|
@ -48,8 +48,6 @@ class CModListView : public QWidget
|
|||||||
|
|
||||||
// find mods unknown to mod list (not present in repo and not installed)
|
// find mods unknown to mod list (not present in repo and not installed)
|
||||||
QStringList findInvalidDependencies(QString mod);
|
QStringList findInvalidDependencies(QString mod);
|
||||||
// find mods that block enabling of this mod: conflicting with this mod or one of required mods
|
|
||||||
QStringList findBlockingMods(QString modUnderTest);
|
|
||||||
// find mods that depend on this one
|
// find mods that depend on this one
|
||||||
QStringList findDependentMods(QString mod, bool excludeDisabled);
|
QStringList findDependentMods(QString mod, bool excludeDisabled);
|
||||||
|
|
||||||
|
@ -14,17 +14,6 @@
|
|||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
namespace ModStatus
|
|
||||||
{
|
|
||||||
static const QString iconDelete = ":/icons/mod-delete.png";
|
|
||||||
static const QString iconDisabled = ":/icons/mod-disabled.png";
|
|
||||||
static const QString iconDisabledSubmod = ":/icons/submod-disabled.png";
|
|
||||||
static const QString iconDownload = ":/icons/mod-download.png";
|
|
||||||
static const QString iconEnabled = ":/icons/mod-enabled.png";
|
|
||||||
static const QString iconEnabledSubmod = ":/icons/submod-enabled.png";
|
|
||||||
static const QString iconUpdate = ":/icons/mod-update.png";
|
|
||||||
}
|
|
||||||
|
|
||||||
ModStateItemModel::ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent)
|
ModStateItemModel::ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent)
|
||||||
: QAbstractItemModel(parent)
|
: QAbstractItemModel(parent)
|
||||||
, model(model)
|
, model(model)
|
||||||
@ -109,6 +98,13 @@ QVariant ModStateItemModel::getText(const ModState & mod, int field) const
|
|||||||
|
|
||||||
QVariant ModStateItemModel::getIcon(const ModState & mod, int field) const
|
QVariant ModStateItemModel::getIcon(const ModState & mod, int field) const
|
||||||
{
|
{
|
||||||
|
static const QString iconDisabled = ":/icons/mod-disabled.png";
|
||||||
|
static const QString iconDisabledSubmod = ":/icons/submod-disabled.png";
|
||||||
|
static const QString iconDownload = ":/icons/mod-download.png";
|
||||||
|
static const QString iconEnabled = ":/icons/mod-enabled.png";
|
||||||
|
static const QString iconEnabledSubmod = ":/icons/submod-enabled.png";
|
||||||
|
static const QString iconUpdate = ":/icons/mod-update.png";
|
||||||
|
|
||||||
if (field == ModFields::STATUS_ENABLED)
|
if (field == ModFields::STATUS_ENABLED)
|
||||||
{
|
{
|
||||||
if (!model->isModInstalled(mod.getID()))
|
if (!model->isModInstalled(mod.getID()))
|
||||||
@ -119,24 +115,24 @@ QVariant ModStateItemModel::getIcon(const ModState & mod, int field) const
|
|||||||
if (!model->isModEnabled(mod.getTopParentID()))
|
if (!model->isModEnabled(mod.getTopParentID()))
|
||||||
{
|
{
|
||||||
if (model->isModEnabled(mod.getID()))
|
if (model->isModEnabled(mod.getID()))
|
||||||
return QIcon(ModStatus::iconEnabledSubmod);
|
return QIcon(iconEnabledSubmod);
|
||||||
else
|
else
|
||||||
return QIcon(ModStatus::iconDisabledSubmod);
|
return QIcon(iconDisabledSubmod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model->isModEnabled(mod.getID()))
|
if (model->isModEnabled(mod.getID()))
|
||||||
return QIcon(ModStatus::iconEnabled);
|
return QIcon(iconEnabled);
|
||||||
else
|
else
|
||||||
return QIcon(ModStatus::iconDisabled);
|
return QIcon(iconDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(field == ModFields::STATUS_UPDATE)
|
if(field == ModFields::STATUS_UPDATE)
|
||||||
{
|
{
|
||||||
if (model->isModUpdateAvailable(mod.getID()))
|
if (model->isModUpdateAvailable(mod.getID()))
|
||||||
return QIcon(ModStatus::iconUpdate);
|
return QIcon(iconUpdate);
|
||||||
if (!model->isModInstalled(mod.getID()))
|
if (!model->isModInstalled(mod.getID()))
|
||||||
return QIcon(ModStatus::iconDownload);
|
return QIcon(iconDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@ -189,7 +185,7 @@ Qt::ItemFlags ModStateItemModel::flags(const QModelIndex &) const
|
|||||||
|
|
||||||
QVariant ModStateItemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant ModStateItemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
static const QString header[ModFields::COUNT] =
|
static const std::array header =
|
||||||
{
|
{
|
||||||
QT_TRANSLATE_NOOP("ModFields", "Name"),
|
QT_TRANSLATE_NOOP("ModFields", "Name"),
|
||||||
QT_TRANSLATE_NOOP("ModFields", ""), // status icon
|
QT_TRANSLATE_NOOP("ModFields", ""), // status icon
|
||||||
@ -198,7 +194,7 @@ QVariant ModStateItemModel::headerData(int section, Qt::Orientation orientation,
|
|||||||
};
|
};
|
||||||
|
|
||||||
if(role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
if(role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
||||||
return QCoreApplication::translate("ModFields", header[section].toStdString().c_str());
|
return QCoreApplication::translate("ModFields", header[section]);
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +307,7 @@ bool CModFilterModel::filterAcceptsRow(int source_row, const QModelIndex & sourc
|
|||||||
|
|
||||||
for(size_t i = 0; i < base->rowCount(index); i++)
|
for(size_t i = 0; i < base->rowCount(index); i++)
|
||||||
{
|
{
|
||||||
if(filterMatchesThis(base->index((int)i, 0, index)))
|
if(filterMatchesThis(base->index(i, 0, index)))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class ModStateItemModel final : public QAbstractItemModel
|
|||||||
QVariant getIcon(const ModState & mod, int field) const;
|
QVariant getIcon(const ModState & mod, int field) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent = nullptr);
|
explicit ModStateItemModel(std::shared_ptr<ModStateModel> model, QObject * parent);
|
||||||
|
|
||||||
/// CModListContainer overrides
|
/// CModListContainer overrides
|
||||||
void reloadRepositories();
|
void reloadRepositories();
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
int rowCount(const QModelIndex & parent) const override;
|
int rowCount(const QModelIndex & parent) const override;
|
||||||
int columnCount(const QModelIndex & parent) const override;
|
int columnCount(const QModelIndex & parent) const override;
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
|
QModelIndex index(int row, int column, const QModelIndex & parent) const override;
|
||||||
QModelIndex parent(const QModelIndex & child) const override;
|
QModelIndex parent(const QModelIndex & child) const override;
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex & index) const override;
|
Qt::ItemFlags flags(const QModelIndex & index) const override;
|
||||||
|
@ -262,11 +262,9 @@ void CContentHandler::init()
|
|||||||
bool CContentHandler::preloadData(const ModDescription & mod, bool validate)
|
bool CContentHandler::preloadData(const ModDescription & mod, bool validate)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
if (validate && mod.getID() != ModScope::scopeBuiltin()) // TODO: remove workaround
|
|
||||||
{
|
if (!JsonUtils::validate(mod.getLocalConfig(), "vcmi:mod", mod.getID()))
|
||||||
if (!JsonUtils::validate(mod.getLocalConfig(), "vcmi:mod", mod.getID()))
|
result = false;
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto & handler : handlers)
|
for(auto & handler : handlers)
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ double ModsState::getInstalledModSizeMegabytes(const TModID & modName) const
|
|||||||
sizeBytes += boost::filesystem::file_size(*it);
|
sizeBytes += boost::filesystem::file_size(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
double sizeMegabytes = sizeBytes / double(1024*1024);
|
double sizeMegabytes = sizeBytes / static_cast<double>(1024*1024);
|
||||||
return sizeMegabytes;
|
return sizeMegabytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,20 +150,19 @@ std::vector<TModID> ModsState::scanModsDirectory(const std::string & modDir) con
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static JsonNode loadModSettings(const JsonPath & path)
|
|
||||||
{
|
|
||||||
if(CResourceHandler::get("local")->existsResource(ResourcePath(path)))
|
|
||||||
{
|
|
||||||
return JsonNode(path);
|
|
||||||
}
|
|
||||||
// Probably new install. Create initial configuration
|
|
||||||
CResourceHandler::get("local")->createResource(path.getOriginalName() + ".json");
|
|
||||||
return JsonNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
ModsPresetState::ModsPresetState()
|
ModsPresetState::ModsPresetState()
|
||||||
{
|
{
|
||||||
modConfig = loadModSettings(JsonPath::builtin("config/modSettings.json"));
|
static const JsonPath settingsPath = JsonPath::builtin("config/modSettings.json");
|
||||||
|
|
||||||
|
if(CResourceHandler::get("local")->existsResource(ResourcePath(settingsPath)))
|
||||||
|
{
|
||||||
|
modConfig = JsonNode(settingsPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Probably new install. Create initial configuration
|
||||||
|
CResourceHandler::get("local")->createResource(settingsPath.getOriginalName() + ".json");
|
||||||
|
}
|
||||||
|
|
||||||
if(modConfig["presets"].isNull())
|
if(modConfig["presets"].isNull())
|
||||||
{
|
{
|
||||||
@ -365,7 +364,6 @@ ModManager::ModManager(const JsonNode & repositoryList)
|
|||||||
: modsState(std::make_unique<ModsState>())
|
: modsState(std::make_unique<ModsState>())
|
||||||
, modsPreset(std::make_unique<ModsPresetState>())
|
, modsPreset(std::make_unique<ModsPresetState>())
|
||||||
{
|
{
|
||||||
//TODO: load only active mods & all their submods in game mode?
|
|
||||||
modsStorage = std::make_unique<ModsStorage>(modsState->getInstalledMods(), repositoryList);
|
modsStorage = std::make_unique<ModsStorage>(modsState->getInstalledMods(), repositoryList);
|
||||||
|
|
||||||
eraseMissingModsFromPreset();
|
eraseMissingModsFromPreset();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user