Added dynamic page extra info

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-06-07 00:16:23 +03:00
parent 3b9d822d72
commit 1e702ee40f
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
4 changed files with 35 additions and 13 deletions

View File

@ -35,15 +35,16 @@
#pragma once #pragma once
#include <QString>
#include <QIcon> #include <QIcon>
#include <QString>
#include <functional>
#include <memory> #include <memory>
#include "BasePageContainer.h" #include "BasePageContainer.h"
class BasePage class BasePage {
{ public:
public: using updateExtraInfoFunc = std::function<void(QString)>;
virtual ~BasePage() {} virtual ~BasePage() {}
virtual QString id() const = 0; virtual QString id() const = 0;
virtual QString displayName() const = 0; virtual QString displayName() const = 0;
@ -63,17 +64,16 @@ public:
} }
virtual void openedImpl() {} virtual void openedImpl() {}
virtual void closedImpl() {} virtual void closedImpl() {}
virtual void setParentContainer(BasePageContainer * container) virtual void setParentContainer(BasePageContainer* container) { m_container = container; };
{ virtual void retranslate() {}
m_container = container;
};
virtual void retranslate() { }
public: public:
int stackIndex = -1; int stackIndex = -1;
int listIndex = -1; int listIndex = -1;
protected: updateExtraInfoFunc updateExtraInfo;
BasePageContainer * m_container = nullptr;
protected:
BasePageContainer* m_container = nullptr;
bool isOpened = false; bool isOpened = false;
}; };

View File

@ -9,6 +9,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <algorithm>
ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent) ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent)
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model) : QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
@ -43,6 +44,13 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
auto selection_model = ui->treeView->selectionModel(); auto selection_model = ui->treeView->selectionModel();
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current); connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
auto updateExtra = [this]() {
if (updateExtraInfo)
updateExtraInfo(extraHeaderInfoString());
};
connect(selection_model, &QItemSelectionModel::selectionChanged, this, updateExtra);
connect(model.get(), &ResourceFolderModel::updateFinished, this, updateExtra);
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged); connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged);
} }
@ -248,6 +256,15 @@ bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, const
int row = sourceCurrent.row(); int row = sourceCurrent.row();
Resource const& resource = m_model->at(row); Resource const& resource = m_model->at(row);
ui->frame->updateWithResource(resource); ui->frame->updateWithResource(resource);
return true; return true;
} }
QString ExternalResourcesPage::extraHeaderInfoString()
{
if (ui && ui->treeView && ui->treeView->selectionModel()) {
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
if (auto count = std::count_if(selection.cbegin(), selection.cend(), [](auto v) { return v.column() == 0; }); count != 0)
return tr("[%1 installed, %2 selected]").arg(m_model->size()).arg(count);
}
return tr("[%1 installed]").arg(m_model->size());
}

View File

@ -29,6 +29,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
virtual QString helpPage() const override = 0; virtual QString helpPage() const override = 0;
virtual bool shouldDisplay() const override = 0; virtual bool shouldDisplay() const override = 0;
QString extraHeaderInfoString();
void openedImpl() override; void openedImpl() override;
void closedImpl() override; void closedImpl() override;

View File

@ -93,6 +93,10 @@ PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId,
page->listIndex = counter; page->listIndex = counter;
page->setParentContainer(this); page->setParentContainer(this);
counter++; counter++;
page->updateExtraInfo = [this](QString info) {
if (m_currentPage)
m_header->setText(m_currentPage->displayName() + info);
};
} }
m_model->setPages(pages); m_model->setPages(pages);