Qt/HostInterface: Track main window pointer

This commit is contained in:
Connor McLaughlin 2020-03-12 15:32:30 +10:00
parent 9e08ae6188
commit 0e3bcfa7b5
3 changed files with 18 additions and 4 deletions

View file

@ -24,6 +24,8 @@ static constexpr char DISC_IMAGE_FILTER[] =
MainWindow::MainWindow(QtHostInterface* host_interface) : QMainWindow(nullptr), m_host_interface(host_interface)
{
m_host_interface->setMainWindow(this);
m_ui.setupUi(this);
setupAdditionalUi();
connectSignals();
@ -34,6 +36,7 @@ MainWindow::MainWindow(QtHostInterface* host_interface) : QMainWindow(nullptr),
MainWindow::~MainWindow()
{
Assert(!m_display_widget);
m_host_interface->setMainWindow(nullptr);
}
void MainWindow::reportError(const QString& message)

View file

@ -10,6 +10,7 @@
#include "core/system.h"
#include "frontend-common/sdl_audio_stream.h"
#include "frontend-common/sdl_controller_interface.h"
#include "mainwindow.h"
#include "opengldisplaywidget.h"
#include "qtsettingsinterface.h"
#include "qtutils.h"
@ -147,6 +148,12 @@ void QtHostInterface::refreshGameList(bool invalidate_cache /* = false */, bool
emit gameListRefreshed();
}
void QtHostInterface::setMainWindow(MainWindow* window)
{
DebugAssert((!m_main_window && window) || (m_main_window && !window));
m_main_window = window;
}
QtDisplayWidget* QtHostInterface::createDisplayWidget()
{
Assert(!m_display_widget);

View file

@ -23,6 +23,7 @@ class QTimer;
class GameList;
class MainWindow;
class QtDisplayWidget;
Q_DECLARE_METATYPE(SystemBootParameters);
@ -44,14 +45,16 @@ public:
void putSettingValue(const QString& name, const QVariant& value);
void removeSettingValue(const QString& name);
const GameList* getGameList() const { return m_game_list.get(); }
GameList* getGameList() { return m_game_list.get(); }
ALWAYS_INLINE const GameList* getGameList() const { return m_game_list.get(); }
ALWAYS_INLINE GameList* getGameList() { return m_game_list.get(); }
void refreshGameList(bool invalidate_cache = false, bool invalidate_database = false);
const HotkeyInfoList& getHotkeyInfoList() const { return GetHotkeyInfoList(); }
ALWAYS_INLINE const HotkeyInfoList& getHotkeyInfoList() const { return GetHotkeyInfoList(); }
bool isOnWorkerThread() const { return QThread::currentThread() == m_worker_thread; }
ALWAYS_INLINE bool isOnWorkerThread() const { return QThread::currentThread() == m_worker_thread; }
ALWAYS_INLINE MainWindow* getMainWindow() const { return m_main_window; }
void setMainWindow(MainWindow* window);
QtDisplayWidget* createDisplayWidget();
void populateSaveStateMenus(const char* game_code, QMenu* load_menu, QMenu* save_menu);
@ -156,6 +159,7 @@ private:
QSettings m_qsettings;
std::mutex m_qsettings_mutex;
MainWindow* m_main_window = nullptr;
QtDisplayWidget* m_display_widget = nullptr;
QThread* m_original_thread = nullptr;
Thread* m_worker_thread = nullptr;