Moved QApplication instance to main Application class
This commit is contained in:
@@ -28,52 +28,24 @@ namespace Bloom
|
||||
const ProjectConfig& projectConfig,
|
||||
const EnvironmentConfig& environmentConfig,
|
||||
const InsightConfig& insightConfig,
|
||||
InsightProjectSettings& insightProjectSettings
|
||||
InsightProjectSettings& insightProjectSettings,
|
||||
QApplication* parent
|
||||
)
|
||||
: eventListener(eventListener)
|
||||
: QObject(parent)
|
||||
, eventListener(eventListener)
|
||||
, projectConfig(projectConfig)
|
||||
, environmentConfig(environmentConfig)
|
||||
, insightConfig(insightConfig)
|
||||
, insightProjectSettings(insightProjectSettings)
|
||||
, application(
|
||||
(
|
||||
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true),
|
||||
#ifndef BLOOM_DEBUG_BUILD
|
||||
QCoreApplication::addLibraryPath(QString::fromStdString(Services::PathService::applicationDirPath() + "/plugins")),
|
||||
#endif
|
||||
QApplication(this->qtApplicationArgc, this->qtApplicationArgv.data())
|
||||
)
|
||||
)
|
||||
{}
|
||||
|
||||
void Insight::run() {
|
||||
try {
|
||||
this->startup();
|
||||
|
||||
this->threadState = ThreadState::READY;
|
||||
Logger::info("Insight ready");
|
||||
this->application.exec();
|
||||
|
||||
} catch (const Exception& exception) {
|
||||
Logger::error("Insight encountered a fatal error. See below for errors:");
|
||||
Logger::error(exception.getMessage());
|
||||
|
||||
} catch (const std::exception& exception) {
|
||||
Logger::error("Insight encountered a fatal error. See below for errors:");
|
||||
Logger::error(std::string(exception.what()));
|
||||
}
|
||||
|
||||
this->shutdown();
|
||||
}
|
||||
|
||||
void Insight::showMainWindow() {
|
||||
this->mainWindow->show();
|
||||
this->mainWindow->activateWindow();
|
||||
}
|
||||
|
||||
void Insight::startup() {
|
||||
void Insight::activate() {
|
||||
Logger::info("Starting Insight");
|
||||
this->threadState = ThreadState::STARTING;
|
||||
|
||||
this->eventListener.registerCallbackForEventType<Events::TargetExecutionStopped>(
|
||||
std::bind(&Insight::onTargetStoppedEvent, this, std::placeholders::_1)
|
||||
@@ -116,8 +88,6 @@ namespace Bloom
|
||||
throw Exception("Failed to open global stylesheet file");
|
||||
}
|
||||
|
||||
this->application.setStyleSheet(globalStylesheet.readAll());
|
||||
|
||||
qRegisterMetaType<Bloom::Targets::TargetDescriptor>();
|
||||
qRegisterMetaType<Bloom::Targets::TargetPinDescriptor>();
|
||||
qRegisterMetaType<Bloom::Targets::TargetPinState>();
|
||||
@@ -168,16 +138,6 @@ namespace Bloom
|
||||
QString::fromStdString(Services::PathService::resourcesDirPath() + "/fonts/Ubuntu/Ubuntu-Th.ttf")
|
||||
);
|
||||
|
||||
/*
|
||||
* We can't run our own event loop here - we have to use Qt's event loop. But we still need to be able to
|
||||
* process our events. To address this, we use a QTimer to dispatch our events on an interval.
|
||||
*
|
||||
* This allows us to use Qt's event loop whilst still being able to process our own events.
|
||||
*/
|
||||
auto* eventDispatchTimer = new QTimer(&(this->application));
|
||||
QObject::connect(eventDispatchTimer, &QTimer::timeout, this, &Insight::dispatchEvents);
|
||||
eventDispatchTimer->start(100);
|
||||
|
||||
QObject::connect(
|
||||
this->mainWindow,
|
||||
&InsightWindow::activatedSignal,
|
||||
@@ -185,6 +145,8 @@ namespace Bloom
|
||||
&Insight::onInsightWindowActivated
|
||||
);
|
||||
|
||||
this->mainWindow->setStyleSheet(globalStylesheet.readAll());
|
||||
|
||||
this->mainWindow->setInsightConfig(this->insightConfig);
|
||||
this->mainWindow->setEnvironmentConfig(this->environmentConfig);
|
||||
|
||||
@@ -212,10 +174,6 @@ namespace Bloom
|
||||
}
|
||||
|
||||
void Insight::shutdown() {
|
||||
if (this->getThreadState() == ThreadState::STOPPED) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info("Shutting down Insight");
|
||||
|
||||
this->mainWindow->close();
|
||||
@@ -230,9 +188,6 @@ namespace Bloom
|
||||
workerThread->wait();
|
||||
}
|
||||
}
|
||||
|
||||
this->application.exit(0);
|
||||
this->threadState = ThreadState::STOPPED;
|
||||
}
|
||||
|
||||
void Insight::checkBloomVersion() {
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Bloom
|
||||
*
|
||||
* The Insight component occupies the Bloom's main thread. See Application::run() for more.
|
||||
*/
|
||||
class Insight: public QObject, public Thread
|
||||
class Insight: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -53,13 +53,14 @@ namespace Bloom
|
||||
const ProjectConfig& projectConfig,
|
||||
const EnvironmentConfig& environmentConfig,
|
||||
const InsightConfig& insightConfig,
|
||||
InsightProjectSettings& insightProjectSettings
|
||||
InsightProjectSettings& insightProjectSettings,
|
||||
QApplication* parent
|
||||
);
|
||||
|
||||
/**
|
||||
* Entry point for Insight.
|
||||
*/
|
||||
void run();
|
||||
void activate();
|
||||
|
||||
/**
|
||||
* Opens main window and obtains focus.
|
||||
@@ -73,9 +74,6 @@ namespace Bloom
|
||||
|
||||
private:
|
||||
static constexpr std::uint8_t INSIGHT_WORKER_COUNT = 3;
|
||||
std::string qtApplicationName = "Bloom";
|
||||
std::array<char*, 1> qtApplicationArgv = {this->qtApplicationName.data()};
|
||||
int qtApplicationArgc = 1;
|
||||
|
||||
ProjectConfig projectConfig;
|
||||
EnvironmentConfig environmentConfig;
|
||||
@@ -86,8 +84,6 @@ namespace Bloom
|
||||
EventListener& eventListener;
|
||||
Services::TargetControllerService targetControllerService = Services::TargetControllerService();
|
||||
|
||||
QApplication application;
|
||||
|
||||
std::map<decltype(InsightWorker::id), std::pair<InsightWorker*, QThread*>> insightWorkersById;
|
||||
InsightWindow* mainWindow = new InsightWindow(
|
||||
this->environmentConfig,
|
||||
@@ -102,8 +98,6 @@ namespace Bloom
|
||||
|
||||
InsightSignals* insightSignals = InsightSignals::instance();
|
||||
|
||||
void startup();
|
||||
|
||||
/**
|
||||
* Queries the Bloom server for the latest version number. If the current version number doesn't match the
|
||||
* latest version number returned by the server, we'll display a warning in the logs to instruct the user to
|
||||
@@ -111,17 +105,6 @@ namespace Bloom
|
||||
*/
|
||||
void checkBloomVersion();
|
||||
|
||||
/**
|
||||
* Dispatches any events currently in the queue.
|
||||
*
|
||||
* Because Insight is effectively a Qt application, we cannot use our own event loop. We must use Qt's event
|
||||
* loop. We do this by utilizing a QTimer instance to call this method on an interval.
|
||||
* See Insight::startup() for more.
|
||||
*/
|
||||
void dispatchEvents() {
|
||||
this->eventListener.dispatchCurrentEvents();
|
||||
};
|
||||
|
||||
void onInsightWindowActivated();
|
||||
void onTargetStoppedEvent(const Events::TargetExecutionStopped& event);
|
||||
void onTargetResumedEvent(const Events::TargetExecutionResumed& event);
|
||||
|
||||
Reference in New Issue
Block a user