From d7cff6361e091990e7b3a90fc94f824284543c13 Mon Sep 17 00:00:00 2001 From: graffy76 Date: Mon, 23 Sep 2013 06:51:49 -0500 Subject: [PATCH] Fixed filter issue (all addons for a gamefile are enabled for checking). Note: Other dependencies are not yet automatically selected when an addon is checked. --- apps/opencs/view/doc/adjusterwidget.hpp | 1 - apps/opencs/view/doc/filedialog.cpp | 3 +- .../contentselector/model/contentmodel.cpp | 32 +++++++++++++------ .../contentselector/model/contentmodel.hpp | 3 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/opencs/view/doc/adjusterwidget.hpp b/apps/opencs/view/doc/adjusterwidget.hpp index d970cffee..461cfb345 100644 --- a/apps/opencs/view/doc/adjusterwidget.hpp +++ b/apps/opencs/view/doc/adjusterwidget.hpp @@ -25,7 +25,6 @@ namespace CSVDoc void setLocalData (const boost::filesystem::path& localData); - QString getText() const; bool isValid() const; boost::filesystem::path getPath() const; diff --git a/apps/opencs/view/doc/filedialog.cpp b/apps/opencs/view/doc/filedialog.cpp index 9dce090a1..68aab27d5 100644 --- a/apps/opencs/view/doc/filedialog.cpp +++ b/apps/opencs/view/doc/filedialog.cpp @@ -67,7 +67,6 @@ void CSVDoc::FileDialog::slotEnableCreateButton(bool enable, int widgetNumber) if (widgetNumber == 2) mEnable_2 = enable; - qDebug() << "update enabled" << mEnable_1 << mEnable_2 << enable; projectCreateButton->setEnabled(mEnable_1 && mEnable_2); } @@ -113,5 +112,5 @@ void CSVDoc::FileDialog::slotAdjusterChanged(bool value) void CSVDoc::FileDialog::slotGameFileSelected(int value) { - emit signalUpdateCreateButton(value > -1, 1); + emit signalUpdateCreateButton(value > -1, 1); } diff --git a/components/contentselector/model/contentmodel.cpp b/components/contentselector/model/contentmodel.cpp index b85da25c6..c1394ef47 100644 --- a/components/contentselector/model/contentmodel.cpp +++ b/components/contentselector/model/contentmodel.cpp @@ -65,7 +65,7 @@ ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::item(int row) return 0; } -const ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::findItem(const QString &name) const +const ContentSelectorModel::EsmFile *ContentSelectorModel::ContentModel::item(const QString &name) const { foreach (const EsmFile *file, mFiles) { @@ -99,7 +99,7 @@ Qt::ItemFlags ContentSelectorModel::ContentModel::flags(const QModelIndex &index if (canBeChecked(file)) return Qt::ItemIsEnabled | mDragDropFlags | mDefaultFlags; - return mDefaultFlags; + return Qt::NoItemFlags; } QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int role) const @@ -167,7 +167,7 @@ QVariant ContentSelectorModel::ContentModel::data(const QModelIndex &index, int if (file->isGameFile()) return ContentType_GameFile; else - if (flags(index) & Qt::ItemIsEnabled) + if (flags(index) & mDefaultFlags) return ContentType_Addon; break; @@ -373,12 +373,26 @@ bool ContentSelectorModel::ContentModel::dropMimeData(const QMimeData *data, Qt: bool ContentSelectorModel::ContentModel::canBeChecked(const EsmFile *file) const { - //element can be checked if all its dependencies are - foreach (const QString &gamefile, file->gameFiles()) - if (!isChecked(gamefile)) - return false; + //game files can always be checked + if (file->isGameFile()) + return true; - return true; + //addon can be checked if its gamefile is + foreach (const QString &fileName, file->gameFiles()) + { + const EsmFile *dependency = item(fileName); + + if (!dependency) + continue; + + if (dependency->isGameFile()) + { + if (isChecked(fileName)) + return true; + } + } + + return false; } void ContentSelectorModel::ContentModel::addFile(EsmFile *file) @@ -422,7 +436,7 @@ void ContentSelectorModel::ContentModel::addFiles(const QString &path) // Put the file in the table - if (findItem(path) == 0) + if (item(path) == 0) addFile(file); } catch(std::runtime_error &e) { diff --git a/components/contentselector/model/contentmodel.hpp b/components/contentselector/model/contentmodel.hpp index a8ff103da..a2a57f850 100644 --- a/components/contentselector/model/contentmodel.hpp +++ b/components/contentselector/model/contentmodel.hpp @@ -42,7 +42,7 @@ namespace ContentSelectorModel void addFiles(const QString &path); QModelIndex indexFromItem(const EsmFile *item) const; - const EsmFile *findItem(const QString &name) const; + const EsmFile *item(const QString &name) const; bool isChecked(const QString &name) const; void setCheckState(const QString &name, bool isChecked); @@ -54,6 +54,7 @@ namespace ContentSelectorModel void addFile(EsmFile *file); const EsmFile *item(int row) const; EsmFile *item(int row); + bool canBeChecked(const EsmFile *file) const; ContentFileList mFiles;