mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Start doing some initialisation.
This commit is contained in:
@@ -4,6 +4,7 @@ from build.pkg import package
|
||||
import config
|
||||
|
||||
package(name="Qt5Widgets", package="Qt5Widgets")
|
||||
package(name="Qt5Concurrent", package="Qt5Concurrent")
|
||||
|
||||
normalrule(
|
||||
name="userinterface_h",
|
||||
@@ -57,6 +58,7 @@ cxxprogram(
|
||||
"+fmt_lib",
|
||||
"+protobuf_lib",
|
||||
".+Qt5Widgets",
|
||||
".+Qt5Concurrent",
|
||||
".+userinterface",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/globals.h"
|
||||
#include "userinterface.h"
|
||||
#include <QThreadPool>
|
||||
#include <QtConcurrent>
|
||||
|
||||
extern QThreadPool workerThreadPool;
|
||||
|
||||
class UserInterface : public Ui_MainWindow
|
||||
{
|
||||
@@ -12,7 +17,19 @@ public:
|
||||
Application(int& argc, char** argv): QApplication(argc, argv) {}
|
||||
virtual ~Application() {}
|
||||
|
||||
virtual void sendToUiThread(std::function<void()> callback) = 0;
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
extern std::unique_ptr<Application> app;
|
||||
template <typename F>
|
||||
auto runOnWorkerThread(F function)
|
||||
{
|
||||
return QtConcurrent::run(&workerThreadPool,
|
||||
[=]()
|
||||
{
|
||||
return function();
|
||||
});
|
||||
}
|
||||
|
||||
extern Application* app;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include "globals.h"
|
||||
#include "mainwindow.h"
|
||||
#include <QtConcurrent>
|
||||
|
||||
std::unique_ptr<Application> app;
|
||||
Application* app;
|
||||
QThreadPool workerThreadPool;
|
||||
|
||||
/* This has to go first due to C++ compiler limitations (has to be defined
|
||||
* before use). */
|
||||
class ApplicationImpl : public Application
|
||||
{
|
||||
public:
|
||||
@@ -13,6 +17,9 @@ public:
|
||||
_mainWindow->show();
|
||||
}
|
||||
|
||||
public:
|
||||
void sendToUiThread(std::function<void()> callback) override {}
|
||||
|
||||
private:
|
||||
std::unique_ptr<MainWindow> _mainWindow;
|
||||
};
|
||||
@@ -20,6 +27,8 @@ private:
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Q_INIT_RESOURCE(resources);
|
||||
app = std::make_unique<ApplicationImpl>(argc, argv);
|
||||
workerThreadPool.setMaxThreadCount(1);
|
||||
ApplicationImpl impl(argc, argv);
|
||||
app = &impl;
|
||||
return app->exec();
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
#include "lib/globals.h"
|
||||
#include "lib/proto.h"
|
||||
#include "lib/usb/usbfinder.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
class MainWindowImpl : public MainWindow
|
||||
@@ -10,6 +13,17 @@ public:
|
||||
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
|
||||
|
||||
setDriveConfigurationPane(noDriveConfigurationWidget);
|
||||
initialiseFormats();
|
||||
initialiseDevices();
|
||||
|
||||
connect(revolutionsSlider,
|
||||
&QSlider::valueChanged,
|
||||
revolutionsSpinBox,
|
||||
&QSpinBox::setValue);
|
||||
connect(revolutionsSpinBox,
|
||||
QOverload<int>::of(&QSpinBox::valueChanged),
|
||||
revolutionsSlider,
|
||||
&QSlider::setValue);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -18,6 +32,26 @@ public:
|
||||
for (auto* w : driveConfigurationContainer->findChildren<QWidget*>())
|
||||
w->setVisible(w == active);
|
||||
}
|
||||
|
||||
private:
|
||||
void initialiseFormats()
|
||||
{
|
||||
for (const auto& it : formats)
|
||||
{
|
||||
if (it.second->is_extension())
|
||||
continue;
|
||||
|
||||
formatsList->addItem(QString::fromStdString(it.first));
|
||||
}
|
||||
}
|
||||
|
||||
void initialiseDevices()
|
||||
{
|
||||
auto devices = runOnWorkerThread(findUsbDevices).result();
|
||||
|
||||
for (const auto& it : devices) {}
|
||||
fmt::print("device count = {}\n", devices.size());
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<MainWindow> MainWindow::create()
|
||||
|
||||
@@ -6,4 +6,6 @@ class MainWindow : public QMainWindow, public Ui_MainWindow
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<MainWindow> create();
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
@@ -350,14 +350,20 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QSlider" name="horizontalSlider">
|
||||
<widget class="QSlider" name="revolutionsSlider">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksAbove</enum>
|
||||
</property>
|
||||
<property name="tickInterval">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QSpinBox" name="spinBox_2"/>
|
||||
<widget class="QSpinBox" name="revolutionsSpinBox"/>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="4">
|
||||
<widget class="QFrame" name="frame">
|
||||
@@ -771,7 +777,7 @@ background: white;
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,100,0">
|
||||
<item row="0" column="2" colspan="2">
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<widget class="QComboBox" name="formatsList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
||||
Reference in New Issue
Block a user