Telemetry refactoring - Fixes #1634
This commit is contained in:
Executable
+22
@@ -0,0 +1,22 @@
|
||||
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
set(shared_SRCS
|
||||
foldersync.cpp
|
||||
genericpanel.cpp
|
||||
hexspinbox.cpp
|
||||
verticalscrollarea.cpp
|
||||
)
|
||||
|
||||
set(shared_HDRS
|
||||
autocheckbox.h
|
||||
autocombobox.h
|
||||
autodoublespinbox.h
|
||||
autohexspinbox.h
|
||||
genericpanel.h
|
||||
hexspinbox.h
|
||||
verticalscrollarea.h
|
||||
)
|
||||
|
||||
qt4_wrap_cpp(shared_SRCS ${shared_HDRS})
|
||||
|
||||
add_library(shared ${shared_SRCS})
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#ifndef AUTOCHECKBOX_H_
|
||||
#define AUTOCHECKBOX_H_
|
||||
|
||||
#include <QCheckBox>
|
||||
#include "modeledit/modeledit.h"
|
||||
|
||||
class AutoCheckBox: public QCheckBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AutoCheckBox(QWidget *parent = 0):
|
||||
QCheckBox(parent),
|
||||
field(NULL),
|
||||
panel(NULL),
|
||||
lock(false)
|
||||
{
|
||||
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
|
||||
}
|
||||
|
||||
void setField(bool & field, ModelPanel * panel=NULL)
|
||||
{
|
||||
this->field = &field;
|
||||
this->panel = panel;
|
||||
updateValue();
|
||||
}
|
||||
|
||||
void updateValue()
|
||||
{
|
||||
lock = true;
|
||||
if (field) {
|
||||
setChecked((int)*field);
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void onToggled(bool checked)
|
||||
{
|
||||
if (field && !lock) {
|
||||
*field = checked;
|
||||
if (panel) {
|
||||
emit panel->modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool * field;
|
||||
ModelPanel * panel;
|
||||
bool lock;
|
||||
};
|
||||
|
||||
#endif /* AUTOCHECKBOX_H_ */
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#ifndef AUTOCOMBOBOX_H_
|
||||
#define AUTOCOMBOBOX_H_
|
||||
|
||||
#include <QComboBox>
|
||||
#include "modeledit/modeledit.h"
|
||||
|
||||
class AutoComboBox: public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AutoComboBox(QWidget *parent = 0):
|
||||
QComboBox(parent),
|
||||
field(NULL),
|
||||
panel(NULL),
|
||||
lock(false)
|
||||
{
|
||||
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
lock = true;
|
||||
QComboBox::clear();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void addItem(const QString & item, unsigned int value)
|
||||
{
|
||||
lock = true;
|
||||
QComboBox::addItem(item, value);
|
||||
if (field && *field==value) {
|
||||
setCurrentIndex(count()-1);
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void setField(unsigned int & field, ModelPanel * panel=NULL)
|
||||
{
|
||||
this->field = &field;
|
||||
this->panel = panel;
|
||||
for (int i=0; i<count(); ++i) {
|
||||
setItemData(i, i);
|
||||
if ((int)field == i)
|
||||
setCurrentIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void onCurrentIndexChanged(int index)
|
||||
{
|
||||
if (field && !lock) {
|
||||
*field = itemData(index).toInt();
|
||||
if (panel) {
|
||||
emit panel->modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
unsigned int * field;
|
||||
ModelPanel * panel;
|
||||
bool lock;
|
||||
};
|
||||
|
||||
#endif /* AUTOCOMBOBOX_H_ */
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#ifndef AUTODOUBLESPINBOX_H_
|
||||
#define AUTODOUBLESPINBOX_H_
|
||||
|
||||
#include <QDoubleSpinBox>
|
||||
#include "modeledit/modeledit.h"
|
||||
|
||||
class AutoDoubleSpinBox: public QDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AutoDoubleSpinBox(QWidget *parent = 0):
|
||||
QDoubleSpinBox(parent),
|
||||
field(NULL),
|
||||
panel(NULL),
|
||||
lock(false)
|
||||
{
|
||||
connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double)));
|
||||
}
|
||||
|
||||
void setField(int & field, ModelPanel * panel=NULL)
|
||||
{
|
||||
this->field = &field;
|
||||
this->panel = panel;
|
||||
updateValue();
|
||||
}
|
||||
|
||||
void setField(unsigned int & field, ModelPanel * panel=NULL)
|
||||
{
|
||||
this->field = (int *)&field;
|
||||
this->panel = panel;
|
||||
updateValue();
|
||||
}
|
||||
|
||||
void updateValue()
|
||||
{
|
||||
if (field) {
|
||||
setValue(float(*field)/multiplier());
|
||||
}
|
||||
}
|
||||
|
||||
void setDecimals(int prec)
|
||||
{
|
||||
QDoubleSpinBox::setDecimals(prec);
|
||||
updateValue();
|
||||
}
|
||||
|
||||
protected:
|
||||
int multiplier()
|
||||
{
|
||||
switch (decimals()) {
|
||||
case 1:
|
||||
return 10;
|
||||
case 2:
|
||||
return 100;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void onValueChanged(double value)
|
||||
{
|
||||
if (field && !lock) {
|
||||
*field = value * multiplier();
|
||||
if (panel) {
|
||||
emit panel->modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
int * field;
|
||||
ModelPanel * panel;
|
||||
bool lock;
|
||||
};
|
||||
|
||||
#endif /* AUTODOUBLESPINBOX_H_ */
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#ifndef AUTOHEXSPINBOX_H_
|
||||
#define AUTOHEXSPINBOX_H_
|
||||
|
||||
#include "hexspinbox.h"
|
||||
#include "modeledit/modeledit.h"
|
||||
|
||||
class AutoHexSpinBox: public HexSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AutoHexSpinBox(QWidget *parent = 0):
|
||||
HexSpinBox(parent),
|
||||
field(NULL),
|
||||
panel(NULL),
|
||||
lock(false)
|
||||
{
|
||||
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
|
||||
}
|
||||
|
||||
void setField(unsigned int & field, ModelPanel * panel=NULL)
|
||||
{
|
||||
this->field = &field;
|
||||
this->panel = panel;
|
||||
updateValue();
|
||||
}
|
||||
|
||||
void updateValue()
|
||||
{
|
||||
if (field) {
|
||||
setValue(*field);
|
||||
}
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void onValueChanged(int value)
|
||||
{
|
||||
if (field && !lock) {
|
||||
*field = value;
|
||||
if (panel) {
|
||||
emit panel->modified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
unsigned int * field;
|
||||
ModelPanel * panel;
|
||||
bool lock;
|
||||
};
|
||||
|
||||
#endif /* AUTOHEXSPINBOX_H_ */
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#include "foldersync.h"
|
||||
#include <QDirIterator>
|
||||
#include <QDateTime>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
|
||||
FoldersSyncTask::FoldersSyncTask(const QString &folder1, const QString &folder2)
|
||||
{
|
||||
folders[0] = folder1;
|
||||
folders[1] = folder2;
|
||||
}
|
||||
|
||||
void FoldersSyncTask::run()
|
||||
{
|
||||
QStringList errors = updateDir(folders[0], folders[1]) + updateDir(folders[1], folders[0]);
|
||||
if (errors.count() > 0) {
|
||||
QMessageBox::warning(NULL, QObject::tr("Copy errors"), errors.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
QStringList FoldersSyncTask::updateDir(const QDir &source, const QDir &destination)
|
||||
{
|
||||
QStringList errors;
|
||||
QDirIterator it(source, QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString path = it.next();
|
||||
QFileInfo sourceInfo(path);
|
||||
QString relativePath = source.relativeFilePath(path);
|
||||
QString destinationPath = destination.absoluteFilePath(relativePath);
|
||||
QFileInfo destinationInfo(destinationPath);
|
||||
if (sourceInfo.isDir()) {
|
||||
if (!destinationInfo.exists()) {
|
||||
if (!destination.mkdir(relativePath)) {
|
||||
errors << QObject::tr("Create '%1' failed").arg(destinationPath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!destinationInfo.exists()) {
|
||||
// qDebug() << "Copy" << path << "to" << destinationPath;
|
||||
if (!QFile::copy(path, destinationPath)) {
|
||||
errors << QObject::tr("Copy '%1' to '%2' failed").arg(path).arg(destinationPath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (sourceInfo.lastModified() > destinationInfo.lastModified()) {
|
||||
// retrieve source contents
|
||||
QFile sourceFile(path);
|
||||
if (!sourceFile.open(QFile::ReadOnly)) {
|
||||
errors << QObject::tr("Open '%1' failed").arg(path);
|
||||
continue;
|
||||
}
|
||||
QString sourceContents = sourceFile.readAll();
|
||||
sourceFile.close();
|
||||
// try to retrieve destination contents
|
||||
QFile destinationFile(path);
|
||||
if (destinationFile.open(QFile::ReadOnly)) {
|
||||
QString destinationContents = destinationFile.readAll();
|
||||
destinationFile.close();
|
||||
if (sourceContents == destinationContents) {
|
||||
// qDebug() << "Skip" << path;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!destinationFile.open(QFile::WriteOnly)) {
|
||||
errors << QObject::tr("Write '%1' failed").arg(destinationPath);
|
||||
continue;
|
||||
}
|
||||
// qDebug() << "Write" << destinationPath;
|
||||
QTextStream destinationStream(&destinationFile);
|
||||
destinationStream << sourceContents;
|
||||
destinationFile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#ifndef FOLDERSYNC_H_
|
||||
#define FOLDERSYNC_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class QDir;
|
||||
|
||||
class FoldersSyncTask
|
||||
{
|
||||
public:
|
||||
FoldersSyncTask(const QString &folder1, const QString &folder2);
|
||||
void run();
|
||||
|
||||
protected:
|
||||
QStringList updateDir(const QDir &source, const QDir &destination);
|
||||
QString folders[2];
|
||||
};
|
||||
|
||||
#endif /* FOLDERSYNC_H_ */
|
||||
Executable
+104
@@ -0,0 +1,104 @@
|
||||
#include "genericpanel.h"
|
||||
#include <QComboBox>
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
#include <QSpacerItem>
|
||||
|
||||
GenericPanel::GenericPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
|
||||
QWidget(parent),
|
||||
model(model),
|
||||
generalSettings(generalSettings),
|
||||
firmware(firmware),
|
||||
lock(false)
|
||||
{
|
||||
}
|
||||
|
||||
GenericPanel::~GenericPanel()
|
||||
{
|
||||
}
|
||||
|
||||
void GenericPanel::update()
|
||||
{
|
||||
}
|
||||
|
||||
void GenericPanel::addLabel(QGridLayout *gridLayout, const QString &text, int col, bool minimize)
|
||||
{
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setFrameShape(QFrame::Panel);
|
||||
label->setFrameShadow(QFrame::Raised);
|
||||
label->setMidLineWidth(0);
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
label->setMargin(5);
|
||||
label->setText(text);
|
||||
if (!minimize)
|
||||
label->setMinimumWidth(100);
|
||||
gridLayout->addWidget(label, 0, col, 1, 1);
|
||||
}
|
||||
|
||||
void GenericPanel::addEmptyLabel(QGridLayout * gridLayout, int col)
|
||||
{
|
||||
QLabel *label = new QLabel(this);
|
||||
label->setText("");
|
||||
gridLayout->addWidget(label, 0, col, 1, 1);
|
||||
}
|
||||
|
||||
void GenericPanel::addHSpring(QGridLayout * gridLayout, int col, int row)
|
||||
{
|
||||
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
|
||||
gridLayout->addItem(spacer, row, col);
|
||||
}
|
||||
|
||||
void GenericPanel::addVSpring(QGridLayout * gridLayout, int col, int row)
|
||||
{
|
||||
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
|
||||
gridLayout->addItem(spacer, row, col);
|
||||
}
|
||||
|
||||
void GenericPanel::addDoubleSpring(QGridLayout * gridLayout, int col, int row)
|
||||
{
|
||||
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding );
|
||||
gridLayout->addItem(spacer, row, col);
|
||||
}
|
||||
|
||||
bool GenericPanel::eventFilter(QObject *object, QEvent * event)
|
||||
{
|
||||
QWidget * widget = qobject_cast<QWidget*>(object);
|
||||
if (widget) {
|
||||
if (event->type() == QEvent::Wheel) {
|
||||
if (widget->focusPolicy() == Qt::WheelFocus) {
|
||||
event->accept();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
event->ignore();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (event->type() == QEvent::FocusIn) {
|
||||
widget->setFocusPolicy(Qt::WheelFocus);
|
||||
}
|
||||
else if (event->type() == QEvent::FocusOut) {
|
||||
widget->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
}
|
||||
return QWidget::eventFilter(object, event);
|
||||
}
|
||||
|
||||
void GenericPanel::disableMouseScrolling()
|
||||
{
|
||||
Q_FOREACH(QComboBox * cb, findChildren<QComboBox*>()) {
|
||||
cb->installEventFilter(this);
|
||||
cb->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
Q_FOREACH(QAbstractSpinBox * sb, findChildren<QAbstractSpinBox*>()) {
|
||||
sb->installEventFilter(this);
|
||||
sb->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
Q_FOREACH(QSlider * slider, findChildren<QSlider*>()) {
|
||||
slider->installEventFilter(this);
|
||||
slider->setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
}
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#ifndef GENERICPANEL_H_
|
||||
#define GENERICPANEL_H_
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class ModelData;
|
||||
class GeneralSettings;
|
||||
class FirmwareInterface;
|
||||
class QGridLayout;
|
||||
class QString;
|
||||
|
||||
class GenericPanel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class AutoComboBox;
|
||||
friend class AutoDoubleSpinBox;
|
||||
friend class AutoCheckBox;
|
||||
friend class AutoHexSpinBox;
|
||||
|
||||
public:
|
||||
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware);
|
||||
virtual ~GenericPanel();
|
||||
|
||||
signals:
|
||||
void modified();
|
||||
|
||||
public slots:
|
||||
virtual void update();
|
||||
|
||||
protected:
|
||||
ModelData * model;
|
||||
GeneralSettings & generalSettings;
|
||||
FirmwareInterface * firmware;
|
||||
bool lock;
|
||||
void addLabel(QGridLayout * gridLayout, const QString &text, int col, bool mimimize=false);
|
||||
void addEmptyLabel(QGridLayout * gridLayout, int col);
|
||||
void addHSpring(QGridLayout *, int col, int row);
|
||||
void addVSpring(QGridLayout *, int col, int row);
|
||||
void addDoubleSpring(QGridLayout *, int col, int row);
|
||||
virtual bool eventFilter(QObject *obj, QEvent *event);
|
||||
void disableMouseScrolling();
|
||||
};
|
||||
|
||||
#endif
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#include "hexspinbox.h"
|
||||
|
||||
HexSpinBox::HexSpinBox(QWidget *parent):
|
||||
QSpinBox(parent)
|
||||
{
|
||||
validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"), this);
|
||||
}
|
||||
|
||||
QValidator::State HexSpinBox::validate(QString &text, int &pos) const
|
||||
{
|
||||
return validator->validate(text, pos);
|
||||
}
|
||||
|
||||
int HexSpinBox::valueFromText(const QString &text) const
|
||||
{
|
||||
return text.toInt(0, 16);
|
||||
}
|
||||
|
||||
QString HexSpinBox::textFromValue(int value) const
|
||||
{
|
||||
QString text;
|
||||
text.sprintf("%04X", value);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#ifndef HEXSPINBOX_H_
|
||||
#define HEXSPINBOX_H_
|
||||
|
||||
#include <QSpinBox>
|
||||
|
||||
class QRegExpValidator;
|
||||
|
||||
class HexSpinBox : public QSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HexSpinBox(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
QValidator::State validate(QString &text, int &pos) const;
|
||||
int valueFromText(const QString &text) const;
|
||||
QString textFromValue(int value) const;
|
||||
|
||||
private:
|
||||
QRegExpValidator *validator;
|
||||
};
|
||||
|
||||
#endif /* HEXSPINBOX_H_ */
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#include "verticalscrollarea.h"
|
||||
#include "genericpanel.h"
|
||||
#include <QEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
VerticalScrollArea::VerticalScrollArea(QWidget * parent, GenericPanel * panel):
|
||||
QScrollArea(parent),
|
||||
panel(panel),
|
||||
parent(parent)
|
||||
{
|
||||
setWidgetResizable(true);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setWidget(panel);
|
||||
panel->installEventFilter(this);
|
||||
}
|
||||
|
||||
bool VerticalScrollArea::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if (o == panel && e->type() == QEvent::Resize) {
|
||||
setMinimumWidth(panel->minimumSizeHint().width() + verticalScrollBar()->width());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#ifndef VERTICALSCROLLAREA_H_
|
||||
#define VERTICALSCROLLAREA_H_
|
||||
|
||||
#include <QScrollArea>
|
||||
|
||||
class GenericPanel;
|
||||
|
||||
class VerticalScrollArea : public QScrollArea
|
||||
{
|
||||
public:
|
||||
VerticalScrollArea(QWidget * parent, GenericPanel * panel);
|
||||
|
||||
protected:
|
||||
virtual bool eventFilter(QObject *o, QEvent *e);
|
||||
|
||||
private:
|
||||
GenericPanel * panel;
|
||||
QWidget * parent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user