A fair chunk of the drive component now works.

This commit is contained in:
David Given
2024-01-15 00:01:57 +01:00
parent 7567c8a609
commit 4ea12d2e1d
9 changed files with 172 additions and 25 deletions

View File

@@ -38,6 +38,16 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
@@ -66,6 +76,9 @@
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QRadioButton" name="defaultSampleTimeCheckbox"> <widget class="QRadioButton" name="defaultSampleTimeCheckbox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Default for format</string> <string>Default for format</string>
</property> </property>
@@ -78,6 +91,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>
<widget class="QRadioButton" name="customSampleTimeCheckBox"> <widget class="QRadioButton" name="customSampleTimeCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Custom:</string> <string>Custom:</string>
</property> </property>

View File

@@ -7,13 +7,18 @@
#include "fluxConfigurationForm.h" #include "fluxConfigurationForm.h"
#include <QStandardItemModel> #include <QStandardItemModel>
static const char* DRIVE = "drive/";
static const char* SELECTED_DRIVE = "drive/drive";
class DriveComponentImpl : public DriveComponent, public QObject class DriveComponentImpl : public DriveComponent, public QObject
{ {
W_OBJECT(DriveComponentImpl) W_OBJECT(DriveComponentImpl)
public: public:
class ConfigurationForm : public QStandardItem class ConfigurationForm : public QStandardItem, public QObject
{ {
W_OBJECT(ConfigurationForm)
public: public:
ConfigurationForm( ConfigurationForm(
DriveComponentImpl* dci, QIcon icon, const std::string text): DriveComponentImpl* dci, QIcon icon, const std::string text):
@@ -23,12 +28,24 @@ public:
_widget = new QWidget(); _widget = new QWidget();
} }
public:
virtual std::string id() const = 0;
virtual void updateSavedState() const = 0;
W_SLOT(updateSavedState)
public: public:
QWidget* widget() const QWidget* widget() const
{ {
return _widget; return _widget;
} }
protected:
QString qid() const
{
return DRIVE + QString::fromStdString(id());
}
protected: protected:
DriveComponentImpl* _dci; DriveComponentImpl* _dci;
QWidget* _widget; QWidget* _widget;
@@ -44,6 +61,22 @@ public:
dci, QIcon(":/ui/extras/fluxfile.png"), "Flux file") dci, QIcon(":/ui/extras/fluxfile.png"), "Flux file")
{ {
setupUi(_widget); setupUi(_widget);
connect(filenameEdit,
&QLineEdit::editingFinished,
this,
&ConfigurationForm::updateSavedState);
}
public:
std::string id() const override
{
return "flux";
}
void updateSavedState() const override
{
app->setValue(qid() + "/filename", filenameEdit->text());
} }
}; };
@@ -57,6 +90,30 @@ public:
ConfigurationForm(dci, icon, label) ConfigurationForm(dci, icon, label)
{ {
setupUi(_widget); setupUi(_widget);
connect(portLineEdit,
&QLineEdit::editingFinished,
this,
&ConfigurationForm::updateSavedState);
connect(driveComboBox,
QOverload<int>::of(&QComboBox::activated),
this,
&ConfigurationForm::updateSavedState);
connect(driveTypeComboBox,
QOverload<int>::of(&QComboBox::activated),
this,
&ConfigurationForm::updateSavedState);
connect(highDensityToggle,
&QCheckBox::stateChanged,
this,
&ConfigurationForm::updateSavedState);
}
void updateSavedState() const override
{
app->setValue(
qid() + "/highDensity", highDensityToggle->isChecked());
app->setValue(qid() + "/drive", driveComboBox->currentIndex());
} }
}; };
@@ -69,6 +126,18 @@ public:
"Greaseweazle\n(configured manually)") "Greaseweazle\n(configured manually)")
{ {
} }
public:
std::string id() const override
{
return "greaseweazle/manual";
}
void updateSavedState() const override
{
app->setValue(qid() + "/port", portLineEdit->text());
DriveConfigurationForm::updateSavedState();
}
}; };
class DetectedDriveConfigurationForm : public DriveConfigurationForm class DetectedDriveConfigurationForm : public DriveConfigurationForm
@@ -81,24 +150,30 @@ public:
DriveConfigurationForm(dci, DriveConfigurationForm(dci,
QIcon(":/ui/extras/hardware.png"), QIcon(":/ui/extras/hardware.png"),
fmt::format("{}\n{}", type, id)), fmt::format("{}\n{}", type, id)),
_type(type),
_id(id),
_device(device) _device(device)
{ {
portLineEdit->setEnabled(false); portLineEdit->setEnabled(false);
portLineEdit->setText(QString::fromStdString(_device->serialPort)); portLineEdit->setText(QString::fromStdString(_device->serialPort));
} }
public:
std::string id() const override
{
return fmt::format("{}:{}", _type, _id);
}
private: private:
std::shared_ptr<CandidateDevice>& _device; std::shared_ptr<CandidateDevice>& _device;
std::string _type;
std::string _id;
}; };
public: public:
DriveComponentImpl(MainWindow* mainWindow): _mainWindow(mainWindow) DriveComponentImpl(MainWindow* mainWindow): _mainWindow(mainWindow)
{ {
_mainWindow->connect(_mainWindow->deviceSelectionComboBox, setParent(mainWindow);
QOverload<int>::of(&QComboBox::activated),
this,
&DriveComponentImpl::onDeviceIndexChanged);
_devicesModel.setColumnCount(1); _devicesModel.setColumnCount(1);
_mainWindow->deviceSelectionComboBox->setModel(&_devicesModel); _mainWindow->deviceSelectionComboBox->setModel(&_devicesModel);
@@ -110,7 +185,21 @@ public:
addForm(new DetectedDriveConfigurationForm( addForm(new DetectedDriveConfigurationForm(
this, getDeviceName(it->type), it->serial, it)); this, getDeviceName(it->type), it->serial, it));
onDeviceIndexChanged(0); auto currentFormId =
app->value(SELECTED_DRIVE).toString().toStdString();
int currentFormIndex = findFormById(currentFormId, 0);
_mainWindow->deviceSelectionComboBox->setCurrentIndex(currentFormIndex);
changeSelectedDevice(currentFormIndex);
_mainWindow->connect(_mainWindow->deviceSelectionComboBox,
QOverload<int>::of(&QComboBox::activated),
this,
&DriveComponentImpl::changeSelectedDevice);
_mainWindow->connect(_mainWindow->deviceSelectionComboBox,
QOverload<int>::of(&QComboBox::activated),
this,
&DriveComponentImpl::updateSavedState);
container()->updateGeometry(); container()->updateGeometry();
} }
@@ -124,13 +213,30 @@ private:
form->widget()->hide(); form->widget()->hide();
} }
int findFormById(const std::string& id, int def)
{
for (int i = 0; i < _forms.size(); i++)
if (_forms[i]->id() == id)
return i;
return def;
}
public: public:
void onDeviceIndexChanged(int index) void changeSelectedDevice(int index)
{ {
for (int i = 0; i < _forms.size(); i++) for (int i = 0; i < _forms.size(); i++)
_forms[i]->widget()->setVisible(i == index); _forms[i]->widget()->setVisible(i == index);
} }
W_SLOT(onDeviceIndexChanged) W_SLOT(changeSelectedDevice)
void updateSavedState()
{
int selectedForm = _mainWindow->deviceSelectionComboBox->currentIndex();
ConfigurationForm* form = _forms[selectedForm];
app->setValue(SELECTED_DRIVE, QString::fromStdString(form->id()));
}
W_SLOT(updateSavedState)
public: public:
QWidget* container() const QWidget* container() const
@@ -145,8 +251,9 @@ private:
}; };
W_OBJECT_IMPL(DriveComponentImpl) W_OBJECT_IMPL(DriveComponentImpl)
W_OBJECT_IMPL(DriveComponentImpl::ConfigurationForm)
std::unique_ptr<DriveComponent> DriveComponent::create(MainWindow* mainWindow) DriveComponent* DriveComponent::create(MainWindow* mainWindow)
{ {
return std::make_unique<DriveComponentImpl>(mainWindow); return new DriveComponentImpl(mainWindow);
} }

View File

@@ -5,5 +5,5 @@ class MainWindow;
class DriveComponent class DriveComponent
{ {
public: public:
static std::unique_ptr<DriveComponent> create(MainWindow* mainWindow); static DriveComponent* create(MainWindow* mainWindow);
}; };

View File

@@ -30,7 +30,7 @@
<item row="0" column="1"> <item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLineEdit" name="lineEdit"/> <widget class="QLineEdit" name="filenameEdit"/>
</item> </item>
<item> <item>
<widget class="QToolButton" name="toolButton_7"> <widget class="QToolButton" name="toolButton_7">
@@ -57,6 +57,9 @@
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QRadioButton" name="radioButton"> <widget class="QRadioButton" name="radioButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Use value in file</string> <string>Use value in file</string>
</property> </property>
@@ -67,6 +70,9 @@
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QRadioButton" name="radioButton_2"> <widget class="QRadioButton" name="radioButton_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>300 rpm / 200 ms</string> <string>300 rpm / 200 ms</string>
</property> </property>
@@ -77,6 +83,9 @@
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QRadioButton" name="radioButton_3"> <widget class="QRadioButton" name="radioButton_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>360 rpm / 166 ms</string> <string>360 rpm / 166 ms</string>
</property> </property>
@@ -89,6 +98,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QRadioButton" name="radioButton_4"> <widget class="QRadioButton" name="radioButton_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Custom:</string> <string>Custom:</string>
</property> </property>
@@ -105,6 +117,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="suffix">
<string>ms</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@@ -33,6 +33,8 @@ private:
public: public:
FormatComponentImpl(MainWindow* mainWindow): _mainWindow(mainWindow) FormatComponentImpl(MainWindow* mainWindow): _mainWindow(mainWindow)
{ {
setParent(mainWindow);
/* Configure the formats drop-down list. */ /* Configure the formats drop-down list. */
std::string defaultFormat = std::string defaultFormat =
@@ -140,7 +142,8 @@ public:
} }
qb->setCurrentIndex(selectedItem); qb->setCurrentIndex(selectedItem);
layout->addRow(QString::fromStdString(groupName), qb); layout->addWidget(new QLabel(QString::fromStdString(groupName)));
layout->addWidget(qb);
_mainWindow->connect(qb, _mainWindow->connect(qb,
QOverload<int>::of(&QComboBox::activated), QOverload<int>::of(&QComboBox::activated),
@@ -156,7 +159,7 @@ public:
settings.contains(QString::fromStdString(option.name())) settings.contains(QString::fromStdString(option.name()))
? Qt::Checked ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
layout->addRow(nullptr, rb); layout->addWidget(rb);
_mainWindow->connect(rb, _mainWindow->connect(rb,
&QCheckBox::stateChanged, &QCheckBox::stateChanged,
@@ -165,7 +168,7 @@ public:
} }
if (layout->count() == 0) if (layout->count() == 0)
layout->addRow(new QLabel("No options for this format!")); layout->addWidget(new QLabel("No options for this format!"));
} }
W_SLOT(changeSelectedFormat) W_SLOT(changeSelectedFormat)
@@ -190,7 +193,10 @@ public:
if (QComboBox* cb = dynamic_cast<QComboBox*>(w)) if (QComboBox* cb = dynamic_cast<QComboBox*>(w))
settings.append(cb->currentData().toString()); settings.append(cb->currentData().toString());
else if (OptionCheckBox* cb = dynamic_cast<OptionCheckBox*>(w)) else if (OptionCheckBox* cb = dynamic_cast<OptionCheckBox*>(w))
settings.append(QString::fromStdString(cb->option->name())); {
if (cb->isChecked())
settings.append(QString::fromStdString(cb->option->name()));
}
} }
app->setValue(QString(FORMAT_OPTIONS_PREFIX) + "/" + formatId, app->setValue(QString(FORMAT_OPTIONS_PREFIX) + "/" + formatId,
@@ -204,7 +210,7 @@ private:
}; };
W_OBJECT_IMPL(FormatComponentImpl) W_OBJECT_IMPL(FormatComponentImpl)
std::unique_ptr<FormatComponent> FormatComponent::create(MainWindow* mainWindow) FormatComponent* FormatComponent::create(MainWindow* mainWindow)
{ {
return std::make_unique<FormatComponentImpl>(mainWindow); return new FormatComponentImpl(mainWindow);
} }

View File

@@ -5,5 +5,5 @@ class MainWindow;
class FormatComponent class FormatComponent
{ {
public: public:
static std::unique_ptr<FormatComponent> create(MainWindow* mainWindow); static FormatComponent* create(MainWindow* mainWindow);
}; };

View File

@@ -65,6 +65,9 @@ Application::Application(int& argc, char** argv):
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
Q_INIT_RESOURCE(resources); Q_INIT_RESOURCE(resources);
workerThreadPool.setMaxThreadCount(1); workerThreadPool.setMaxThreadCount(1);

View File

@@ -34,8 +34,8 @@ public:
} }
private: private:
std::unique_ptr<DriveComponent> _driveComponent; DriveComponent* _driveComponent;
std::unique_ptr<FormatComponent> _formatComponent; FormatComponent* _formatComponent;
}; };
std::unique_ptr<MainWindow> MainWindow::create() std::unique_ptr<MainWindow> MainWindow::create()

View File

@@ -14,7 +14,7 @@
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="resources.qrc"> <iconset>
<normaloff>:/ui/extras/icon.png</normaloff>:/ui/extras/icon.png</iconset> <normaloff>:/ui/extras/icon.png</normaloff>:/ui/extras/icon.png</iconset>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
@@ -112,7 +112,7 @@
<string/> <string/>
</property> </property>
<property name="pixmap"> <property name="pixmap">
<pixmap resource="resources.qrc">:/ui/extras/icon.png</pixmap> <pixmap>:/ui/extras/icon.png</pixmap>
</property> </property>
<property name="scaledContents"> <property name="scaledContents">
<bool>false</bool> <bool>false</bool>
@@ -697,7 +697,7 @@ background: white;
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_10"> <layout class="QVBoxLayout" name="verticalLayout_10">
<item> <item>
<layout class="QFormLayout" name="formatOptionsContainerLayout"/> <layout class="QVBoxLayout" name="formatOptionsContainerLayout"/>
</item> </item>
</layout> </layout>
</widget> </widget>