Store generated UI by pointer to avoid redundant processing

macos_ci_fix
Andrei Kortunov 1 year ago
parent 51b05647e2
commit 1ca2a0ef66

@ -41,7 +41,6 @@ set(LAUNCHER_UI
${CMAKE_CURRENT_SOURCE_DIR}/ui/importpage.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/importpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/settingspage.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/settingspage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/directorypicker.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/directorypicker.ui
${CMAKE_SOURCE_DIR}/components/contentselector/contentselector.ui
) )
source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER}) source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER})

@ -139,7 +139,6 @@ set (OPENCS_RES ${CMAKE_SOURCE_DIR}/files/opencs/resources.qrc
) )
set (OPENCS_UI set (OPENCS_UI
${CMAKE_SOURCE_DIR}/components/contentselector/contentselector.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/filedialog.ui ${CMAKE_CURRENT_SOURCE_DIR}/ui/filedialog.ui
) )

@ -1,5 +1,7 @@
#include "contentselector.hpp" #include "contentselector.hpp"
#include "ui_contentselector.h"
#include <components/contentselector/model/esmfile.hpp> #include <components/contentselector/model/esmfile.hpp>
#include <QClipboard> #include <QClipboard>
@ -9,14 +11,15 @@
ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool showOMWScripts) ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool showOMWScripts)
: QObject(parent) : QObject(parent)
, ui(std::make_unique<Ui::ContentSelector>())
{ {
ui.setupUi(parent); ui->setupUi(parent);
ui.addonView->setDragDropMode(QAbstractItemView::InternalMove); ui->addonView->setDragDropMode(QAbstractItemView::InternalMove);
if (!showOMWScripts) if (!showOMWScripts)
{ {
ui.languageComboBox->setHidden(true); ui->languageComboBox->setHidden(true);
ui.refreshButton->setHidden(true); ui->refreshButton->setHidden(true);
} }
buildContentModel(showOMWScripts); buildContentModel(showOMWScripts);
@ -24,21 +27,23 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool show
buildAddonView(); buildAddonView();
} }
ContentSelectorView::ContentSelector::~ContentSelector() = default;
void ContentSelectorView::ContentSelector::buildContentModel(bool showOMWScripts) void ContentSelectorView::ContentSelector::buildContentModel(bool showOMWScripts)
{ {
QIcon warningIcon(ui.addonView->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(16, 15))); QIcon warningIcon(ui->addonView->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(16, 15)));
mContentModel = new ContentSelectorModel::ContentModel(this, warningIcon, showOMWScripts); mContentModel = new ContentSelectorModel::ContentModel(this, warningIcon, showOMWScripts);
} }
void ContentSelectorView::ContentSelector::buildGameFileView() void ContentSelectorView::ContentSelector::buildGameFileView()
{ {
ui.gameFileView->addItem(tr("<No game file>")); ui->gameFileView->addItem(tr("<No game file>"));
ui.gameFileView->setVisible(true); ui->gameFileView->setVisible(true);
connect(ui.gameFileView, qOverload<int>(&ComboBox::currentIndexChanged), this, connect(ui->gameFileView, qOverload<int>(&ComboBox::currentIndexChanged), this,
&ContentSelector::slotCurrentGameFileIndexChanged); &ContentSelector::slotCurrentGameFileIndexChanged);
ui.gameFileView->setCurrentIndex(0); ui->gameFileView->setCurrentIndex(0);
} }
class AddOnProxyModel : public QSortFilterProxyModel class AddOnProxyModel : public QSortFilterProxyModel
@ -60,9 +65,34 @@ public:
} }
}; };
bool ContentSelectorView::ContentSelector::isGamefileSelected() const
{
return ui->gameFileView->currentIndex() > 0;
}
QWidget* ContentSelectorView::ContentSelector::uiWidget() const
{
return ui->contentGroupBox;
}
QComboBox* ContentSelectorView::ContentSelector::languageBox() const
{
return ui->languageComboBox;
}
QToolButton* ContentSelectorView::ContentSelector::refreshButton() const
{
return ui->refreshButton;
}
QLineEdit* ContentSelectorView::ContentSelector::searchFilter() const
{
return ui->searchFilter;
}
void ContentSelectorView::ContentSelector::buildAddonView() void ContentSelectorView::ContentSelector::buildAddonView()
{ {
ui.addonView->setVisible(true); ui->addonView->setVisible(true);
mAddonProxyModel = new AddOnProxyModel(this); mAddonProxyModel = new AddOnProxyModel(this);
mAddonProxyModel->setFilterRegularExpression(searchFilter()->text()); mAddonProxyModel->setFilterRegularExpression(searchFilter()->text());
@ -70,12 +100,12 @@ void ContentSelectorView::ContentSelector::buildAddonView()
mAddonProxyModel->setDynamicSortFilter(true); mAddonProxyModel->setDynamicSortFilter(true);
mAddonProxyModel->setSourceModel(mContentModel); mAddonProxyModel->setSourceModel(mContentModel);
connect(ui.searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard); connect(ui->searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard);
connect(ui.searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged); connect(ui->searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged);
ui.addonView->setModel(mAddonProxyModel); ui->addonView->setModel(mAddonProxyModel);
connect(ui.addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated); connect(ui->addonView, &QTableView::activated, this, &ContentSelector::slotAddonTableItemActivated);
connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this, connect(mContentModel, &ContentSelectorModel::ContentModel::dataChanged, this,
&ContentSelector::signalAddonDataChanged); &ContentSelector::signalAddonDataChanged);
buildContextMenu(); buildContextMenu();
@ -83,10 +113,10 @@ void ContentSelectorView::ContentSelector::buildAddonView()
void ContentSelectorView::ContentSelector::buildContextMenu() void ContentSelectorView::ContentSelector::buildContextMenu()
{ {
ui.addonView->setContextMenuPolicy(Qt::CustomContextMenu); ui->addonView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui.addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu); connect(ui->addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu);
mContextMenu = new QMenu(ui.addonView); mContextMenu = new QMenu(ui->addonView);
mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems())); mContextMenu->addAction(tr("&Check Selected"), this, SLOT(slotCheckMultiSelectedItems()));
mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems())); mContextMenu->addAction(tr("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems()));
mContextMenu->addAction(tr("&Copy Path(s) to Clipboard"), this, SLOT(slotCopySelectedItemsPaths())); mContextMenu->addAction(tr("&Copy Path(s) to Clipboard"), this, SLOT(slotCopySelectedItemsPaths()));
@ -116,7 +146,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename)
if (!filename.isEmpty()) if (!filename.isEmpty())
{ {
const ContentSelectorModel::EsmFile* file = mContentModel->item(filename); const ContentSelectorModel::EsmFile* file = mContentModel->item(filename);
index = ui.gameFileView->findText(file->fileName()); index = ui->gameFileView->findText(file->fileName());
// verify that the current index is also checked in the model // verify that the current index is also checked in the model
if (!mContentModel->setCheckState(filename, true)) if (!mContentModel->setCheckState(filename, true))
@ -126,7 +156,7 @@ void ContentSelectorView::ContentSelector::setGameFile(const QString& filename)
} }
} }
ui.gameFileView->setCurrentIndex(index); ui->gameFileView->setCurrentIndex(index);
} }
void ContentSelectorView::ContentSelector::clearCheckStates() void ContentSelectorView::ContentSelector::clearCheckStates()
@ -143,7 +173,7 @@ void ContentSelectorView::ContentSelector::setContentList(const QStringList& lis
{ {
if (list.isEmpty()) if (list.isEmpty())
{ {
slotCurrentGameFileIndexChanged(ui.gameFileView->currentIndex()); slotCurrentGameFileIndexChanged(ui->gameFileView->currentIndex());
} }
else else
mContentModel->setContentList(list); mContentModel->setContentList(list);
@ -164,14 +194,14 @@ void ContentSelectorView::ContentSelector::addFiles(const QString& path, bool ne
// add any game files to the combo box // add any game files to the combo box
for (const QString& gameFileName : mContentModel->gameFiles()) for (const QString& gameFileName : mContentModel->gameFiles())
{ {
if (ui.gameFileView->findText(gameFileName) == -1) if (ui->gameFileView->findText(gameFileName) == -1)
{ {
ui.gameFileView->addItem(gameFileName); ui->gameFileView->addItem(gameFileName);
} }
} }
if (ui.gameFileView->currentIndex() != 0) if (ui->gameFileView->currentIndex() != 0)
ui.gameFileView->setCurrentIndex(0); ui->gameFileView->setCurrentIndex(0);
mContentModel->uncheckAll(); mContentModel->uncheckAll();
mContentModel->checkForLoadOrderErrors(); mContentModel->checkForLoadOrderErrors();
@ -194,10 +224,10 @@ void ContentSelectorView::ContentSelector::clearFiles()
QString ContentSelectorView::ContentSelector::currentFile() const QString ContentSelectorView::ContentSelector::currentFile() const
{ {
QModelIndex currentIdx = ui.addonView->currentIndex(); QModelIndex currentIdx = ui->addonView->currentIndex();
if (!currentIdx.isValid() && ui.gameFileView->currentIndex() > 0) if (!currentIdx.isValid() && ui->gameFileView->currentIndex() > 0)
return ui.gameFileView->currentText(); return ui->gameFileView->currentText();
QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex()); QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex());
return mContentModel->data(idx, Qt::DisplayRole).toString(); return mContentModel->data(idx, Qt::DisplayRole).toString();
@ -225,7 +255,7 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool selected) void ContentSelectorView::ContentSelector::setGameFileSelected(int index, bool selected)
{ {
QString fileName = ui.gameFileView->itemText(index); QString fileName = ui->gameFileView->itemText(index);
const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName); const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName);
if (file != nullptr) if (file != nullptr)
{ {
@ -253,14 +283,14 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QMo
void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos) void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos)
{ {
QPoint globalPos = ui.addonView->viewport()->mapToGlobal(pos); QPoint globalPos = ui->addonView->viewport()->mapToGlobal(pos);
mContextMenu->exec(globalPos); mContextMenu->exec(globalPos);
} }
void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked) void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked)
{ {
Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked; Qt::CheckState checkState = checked ? Qt::Checked : Qt::Unchecked;
for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes()) for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes())
{ {
QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index); QModelIndex sourceIndex = mAddonProxyModel->mapToSource(index);
if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState) if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState)
@ -284,7 +314,7 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths()
{ {
QClipboard* clipboard = QApplication::clipboard(); QClipboard* clipboard = QApplication::clipboard();
QString filepaths; QString filepaths;
for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes()) for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes())
{ {
int row = mAddonProxyModel->mapToSource(index).row(); int row = mAddonProxyModel->mapToSource(index).row();
const ContentSelectorModel::EsmFile* file = mContentModel->item(row); const ContentSelectorModel::EsmFile* file = mContentModel->item(row);
@ -299,5 +329,5 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths()
void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QString& newText) void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QString& newText)
{ {
ui.addonView->setDragEnabled(newText.isEmpty()); ui->addonView->setDragEnabled(newText.isEmpty());
} }

@ -1,13 +1,22 @@
#ifndef CONTENTSELECTOR_HPP #ifndef CONTENTSELECTOR_HPP
#define CONTENTSELECTOR_HPP #define CONTENTSELECTOR_HPP
#include <memory>
#include <QComboBox>
#include <QDialog> #include <QDialog>
#include <QMenu>
#include <QToolButton>
#include "ui_contentselector.h"
#include <components/contentselector/model/contentmodel.hpp> #include <components/contentselector/model/contentmodel.hpp>
class QSortFilterProxyModel; class QSortFilterProxyModel;
namespace Ui
{
class ContentSelector;
}
namespace ContentSelectorView namespace ContentSelectorView
{ {
class ContentSelector : public QObject class ContentSelector : public QObject
@ -23,6 +32,8 @@ namespace ContentSelectorView
public: public:
explicit ContentSelector(QWidget* parent = nullptr, bool showOMWScripts = false); explicit ContentSelector(QWidget* parent = nullptr, bool showOMWScripts = false);
~ContentSelector() override;
QString currentFile() const; QString currentFile() const;
void addFiles(const QString& path, bool newfiles = false); void addFiles(const QString& path, bool newfiles = false);
@ -39,18 +50,18 @@ namespace ContentSelectorView
void setGameFile(const QString& filename = QString("")); void setGameFile(const QString& filename = QString(""));
bool isGamefileSelected() const { return ui.gameFileView->currentIndex() > 0; } bool isGamefileSelected() const;
QWidget* uiWidget() const { return ui.contentGroupBox; } QWidget* uiWidget() const;
QComboBox* languageBox() const { return ui.languageComboBox; } QComboBox* languageBox() const;
QToolButton* refreshButton() const { return ui.refreshButton; } QToolButton* refreshButton() const;
QLineEdit* searchFilter() const { return ui.searchFilter; } QLineEdit* searchFilter() const;
private: private:
Ui::ContentSelector ui; std::unique_ptr<Ui::ContentSelector> ui;
void buildContentModel(bool showOMWScripts); void buildContentModel(bool showOMWScripts);
void buildGameFileView(); void buildGameFileView();

Loading…
Cancel
Save