diff options
| -rw-r--r-- | src/mainwindow.cpp | 15 | ||||
| -rw-r--r-- | src/mainwindow.h | 1 | ||||
| -rw-r--r-- | src/mainwindow.ui | 8 | ||||
| -rw-r--r-- | src/modlistsortproxy.cpp | 58 | ||||
| -rw-r--r-- | src/modlistsortproxy.h | 8 |
5 files changed, 77 insertions, 13 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3b7fa917..44381864 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -285,14 +285,17 @@ MainWindow::MainWindow(QSettings &initSettings ui->modList->setItemDelegateForColumn(ModList::COL_FLAGS, new ModFlagIconDelegate(ui->modList));
ui->modList->setItemDelegateForColumn(ModList::COL_CONTENT, contentDelegate);
ui->modList->header()->installEventFilter(m_OrganizerCore.modList());
+ connect(ui->modList->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(modListSectionResized(int, int, int)));
bool modListAdjusted = registerWidgetState(ui->modList->objectName(), ui->modList->header(), "mod_list_state");
if (modListAdjusted) {
// hack: force the resize-signal to be triggered because restoreState doesn't seem to do that
- int sectionSize = ui->modList->header()->sectionSize(ModList::COL_CONTENT);
- ui->modList->header()->resizeSection(ModList::COL_CONTENT, sectionSize + 1);
- ui->modList->header()->resizeSection(ModList::COL_CONTENT, sectionSize);
+ for (int column = 0; column <= ModList::COL_LASTCOLUMN; ++column) {
+ int sectionSize = ui->modList->header()->sectionSize(column);
+ ui->modList->header()->resizeSection(column, sectionSize + 1);
+ ui->modList->header()->resizeSection(column, sectionSize);
+ }
} else {
// hide these columns by default
ui->modList->header()->setSectionHidden(ModList::COL_CONTENT, true);
@@ -2474,6 +2477,12 @@ void MainWindow::modListSortIndicatorChanged(int, Qt::SortOrder) ui->modList->verticalScrollBar()->repaint();
}
+void MainWindow::modListSectionResized(int logicalIndex, int oldSize, int newSize)
+{
+ bool enabled = (newSize != 0);
+ qobject_cast<ModListSortProxy *>(ui->modList->model())->setColumnVisible(logicalIndex, enabled);
+}
+
void MainWindow::removeMod_clicked()
{
try {
diff --git a/src/mainwindow.h b/src/mainwindow.h index e799a64a..f66ea5e7 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -577,6 +577,7 @@ private slots: void modlistSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
void modListSortIndicatorChanged(int column, Qt::SortOrder order);
+ void modListSectionResized(int logicalIndex, int oldSize, int newSize);
void modlistSelectionsChanged(const QItemSelection ¤t);
void esplistSelectionsChanged(const QItemSelection ¤t);
diff --git a/src/mainwindow.ui b/src/mainwindow.ui index e42bed27..7e94000d 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -448,7 +448,7 @@ p, li { white-space: pre-wrap; } <bool>false</bool>
</property>
<attribute name="headerDefaultSectionSize">
- <number>20</number>
+ <number>35</number>
</attribute>
<attribute name="headerShowSortIndicator" stdset="0">
<bool>true</bool>
@@ -612,7 +612,7 @@ p, li { white-space: pre-wrap; } </size>
</property>
<property name="placeholderText">
- <string>Namefilter</string>
+ <string>Filter</string>
</property>
</widget>
</item>
@@ -999,7 +999,7 @@ p, li { white-space: pre-wrap; } <string/>
</property>
<property name="placeholderText">
- <string>Namefilter</string>
+ <string>Filter</string>
</property>
</widget>
</item>
@@ -1338,7 +1338,7 @@ p, li { white-space: pre-wrap; } <item>
<widget class="MOBase::LineEditClear" name="downloadFilterEdit">
<property name="placeholderText">
- <string>Namefilter</string>
+ <string>Filter</string>
</property>
</widget>
</item>
diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 9adaa511..b5f1ee5c 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -39,10 +39,6 @@ ModListSortProxy::ModListSortProxy(Profile* profile, QObject *parent) , m_FilterActive(false)
, m_FilterMode(FILTER_AND)
{
- m_EnabledColumns.set(ModList::COL_FLAGS);
- m_EnabledColumns.set(ModList::COL_NAME);
- m_EnabledColumns.set(ModList::COL_VERSION);
- m_EnabledColumns.set(ModList::COL_PRIORITY);
setDynamicSortFilter(true); // this seems to work without dynamicsortfilter
// but I don't know why. This should be necessary
}
@@ -340,8 +336,53 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const
{
- if (!m_CurrentFilter.isEmpty() &&
- !info->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) {
+ bool display = true;
+ if (!m_CurrentFilter.isEmpty()) {
+ display = false;
+
+ // Search by name
+ if (!display &&
+ m_EnabledColumns[ModList::COL_NAME] &&
+ info->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) {
+ display = true;
+ }
+
+ // Search by notes
+ if (!display &&
+ m_EnabledColumns[ModList::COL_NOTES] &&
+ info->comments().contains(m_CurrentFilter, Qt::CaseInsensitive)) {
+ display = true;
+ }
+
+ // Search by Nexus ID
+ if (!display &&
+ m_EnabledColumns[ModList::COL_MODID]) {
+ bool ok;
+ int filterID = m_CurrentFilter.toInt(&ok);
+ if (ok) {
+ int modID = info->getNexusID();
+ while (modID > 0) {
+ if (modID == filterID) {
+ display = true;
+ break;
+ }
+ modID = (int)(modID / 10);
+ }
+ }
+ }
+
+ // Search by categories
+ if (!display &&
+ m_EnabledColumns[ModList::COL_CATEGORY]) {
+ for (auto category : info->categories()) {
+ if (category.contains(m_CurrentFilter, Qt::CaseInsensitive)) {
+ display = true;
+ break;
+ }
+ }
+ }
+ }
+ if (!display) {
return false;
}
@@ -352,6 +393,11 @@ bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const }
}
+void ModListSortProxy::setColumnVisible(int column, bool visible)
+{
+ m_EnabledColumns[column] = visible;
+}
+
void ModListSortProxy::setFilterMode(ModListSortProxy::FilterMode mode)
{
if (m_FilterMode != mode) {
diff --git a/src/modlistsortproxy.h b/src/modlistsortproxy.h index b3c01fea..5fe8d9d6 100644 --- a/src/modlistsortproxy.h +++ b/src/modlistsortproxy.h @@ -60,6 +60,7 @@ public: virtual void setSourceModel(QAbstractItemModel *sourceModel) override;
+
/**
* @brief enable all mods visible under the current filter
**/
@@ -94,6 +95,13 @@ public: return rowCount(parent) > 0;
}
+ /**
+ * @brief sets whether a column is visible
+ * @param column the index of the column
+ * @param visible the visibility of the column
+ */
+ void setColumnVisible(int column, bool visible);
+
public slots:
void updateFilter(const QString &filter);
|
