1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-01 08:06:41 +00:00

Move from qt_wrap_ui to AUTOUIC for opencs

Set opencs target properties in appropriate section
Use forward declaration for Ui::FileDialog

(#7348)
This commit is contained in:
Pi03k 2024-11-07 21:44:52 +01:00
parent 05a71e982d
commit 306982cdd1
3 changed files with 37 additions and 32 deletions

View file

@ -137,10 +137,6 @@ set (OPENCS_RES ${CMAKE_SOURCE_DIR}/files/opencs/resources.qrc
${CMAKE_SOURCE_DIR}/files/launcher/launcher.qrc
)
set (OPENCS_UI
${CMAKE_CURRENT_SOURCE_DIR}/ui/filedialog.ui
)
source_group (openmw-cs FILES main.cpp ${OPENCS_SRC} ${OPENCS_HDR})
if(WIN32)
@ -151,16 +147,8 @@ else(WIN32)
set(OPENCS_RC_FILE "")
endif(WIN32)
if (QT_VERSION_MAJOR VERSION_EQUAL 5)
qt5_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})
else ()
qt6_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI})
endif()
qt_add_resources(OPENCS_RES_SRC ${OPENCS_RES})
# for compiled .ui files
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(APPLE)
set (OPENCS_MAC_ICON "${CMAKE_SOURCE_DIR}/files/mac/openmw-cs.icns")
set (OPENCS_CFG "${OpenMW_BINARY_DIR}/defaults-cs.bin")
@ -193,6 +181,10 @@ if(BUILD_OPENCS)
target_link_libraries(openmw-cs openmw-cs-lib)
set_property(TARGET openmw-cs PROPERTY AUTOMOC ON)
set_property(TARGET openmw-cs PROPERTY AUTOUIC_SEARCH_PATHS ui)
set_property(TARGET openmw-cs PROPERTY AUTOUIC ON)
if (BUILD_WITH_CODE_COVERAGE)
target_compile_options(openmw-cs PRIVATE --coverage)
target_link_libraries(openmw-cs gcov)
@ -284,6 +276,8 @@ endif()
if(USE_QT)
set_property(TARGET openmw-cs-lib PROPERTY AUTOMOC ON)
set_property(TARGET openmw-cs-lib PROPERTY AUTOUIC_SEARCH_PATHS ui)
set_property(TARGET openmw-cs-lib PROPERTY AUTOUIC ON)
endif(USE_QT)
if (BUILD_WITH_CODE_COVERAGE)

View file

@ -13,22 +13,27 @@
#include "adjusterwidget.hpp"
#include "filewidget.hpp"
#include "ui_filedialog.h"
CSVDoc::FileDialog::FileDialog(QWidget* parent)
: QDialog(parent)
, mSelector(nullptr)
, ui(std::make_unique<Ui::FileDialog>())
, mAction(ContentAction_Undefined)
, mFileWidget(nullptr)
, mAdjusterWidget(nullptr)
, mDialogBuilt(false)
{
ui.setupUi(this);
ui->setupUi(this);
resize(400, 400);
setObjectName("FileDialog");
mSelector = new ContentSelectorView::ContentSelector(ui.contentSelectorWidget, /*showOMWScripts=*/false);
mSelector = new ContentSelectorView::ContentSelector(ui->contentSelectorWidget, /*showOMWScripts=*/false);
mAdjusterWidget = new AdjusterWidget(this);
}
CSVDoc::FileDialog::~FileDialog() = default;
void CSVDoc::FileDialog::addFiles(const std::vector<std::filesystem::path>& dataDirs)
{
for (auto iter = dataDirs.rbegin(); iter != dataDirs.rend(); ++iter)
@ -68,7 +73,7 @@ void CSVDoc::FileDialog::showDialog(ContentAction action)
{
mAction = action;
ui.projectGroupBoxLayout->insertWidget(0, mAdjusterWidget);
ui->projectGroupBoxLayout->insertWidget(0, mAdjusterWidget);
switch (mAction)
{
@ -92,7 +97,7 @@ void CSVDoc::FileDialog::showDialog(ContentAction action)
connect(mSelector, &ContentSelectorView::ContentSelector::signalCurrentGamefileIndexChanged, this,
qOverload<int>(&FileDialog::slotUpdateAcceptButton));
connect(ui.projectButtonBox, &QDialogButtonBox::rejected, this, &FileDialog::slotRejected);
connect(ui->projectButtonBox, &QDialogButtonBox::rejected, this, &FileDialog::slotRejected);
mDialogBuilt = true;
}
@ -105,7 +110,7 @@ void CSVDoc::FileDialog::buildNewFileView()
{
setWindowTitle(tr("Create a new addon"));
QPushButton* createButton = ui.projectButtonBox->button(QDialogButtonBox::Ok);
QPushButton* createButton = ui->projectButtonBox->button(QDialogButtonBox::Ok);
createButton->setText("Create");
createButton->setEnabled(false);
@ -122,27 +127,27 @@ void CSVDoc::FileDialog::buildNewFileView()
qOverload<const QString&, bool>(&FileDialog::slotUpdateAcceptButton));
}
ui.projectGroupBoxLayout->insertWidget(0, mFileWidget);
ui->projectGroupBoxLayout->insertWidget(0, mFileWidget);
connect(ui.projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotNewFile);
connect(ui->projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotNewFile);
}
void CSVDoc::FileDialog::buildOpenFileView()
{
setWindowTitle(tr("Open"));
ui.projectGroupBox->setTitle(QString(""));
ui.projectButtonBox->button(QDialogButtonBox::Ok)->setText("Open");
ui->projectGroupBox->setTitle(QString(""));
ui->projectButtonBox->button(QDialogButtonBox::Ok)->setText("Open");
if (mSelector->isGamefileSelected())
ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
ui->projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
else
ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
ui->projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
if (!mDialogBuilt)
{
connect(mSelector, &ContentSelectorView::ContentSelector::signalAddonDataChanged, this,
&FileDialog::slotAddonDataChanged);
}
connect(ui.projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotOpenFile);
connect(ui->projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotOpenFile);
}
void CSVDoc::FileDialog::slotAddonDataChanged(const QModelIndex& topleft, const QModelIndex& bottomright)
@ -176,7 +181,7 @@ void CSVDoc::FileDialog::slotUpdateAcceptButton(const QString& name, bool)
else
mAdjusterWidget->setName("", true);
ui.projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled(success);
ui->projectButtonBox->button(QDialogButtonBox::Ok)->setEnabled(success);
}
QString CSVDoc::FileDialog::filename() const
@ -190,8 +195,8 @@ QString CSVDoc::FileDialog::filename() const
void CSVDoc::FileDialog::slotRejected()
{
emit rejected();
disconnect(ui.projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotNewFile);
disconnect(ui.projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotOpenFile);
disconnect(ui->projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotNewFile);
disconnect(ui->projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotOpenFile);
if (mFileWidget)
{
delete mFileWidget;
@ -208,7 +213,7 @@ void CSVDoc::FileDialog::slotNewFile()
delete mFileWidget;
mFileWidget = nullptr;
}
disconnect(ui.projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotNewFile);
disconnect(ui->projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotNewFile);
close();
}
@ -219,6 +224,6 @@ void CSVDoc::FileDialog::slotOpenFile()
mAdjusterWidget->setName(file->filePath(), !file->isGameFile());
emit signalOpenFiles(mAdjusterWidget->getPath());
disconnect(ui.projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotOpenFile);
disconnect(ui->projectButtonBox, &QDialogButtonBox::accepted, this, &FileDialog::slotOpenFile);
close();
}

View file

@ -14,8 +14,6 @@ Q_DECLARE_METATYPE(std::filesystem::path)
#endif
#include "ui_filedialog.h"
#include <filesystem>
#include <vector>
@ -26,6 +24,11 @@ namespace ContentSelectorView
class ContentSelector;
}
namespace Ui
{
class FileDialog;
}
namespace CSVDoc
{
class FileWidget;
@ -36,7 +39,7 @@ namespace CSVDoc
private:
ContentSelectorView::ContentSelector* mSelector;
Ui::FileDialog ui;
std::unique_ptr<Ui::FileDialog> ui;
ContentAction mAction;
FileWidget* mFileWidget;
AdjusterWidget* mAdjusterWidget;
@ -44,6 +47,9 @@ namespace CSVDoc
public:
explicit FileDialog(QWidget* parent = nullptr);
~FileDialog();
void showDialog(ContentAction action);
void addFiles(const std::vector<std::filesystem::path>& dataDirs);