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

View File

@@ -7,13 +7,18 @@
#include "fluxConfigurationForm.h"
#include <QStandardItemModel>
static const char* DRIVE = "drive/";
static const char* SELECTED_DRIVE = "drive/drive";
class DriveComponentImpl : public DriveComponent, public QObject
{
W_OBJECT(DriveComponentImpl)
public:
class ConfigurationForm : public QStandardItem
class ConfigurationForm : public QStandardItem, public QObject
{
W_OBJECT(ConfigurationForm)
public:
ConfigurationForm(
DriveComponentImpl* dci, QIcon icon, const std::string text):
@@ -23,12 +28,24 @@ public:
_widget = new QWidget();
}
public:
virtual std::string id() const = 0;
virtual void updateSavedState() const = 0;
W_SLOT(updateSavedState)
public:
QWidget* widget() const
{
return _widget;
}
protected:
QString qid() const
{
return DRIVE + QString::fromStdString(id());
}
protected:
DriveComponentImpl* _dci;
QWidget* _widget;
@@ -44,6 +61,22 @@ public:
dci, QIcon(":/ui/extras/fluxfile.png"), "Flux file")
{
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)
{
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)")
{
}
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
@@ -81,24 +150,30 @@ public:
DriveConfigurationForm(dci,
QIcon(":/ui/extras/hardware.png"),
fmt::format("{}\n{}", type, id)),
_type(type),
_id(id),
_device(device)
{
portLineEdit->setEnabled(false);
portLineEdit->setText(QString::fromStdString(_device->serialPort));
}
public:
std::string id() const override
{
return fmt::format("{}:{}", _type, _id);
}
private:
std::shared_ptr<CandidateDevice>& _device;
std::string _type;
std::string _id;
};
public:
DriveComponentImpl(MainWindow* mainWindow): _mainWindow(mainWindow)
{
_mainWindow->connect(_mainWindow->deviceSelectionComboBox,
QOverload<int>::of(&QComboBox::activated),
this,
&DriveComponentImpl::onDeviceIndexChanged);
setParent(mainWindow);
_devicesModel.setColumnCount(1);
_mainWindow->deviceSelectionComboBox->setModel(&_devicesModel);
@@ -110,7 +185,21 @@ public:
addForm(new DetectedDriveConfigurationForm(
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();
}
@@ -124,13 +213,30 @@ private:
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:
void onDeviceIndexChanged(int index)
void changeSelectedDevice(int index)
{
for (int i = 0; i < _forms.size(); i++)
_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:
QWidget* container() const
@@ -145,8 +251,9 @@ private:
};
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
{
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">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="filenameEdit"/>
</item>
<item>
<widget class="QToolButton" name="toolButton_7">
@@ -57,6 +57,9 @@
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="radioButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Use value in file</string>
</property>
@@ -67,6 +70,9 @@
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="radioButton_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>300 rpm / 200 ms</string>
</property>
@@ -77,6 +83,9 @@
</item>
<item row="3" column="1">
<widget class="QRadioButton" name="radioButton_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>360 rpm / 166 ms</string>
</property>
@@ -89,6 +98,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QRadioButton" name="radioButton_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Custom:</string>
</property>
@@ -105,6 +117,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>ms</string>
</property>
</widget>
</item>
</layout>

View File

@@ -33,6 +33,8 @@ private:
public:
FormatComponentImpl(MainWindow* mainWindow): _mainWindow(mainWindow)
{
setParent(mainWindow);
/* Configure the formats drop-down list. */
std::string defaultFormat =
@@ -140,7 +142,8 @@ public:
}
qb->setCurrentIndex(selectedItem);
layout->addRow(QString::fromStdString(groupName), qb);
layout->addWidget(new QLabel(QString::fromStdString(groupName)));
layout->addWidget(qb);
_mainWindow->connect(qb,
QOverload<int>::of(&QComboBox::activated),
@@ -156,7 +159,7 @@ public:
settings.contains(QString::fromStdString(option.name()))
? Qt::Checked
: Qt::Unchecked);
layout->addRow(nullptr, rb);
layout->addWidget(rb);
_mainWindow->connect(rb,
&QCheckBox::stateChanged,
@@ -165,7 +168,7 @@ public:
}
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)
@@ -190,7 +193,10 @@ public:
if (QComboBox* cb = dynamic_cast<QComboBox*>(w))
settings.append(cb->currentData().toString());
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,
@@ -204,7 +210,7 @@ private:
};
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
{
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)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
Q_INIT_RESOURCE(resources);
workerThreadPool.setMaxThreadCount(1);

View File

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

View File

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