Refactor autoxxxxx to use autowidget

This commit is contained in:
elecpower
2021-05-10 07:04:18 +10:00
parent ec52ef10c5
commit 10e7a4fc47
26 changed files with 1258 additions and 980 deletions
+12 -64
View File
@@ -20,83 +20,31 @@
#pragma once
#include "autowidget.h"
#include <QLineEdit>
#include <QRegExpValidator>
#include "genericpanel.h"
class AutoLineEdit: public QLineEdit
class AutoLineEdit: public QLineEdit, AutoWidget
{
Q_OBJECT
public:
explicit AutoLineEdit(QWidget * parent = nullptr, bool updateOnChange = false):
QLineEdit(parent),
field(NULL),
strField(nullptr),
panel(nullptr),
lock(false)
{
if (updateOnChange)
connect(this, &AutoLineEdit::textChanged, this, &AutoLineEdit::onEdited);
else
connect(this, &AutoLineEdit::editingFinished, this, &AutoLineEdit::onEdited);
}
explicit AutoLineEdit(QWidget * parent = nullptr, bool updateOnChange = false);
virtual ~AutoLineEdit();
void setField(char * field, int len, GenericPanel * panel = nullptr)
{
this->field = field;
this->panel = panel;
setValidator(new QRegExpValidator(QRegExp("[ A-Za-z0-9_.-,]*"), this));
setMaxLength(len);
updateValue();
}
virtual void updateValue() override;
void setField(QString & field, int len = 0, GenericPanel * panel = nullptr)
{
strField = &field;
this->panel = panel;
if (len)
setMaxLength(len);
updateValue();
}
void updateValue()
{
lock = true;
if (field)
setText(field);
else if (strField)
setText(*strField);
lock = false;
}
void setField(char * field, int len, GenericPanel * panel = nullptr);
void setField(QString & field, int len = 0, GenericPanel * panel = nullptr);
signals:
void currentDataChanged();
protected slots:
void onEdited()
{
if (panel && panel->lock)
return;
if (lock)
return;
void onEdited();
if (field)
strcpy(field, text().toLatin1());
else if (strField)
*strField = text();
else
return;
emit currentDataChanged();
if (panel)
emit panel->modified();
}
protected:
char * field;
QString * strField = nullptr;
GenericPanel * panel = nullptr;
bool lock = false;
private:
char *m_charField;
QString *m_strField;
};