Skip to content

Commit

Permalink
Merge branch 'autouic' into 'master'
Browse files Browse the repository at this point in the history
Move from qt_wrap_ui to AUTOUIC for all qt dependant components

See merge request OpenMW/openmw!4446
  • Loading branch information
AnyOldName3 committed Nov 10, 2024
2 parents ac7b54a + 306982c commit 0f0ed5a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 67 deletions.
16 changes: 2 additions & 14 deletions apps/launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ set(LAUNCHER_HEADER
utils/openalutil.hpp
)

# Headers that must be pre-processed
set(LAUNCHER_UI
${CMAKE_CURRENT_SOURCE_DIR}/ui/datafilespage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/graphicspage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/mainwindow.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/importpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/settingspage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/directorypicker.ui
)

source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER})

set(QT_USE_QTGUI 1)
Expand All @@ -57,9 +47,7 @@ if(WIN32)
endif(WIN32)

QT_ADD_RESOURCES(RCC_SRCS ${LAUNCHER_RES})
QT_WRAP_UI(UI_HDRS ${LAUNCHER_UI})

include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(NOT WIN32)
include_directories(${LIBUNSHIELD_INCLUDE_DIR})
endif(NOT WIN32)
Expand All @@ -70,8 +58,6 @@ openmw_add_executable(openmw-launcher
${LAUNCHER}
${LAUNCHER_HEADER}
${RCC_SRCS}
${MOC_SRCS}
${UI_HDRS}
)

add_dependencies(openmw-launcher qm-files)
Expand All @@ -95,6 +81,8 @@ endif()

if(USE_QT)
set_property(TARGET openmw-launcher PROPERTY AUTOMOC ON)
set_property(TARGET openmw-launcher PROPERTY AUTOUIC ON)
set_property(TARGET openmw-launcher PROPERTY AUTOUIC_SEARCH_PATHS ui)
endif(USE_QT)

if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
Expand Down
18 changes: 6 additions & 12 deletions apps/opencs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 22 additions & 17 deletions apps/opencs/view/doc/filedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -68,7 +73,7 @@ void CSVDoc::FileDialog::showDialog(ContentAction action)
{
mAction = action;

ui.projectGroupBoxLayout->insertWidget(0, mAdjusterWidget);
ui->projectGroupBoxLayout->insertWidget(0, mAdjusterWidget);

switch (mAction)
{
Expand All @@ -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;
}

Expand All @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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();
}

Expand All @@ -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();
}
12 changes: 9 additions & 3 deletions apps/opencs/view/doc/filedialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Q_DECLARE_METATYPE(std::filesystem::path)

#endif

#include "ui_filedialog.h"

#include <filesystem>
#include <vector>

Expand All @@ -26,6 +24,11 @@ namespace ContentSelectorView
class ContentSelector;
}

namespace Ui
{
class FileDialog;
}

namespace CSVDoc
{
class FileWidget;
Expand All @@ -36,14 +39,17 @@ namespace CSVDoc

private:
ContentSelectorView::ContentSelector* mSelector;
Ui::FileDialog ui;
std::unique_ptr<Ui::FileDialog> ui;
ContentAction mAction;
FileWidget* mFileWidget;
AdjusterWidget* mAdjusterWidget;
bool mDialogBuilt;

public:
explicit FileDialog(QWidget* parent = nullptr);

~FileDialog();

void showDialog(ContentAction action);

void addFiles(const std::vector<std::filesystem::path>& dataDirs);
Expand Down
18 changes: 2 additions & 16 deletions apps/wizard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,9 @@ set(WIZARD_HEADER
utils/componentlistwidget.hpp
)

set(WIZARD_UI
${CMAKE_CURRENT_SOURCE_DIR}/ui/componentselectionpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/conclusionpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/existinginstallationpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/importpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/installationtargetpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/intropage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/languageselectionpage.ui
${CMAKE_CURRENT_SOURCE_DIR}/ui/methodselectionpage.ui
)

if (OPENMW_USE_UNSHIELD)
set (WIZARD ${WIZARD} installationpage.cpp unshield/unshieldworker.cpp)
set (WIZARD_HEADER ${WIZARD_HEADER} installationpage.hpp unshield/unshieldworker.hpp)
set (WIZARD_UI ${WIZARD_UI} ${CMAKE_CURRENT_SOURCE_DIR}/ui/installationpage.ui)
add_definitions(-DOPENMW_USE_UNSHIELD)
endif (OPENMW_USE_UNSHIELD)

Expand All @@ -66,9 +54,6 @@ if(WIN32)
endif(WIN32)

QT_ADD_RESOURCES(RCC_SRCS ${WIZARD_RES})
QT_WRAP_UI(UI_HDRS ${WIZARD_UI})

include_directories(${CMAKE_CURRENT_BINARY_DIR})

if (OPENMW_USE_UNSHIELD)
include_directories(${LIBUNSHIELD_INCLUDE_DIRS})
Expand All @@ -79,7 +64,6 @@ openmw_add_executable(openmw-wizard
${WIZARD}
${WIZARD_HEADER}
${RCC_SRCS}
${UI_HDRS}
)

add_dependencies(openmw-wizard qm-files)
Expand Down Expand Up @@ -109,4 +93,6 @@ endif(WIN32)

if(USE_QT)
set_property(TARGET openmw-wizard PROPERTY AUTOMOC ON)
set_property(TARGET openmw-wizard PROPERTY AUTOUIC ON)
set_property(TARGET openmw-wizard PROPERTY AUTOUIC_SEARCH_PATHS ui)
endif(USE_QT)
8 changes: 3 additions & 5 deletions components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,6 @@ add_component_dir(testing
util
)

set (ESM_UI ${CMAKE_CURRENT_SOURCE_DIR}/contentselector/contentselector.ui
)

if (USE_QT)
add_component_qt_dir (contentselector
model/modelitem model/esmfile
Expand Down Expand Up @@ -558,7 +555,6 @@ if (USE_QT)
qtconversion
)

QT_WRAP_UI(ESM_UI_HDR ${ESM_UI})
endif()

include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
Expand Down Expand Up @@ -619,7 +615,7 @@ endif()
target_link_libraries(components ${BULLET_LIBRARIES})

if (USE_QT)
add_library(components_qt STATIC ${COMPONENT_QT_FILES} ${ESM_UI_HDR})
add_library(components_qt STATIC ${COMPONENT_QT_FILES})
target_link_libraries(components_qt components Qt::Widgets Qt::Core)

if (BUILD_LAUNCHER OR BUILD_WIZARD)
Expand Down Expand Up @@ -692,6 +688,8 @@ endif(OSG_STATIC)

if(USE_QT)
set_property(TARGET components_qt PROPERTY AUTOMOC ON)
set_property(TARGET components_qt PROPERTY AUTOUIC ON)
set_property(TARGET components_qt PROPERTY AUTOUIC_SEARCH_PATHS contentselector)
endif(USE_QT)

if (MSVC AND PRECOMPILE_HEADERS_WITH_MSVC)
Expand Down

0 comments on commit 0f0ed5a

Please sign in to comment.