summaryrefslogtreecommitdiff
path: root/src/pluginlist.cpp
diff options
context:
space:
mode:
authorMikaƫl Capelle <capelle.mikael@gmail.com>2021-01-10 10:25:37 +0100
committerGitHub <noreply@github.com>2021-01-10 10:25:37 +0100
commit80e44a9e3ade61695b4807a3a900d2866138ecac (patch)
tree1ef9904664d8d34dba6692bbf5325aea8c199d08 /src/pluginlist.cpp
parenteaec140f7c823012c09536175d8917dddcacdb7c (diff)
parent4a0ce804ea486744e5f6140a0ce4538d99e21ce3 (diff)
Merge pull request #1338 from Holt59/collapsible-separators
Collapsible separators (and refactoring).
Diffstat (limited to 'src/pluginlist.cpp')
-rw-r--r--src/pluginlist.cpp224
1 files changed, 67 insertions, 157 deletions
diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp
index 504b17c5..918668ed 100644
--- a/src/pluginlist.cpp
+++ b/src/pluginlist.cpp
@@ -135,19 +135,19 @@ QString PluginList::getColumnToolTip(int column)
}
}
-void PluginList::highlightPlugins(const QItemSelectionModel *selection, const MOShared::DirectoryEntry &directoryEntry, const Profile &profile)
+void PluginList::highlightPlugins(
+ const std::vector<unsigned int>& modIndices,
+ const MOShared::DirectoryEntry &directoryEntry)
{
+ auto* profile = m_Organizer.currentProfile();
+
for (auto &esp : m_ESPs) {
esp.modSelected = false;
}
- for (QModelIndex idx : selection->selectedRows(ModList::COL_PRIORITY)) {
- int modIndex = idx.data(Qt::UserRole + 1).toInt();
- if (modIndex == UINT_MAX)
- continue;
-
+ for (auto& modIndex : modIndices) {
ModInfo::Ptr selectedMod = ModInfo::getByIndex(modIndex);
- if (!selectedMod.isNull() && profile.modEnabled(modIndex)) {
+ if (!selectedMod.isNull() && profile->modEnabled(modIndex)) {
QDir dir(selectedMod->absolutePath());
QStringList plugins = dir.entryList(QStringList() << "*.esp" << "*.esm" << "*.esl");
const MOShared::FilesOrigin& origin = directoryEntry.getOriginByName(selectedMod->internalName().toStdWString());
@@ -338,94 +338,89 @@ int PluginList::findPluginByPriority(int priority)
return -1;
}
-void PluginList::enableSelected(const QItemSelectionModel *selectionModel)
+void PluginList::setEnabled(const QModelIndexList& indices, bool enabled)
{
- if (selectionModel->hasSelection()) {
- QStringList dirty;
- for (auto row : selectionModel->selectedRows(COL_PRIORITY)) {
- int rowIndex = findPluginByPriority(row.data().toInt());
- if (!m_ESPs[rowIndex].enabled) {
- m_ESPs[rowIndex].enabled = true;
- dirty.append(m_ESPs[rowIndex].name);
- }
- }
- if (!dirty.isEmpty()) {
- emit writePluginsList();
- pluginStatesChanged(dirty, IPluginList::PluginState::STATE_ACTIVE);
+ QStringList dirty;
+ for (auto& idx : indices) {
+ if (m_ESPs[idx.row()].enabled != enabled) {
+ m_ESPs[idx.row()].enabled = enabled;
+ dirty.append(m_ESPs[idx.row()].name);
}
}
+ if (!dirty.isEmpty()) {
+ emit writePluginsList();
+ pluginStatesChanged(dirty,
+ enabled ? IPluginList::PluginState::STATE_ACTIVE : IPluginList::PluginState::STATE_INACTIVE);
+ }
}
-void PluginList::disableSelected(const QItemSelectionModel *selectionModel)
+void PluginList::setEnabledAll(bool enabled)
{
- if (selectionModel->hasSelection()) {
- QStringList dirty;
- for (auto row : selectionModel->selectedRows(COL_PRIORITY)) {
- int rowIndex = findPluginByPriority(row.data().toInt());
- if (!m_ESPs[rowIndex].forceEnabled && m_ESPs[rowIndex].enabled) {
- m_ESPs[rowIndex].enabled = false;
- dirty.append(m_ESPs[rowIndex].name);
- }
- }
- if (!dirty.isEmpty()) {
- emit writePluginsList();
- pluginStatesChanged(dirty, IPluginList::PluginState::STATE_INACTIVE);
+ QStringList dirty;
+ for (ESPInfo &info : m_ESPs) {
+ if (info.enabled != enabled) {
+ info.enabled = enabled;
+ dirty.append(info.name);
}
}
+ if (!dirty.isEmpty()) {
+ emit writePluginsList();
+ pluginStatesChanged(dirty,
+ enabled ? IPluginList::PluginState::STATE_ACTIVE : IPluginList::PluginState::STATE_INACTIVE);
+ }
}
-
-void PluginList::enableAll()
+void PluginList::sendToPriority(const QModelIndexList& indices, int newPriority)
{
- if (QMessageBox::question(nullptr, tr("Confirm"), tr("Really enable all plugins?"),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- QStringList dirty;
- for (ESPInfo &info : m_ESPs) {
- if (!info.enabled) {
- info.enabled = true;
- dirty.append(info.name);
- }
- }
- if (!dirty.isEmpty()) {
- emit writePluginsList();
- pluginStatesChanged(dirty, IPluginList::PluginState::STATE_ACTIVE);
+ std::vector<int> pluginsToMove;
+ for (auto& idx : indices) {
+ if (!m_ESPs[idx.row()].forceEnabled) {
+ pluginsToMove.push_back(idx.row());
}
}
+ if (pluginsToMove.size()) {
+ changePluginPriority(pluginsToMove, newPriority);
+ }
}
-
-void PluginList::disableAll()
+void PluginList::shiftPluginsPriority(const QModelIndexList& indices, int offset)
{
- if (QMessageBox::question(nullptr, tr("Confirm"), tr("Really disable all plugins?"),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
- QStringList dirty;
- for (ESPInfo &info : m_ESPs) {
- if (!info.forceEnabled && info.enabled) {
- info.enabled = false;
- dirty.append(info.name);
- }
- }
- if (!dirty.isEmpty()) {
- emit writePluginsList();
- pluginStatesChanged(dirty, IPluginList::PluginState::STATE_INACTIVE);
+ // retrieve the plugin index and sort them by priority to avoid issue
+ // when moving them
+ std::vector<int> allIndex;
+ for (auto& idx : indices) {
+ allIndex.push_back(idx.row());
+ }
+ std::sort(allIndex.begin(), allIndex.end(), [=](int lhs, int rhs) {
+ bool cmp = m_ESPs[lhs].priority < m_ESPs[rhs].priority;
+ return offset > 0 ? !cmp : cmp;
+ });
+
+ for (auto index : allIndex) {
+ int newPriority = m_ESPs[index].priority + offset;
+ if (newPriority >= 0 && newPriority < rowCount()) {
+ setPluginPriority(index, newPriority);
}
}
+
+ refreshLoadOrder();
}
-void PluginList::sendToPriority(const QItemSelectionModel *selectionModel, int newPriority)
+void PluginList::toggleState(const QModelIndexList& indices)
{
- if (selectionModel->hasSelection()) {
- std::vector<int> pluginsToMove;
- for (auto row: selectionModel->selectedRows(COL_PRIORITY)) {
- int rowIndex = findPluginByPriority(row.data().toInt());
- if (!m_ESPs[rowIndex].forceEnabled) {
- pluginsToMove.push_back(rowIndex);
- }
+ QModelIndex minRow, maxRow;
+ for (auto& idx : indices) {
+ if (!minRow.isValid() || (idx.row() < minRow.row())) {
+ minRow = idx;
}
- if (pluginsToMove.size()) {
- changePluginPriority(pluginsToMove, newPriority);
+ if (!maxRow.isValid() || (idx.row() > maxRow.row())) {
+ maxRow = idx;
}
+ int oldState = idx.data(Qt::CheckStateRole).toInt();
+ setData(idx, oldState == Qt::Unchecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
}
+
+ emit dataChanged(minRow, maxRow);
}
bool PluginList::isEnabled(const QString &name)
@@ -541,7 +536,6 @@ void PluginList::writeLockedOrder(const QString &fileName) const
file.commit();
}
-
void PluginList::saveTo(const QString &lockedOrderFileName
, const QString& deleterFileName
, bool hideUnchecked) const
@@ -898,13 +892,11 @@ boost::signals2::connection PluginList::onRefreshed(const std::function<void ()>
return m_Refreshed.connect(callback);
}
-
boost::signals2::connection PluginList::onPluginMoved(const std::function<void (const QString &, int, int)> &func)
{
return m_PluginMoved.connect(func);
}
-
void PluginList::updateIndices()
{
m_ESPsByName.clear();
@@ -951,7 +943,6 @@ void PluginList::generatePluginIndexes()
emit esplist_changed();
}
-
int PluginList::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid()) {
@@ -966,7 +957,6 @@ int PluginList::columnCount(const QModelIndex &) const
return COL_LASTCOLUMN + 1;
}
-
void PluginList::testMasters()
{
std::set<QString> enabledMasters;
@@ -998,7 +988,7 @@ QVariant PluginList::data(const QModelIndex &modelIndex, int role) const
return checkstateData(modelIndex);
} else if (role == Qt::ForegroundRole) {
return foregroundData(modelIndex);
- } else if (role == Qt::BackgroundRole || (role == ViewMarkingScrollBar::DEFAULT_ROLE)) {
+ } else if (role == Qt::BackgroundRole) {
return backgroundData(modelIndex);
} else if (role == Qt::FontRole) {
return fontData(modelIndex);
@@ -1371,7 +1361,6 @@ bool PluginList::setData(const QModelIndex &modIndex, const QVariant &value, int
return result;
}
-
QVariant PluginList::headerData(int section, Qt::Orientation orientation,
int role) const
{
@@ -1385,7 +1374,6 @@ QVariant PluginList::headerData(int section, Qt::Orientation orientation,
return QAbstractItemModel::headerData(section, orientation, role);
}
-
Qt::ItemFlags PluginList::flags(const QModelIndex &modelIndex) const
{
int index = modelIndex.row();
@@ -1406,7 +1394,6 @@ Qt::ItemFlags PluginList::flags(const QModelIndex &modelIndex) const
return result;
}
-
void PluginList::setPluginPriority(int row, int &newPriority)
{
int newPriorityTemp = newPriority;
@@ -1464,7 +1451,6 @@ void PluginList::setPluginPriority(int row, int &newPriority)
updateIndices();
}
-
void PluginList::changePluginPriority(std::vector<int> rows, int newPriority)
{
ChangeBracket<PluginList> layoutChange(this);
@@ -1562,82 +1548,6 @@ QModelIndex PluginList::parent(const QModelIndex&) const
return QModelIndex();
}
-
-bool PluginList::eventFilter(QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::KeyPress) {
- QAbstractItemView *itemView = qobject_cast<QAbstractItemView*>(obj);
-
- if (itemView == nullptr) {
- return QAbstractItemModel::eventFilter(obj, event);
- }
-
- QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
- // ctrl+up and ctrl+down -> increase or decrease priority of selected plugins
- if ((keyEvent->modifiers() == Qt::ControlModifier) &&
- ((keyEvent->key() == Qt::Key_Up) || (keyEvent->key() == Qt::Key_Down))) {
- QItemSelectionModel *selectionModel = itemView->selectionModel();
- const QSortFilterProxyModel *proxyModel = qobject_cast<const QSortFilterProxyModel*>(selectionModel->model());
- if (proxyModel != nullptr) {
- int diff = -1;
- if (((keyEvent->key() == Qt::Key_Up) && (proxyModel->sortOrder() == Qt::DescendingOrder)) ||
- ((keyEvent->key() == Qt::Key_Down) && (proxyModel->sortOrder() == Qt::AscendingOrder))) {
- diff = 1;
- }
- QModelIndexList rows = selectionModel->selectedRows();
- // remove elements that aren't supposed to be movable
- QMutableListIterator<QModelIndex> iter(rows);
- while (iter.hasNext()) {
- if ((iter.next().flags() & Qt::ItemIsDragEnabled) == 0) {
- iter.remove();
- }
- }
- if (keyEvent->key() == Qt::Key_Down) {
- for (int i = 0; i < rows.size() / 2; ++i) {
- rows.swapItemsAt(i, rows.size() - i - 1);
- }
- }
- for (QModelIndex idx : rows) {
- idx = proxyModel->mapToSource(idx);
- int newPriority = m_ESPs[idx.row()].priority + diff;
- if ((newPriority >= 0) && (newPriority < rowCount())) {
- setPluginPriority(idx.row(), newPriority);
- }
- }
- refreshLoadOrder();
- }
- return true;
- } else if (keyEvent->key() == Qt::Key_Space) {
- QItemSelectionModel *selectionModel = itemView->selectionModel();
- const QSortFilterProxyModel *proxyModel = qobject_cast<const QSortFilterProxyModel*>(selectionModel->model());
- QList<QPersistentModelIndex> indices;
- for (QModelIndex idx : selectionModel->selectedRows()) {
- indices.append(idx);
- }
-
- QModelIndex minRow, maxRow;
- for (QModelIndex idx : indices) {
- if (proxyModel != nullptr) {
- idx = proxyModel->mapToSource(idx);
- }
- if (!minRow.isValid() || (idx.row() < minRow.row())) {
- minRow = idx;
- }
- if (!maxRow.isValid() || (idx.row() > maxRow.row())) {
- maxRow = idx;
- }
- int oldState = idx.data(Qt::CheckStateRole).toInt();
- setData(idx, oldState == Qt::Unchecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole);
- }
- emit dataChanged(minRow, maxRow);
-
- return true;
- }
- }
- return QAbstractItemModel::eventFilter(obj, event);
-}
-
-
PluginList::ESPInfo::ESPInfo(const QString &name, bool enabled,
const QString &originName, const QString &fullPath,
bool hasIni, std::set<QString> archives, bool lightPluginsAreSupported)