mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Store generated UI by pointer to avoid redundant processing
This commit is contained in:
parent
51b05647e2
commit
1ca2a0ef66
4 changed files with 81 additions and 42 deletions
|
@ -41,7 +41,6 @@ set(LAUNCHER_UI
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/ui/importpage.ui
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ui/settingspage.ui
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ui/directorypicker.ui
|
||||
${CMAKE_SOURCE_DIR}/components/contentselector/contentselector.ui
|
||||
)
|
||||
|
||||
source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER})
|
||||
|
|
|
@ -139,7 +139,6 @@ set (OPENCS_RES ${CMAKE_SOURCE_DIR}/files/opencs/resources.qrc
|
|||
)
|
||||
|
||||
set (OPENCS_UI
|
||||
${CMAKE_SOURCE_DIR}/components/contentselector/contentselector.ui
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ui/filedialog.ui
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "contentselector.hpp"
|
||||
|
||||
#include "ui_contentselector.h"
|
||||
|
||||
#include <components/contentselector/model/esmfile.hpp>
|
||||
|
||||
#include <QClipboard>
|
||||
|
@ -9,14 +11,15 @@
|
|||
|
||||
ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool showOMWScripts)
|
||||
: QObject(parent)
|
||||
, ui(std::make_unique<Ui::ContentSelector>())
|
||||
{
|
||||
ui.setupUi(parent);
|
||||
ui.addonView->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
ui->setupUi(parent);
|
||||
ui->addonView->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
if (!showOMWScripts)
|
||||
{
|
||||
ui.languageComboBox->setHidden(true);
|
||||
ui.refreshButton->setHidden(true);
|
||||
ui->languageComboBox->setHidden(true);
|
||||
ui->refreshButton->setHidden(true);
|
||||
}
|
||||
|
||||
buildContentModel(showOMWScripts);
|
||||
|
@ -24,21 +27,23 @@ ContentSelectorView::ContentSelector::ContentSelector(QWidget* parent, bool show
|
|||
buildAddonView();
|
||||
}
|
||||
|
||||
ContentSelectorView::ContentSelector::~ContentSelector() = default;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void ContentSelectorView::ContentSelector::buildGameFileView()
|
||||
{
|
||||
ui.gameFileView->addItem(tr("<No game file>"));
|
||||
ui.gameFileView->setVisible(true);
|
||||
ui->gameFileView->addItem(tr("<No game file>"));
|
||||
ui->gameFileView->setVisible(true);
|
||||
|
||||
connect(ui.gameFileView, qOverload<int>(&ComboBox::currentIndexChanged), this,
|
||||
connect(ui->gameFileView, qOverload<int>(&ComboBox::currentIndexChanged), this,
|
||||
&ContentSelector::slotCurrentGameFileIndexChanged);
|
||||
|
||||
ui.gameFileView->setCurrentIndex(0);
|
||||
ui->gameFileView->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
ui.addonView->setVisible(true);
|
||||
ui->addonView->setVisible(true);
|
||||
|
||||
mAddonProxyModel = new AddOnProxyModel(this);
|
||||
mAddonProxyModel->setFilterRegularExpression(searchFilter()->text());
|
||||
|
@ -70,12 +100,12 @@ void ContentSelectorView::ContentSelector::buildAddonView()
|
|||
mAddonProxyModel->setDynamicSortFilter(true);
|
||||
mAddonProxyModel->setSourceModel(mContentModel);
|
||||
|
||||
connect(ui.searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard);
|
||||
connect(ui.searchFilter, &QLineEdit::textEdited, this, &ContentSelector::slotSearchFilterTextChanged);
|
||||
connect(ui->searchFilter, &QLineEdit::textEdited, mAddonProxyModel, &QSortFilterProxyModel::setFilterWildcard);
|
||||
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,
|
||||
&ContentSelector::signalAddonDataChanged);
|
||||
buildContextMenu();
|
||||
|
@ -83,10 +113,10 @@ void ContentSelectorView::ContentSelector::buildAddonView()
|
|||
|
||||
void ContentSelectorView::ContentSelector::buildContextMenu()
|
||||
{
|
||||
ui.addonView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui.addonView, &QTableView::customContextMenuRequested, this, &ContentSelector::slotShowContextMenu);
|
||||
ui->addonView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
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("&Uncheck Selected"), this, SLOT(slotUncheckMultiSelectedItems()));
|
||||
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())
|
||||
{
|
||||
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
|
||||
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()
|
||||
|
@ -143,7 +173,7 @@ void ContentSelectorView::ContentSelector::setContentList(const QStringList& lis
|
|||
{
|
||||
if (list.isEmpty())
|
||||
{
|
||||
slotCurrentGameFileIndexChanged(ui.gameFileView->currentIndex());
|
||||
slotCurrentGameFileIndexChanged(ui->gameFileView->currentIndex());
|
||||
}
|
||||
else
|
||||
mContentModel->setContentList(list);
|
||||
|
@ -164,14 +194,14 @@ void ContentSelectorView::ContentSelector::addFiles(const QString& path, bool ne
|
|||
// add any game files to the combo box
|
||||
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)
|
||||
ui.gameFileView->setCurrentIndex(0);
|
||||
if (ui->gameFileView->currentIndex() != 0)
|
||||
ui->gameFileView->setCurrentIndex(0);
|
||||
|
||||
mContentModel->uncheckAll();
|
||||
mContentModel->checkForLoadOrderErrors();
|
||||
|
@ -194,10 +224,10 @@ void ContentSelectorView::ContentSelector::clearFiles()
|
|||
|
||||
QString ContentSelectorView::ContentSelector::currentFile() const
|
||||
{
|
||||
QModelIndex currentIdx = ui.addonView->currentIndex();
|
||||
QModelIndex currentIdx = ui->addonView->currentIndex();
|
||||
|
||||
if (!currentIdx.isValid() && ui.gameFileView->currentIndex() > 0)
|
||||
return ui.gameFileView->currentText();
|
||||
if (!currentIdx.isValid() && ui->gameFileView->currentIndex() > 0)
|
||||
return ui->gameFileView->currentText();
|
||||
|
||||
QModelIndex idx = mContentModel->index(mAddonProxyModel->mapToSource(currentIdx).row(), 0, QModelIndex());
|
||||
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)
|
||||
{
|
||||
QString fileName = ui.gameFileView->itemText(index);
|
||||
QString fileName = ui->gameFileView->itemText(index);
|
||||
const ContentSelectorModel::EsmFile* file = mContentModel->item(fileName);
|
||||
if (file != nullptr)
|
||||
{
|
||||
|
@ -253,14 +283,14 @@ void ContentSelectorView::ContentSelector::slotAddonTableItemActivated(const QMo
|
|||
|
||||
void ContentSelectorView::ContentSelector::slotShowContextMenu(const QPoint& pos)
|
||||
{
|
||||
QPoint globalPos = ui.addonView->viewport()->mapToGlobal(pos);
|
||||
QPoint globalPos = ui->addonView->viewport()->mapToGlobal(pos);
|
||||
mContextMenu->exec(globalPos);
|
||||
}
|
||||
|
||||
void ContentSelectorView::ContentSelector::setCheckStateForMultiSelectedItems(bool checked)
|
||||
{
|
||||
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);
|
||||
if (mContentModel->data(sourceIndex, Qt::CheckStateRole).toInt() != checkState)
|
||||
|
@ -284,7 +314,7 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths()
|
|||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
QString filepaths;
|
||||
for (const QModelIndex& index : ui.addonView->selectionModel()->selectedIndexes())
|
||||
for (const QModelIndex& index : ui->addonView->selectionModel()->selectedIndexes())
|
||||
{
|
||||
int row = mAddonProxyModel->mapToSource(index).row();
|
||||
const ContentSelectorModel::EsmFile* file = mContentModel->item(row);
|
||||
|
@ -299,5 +329,5 @@ void ContentSelectorView::ContentSelector::slotCopySelectedItemsPaths()
|
|||
|
||||
void ContentSelectorView::ContentSelector::slotSearchFilterTextChanged(const QString& newText)
|
||||
{
|
||||
ui.addonView->setDragEnabled(newText.isEmpty());
|
||||
ui->addonView->setDragEnabled(newText.isEmpty());
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
#ifndef CONTENTSELECTOR_HPP
|
||||
#define CONTENTSELECTOR_HPP
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QMenu>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "ui_contentselector.h"
|
||||
#include <components/contentselector/model/contentmodel.hpp>
|
||||
|
||||
class QSortFilterProxyModel;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ContentSelector;
|
||||
}
|
||||
|
||||
namespace ContentSelectorView
|
||||
{
|
||||
class ContentSelector : public QObject
|
||||
|
@ -23,6 +32,8 @@ namespace ContentSelectorView
|
|||
public:
|
||||
explicit ContentSelector(QWidget* parent = nullptr, bool showOMWScripts = false);
|
||||
|
||||
~ContentSelector() override;
|
||||
|
||||
QString currentFile() const;
|
||||
|
||||
void addFiles(const QString& path, bool newfiles = false);
|
||||
|
@ -39,18 +50,18 @@ namespace ContentSelectorView
|
|||
|
||||
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:
|
||||
Ui::ContentSelector ui;
|
||||
std::unique_ptr<Ui::ContentSelector> ui;
|
||||
|
||||
void buildContentModel(bool showOMWScripts);
|
||||
void buildGameFileView();
|
||||
|
|
Loading…
Reference in a new issue