Merge remote-tracking branch elecpower/cpn-auto-widget into elecpower/cpn-refactor-gen-settings
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
set(shared_NAMES
|
||||||
|
autocheckbox
|
||||||
|
)
|
||||||
set(shared_SRCS
|
set(shared_SRCS
|
||||||
genericpanel.cpp
|
genericpanel.cpp
|
||||||
hexspinbox.cpp
|
hexspinbox.cpp
|
||||||
@@ -8,7 +11,6 @@ set(shared_SRCS
|
|||||||
|
|
||||||
set(shared_HDRS
|
set(shared_HDRS
|
||||||
autobitsetcheckbox.h
|
autobitsetcheckbox.h
|
||||||
autocheckbox.h
|
|
||||||
autocombobox.h
|
autocombobox.h
|
||||||
autodoublespinbox.h
|
autodoublespinbox.h
|
||||||
autohexspinbox.h
|
autohexspinbox.h
|
||||||
@@ -21,7 +23,18 @@ set(shared_HDRS
|
|||||||
autoslider.h
|
autoslider.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
foreach(name ${shared_NAMES})
|
||||||
|
set(shared_SRCS ${shared_SRCS} ${name}.cpp)
|
||||||
|
set(shared_HDRS ${shared_HDRS} ${name}.h)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
qt5_wrap_cpp(shared_SRCS ${shared_HDRS})
|
qt5_wrap_cpp(shared_SRCS ${shared_HDRS})
|
||||||
|
|
||||||
|
# add after moc generation to stop warnings
|
||||||
|
set(shared_SRCS ${shared_SRCS}
|
||||||
|
autowidget.h
|
||||||
|
autowidget.cpp
|
||||||
|
)
|
||||||
|
|
||||||
add_library(shared ${shared_SRCS})
|
add_library(shared ${shared_SRCS})
|
||||||
target_link_libraries(shared PRIVATE Qt5::Widgets ${CPN_COMMON_LIB})
|
target_link_libraries(shared PRIVATE Qt5::Widgets ${CPN_COMMON_LIB})
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "autocheckbox.h"
|
||||||
|
|
||||||
|
AutoCheckBox::AutoCheckBox(QWidget * parent):
|
||||||
|
QCheckBox(parent),
|
||||||
|
AutoWidget(),
|
||||||
|
m_field(nullptr),
|
||||||
|
m_invert(false)
|
||||||
|
{
|
||||||
|
connect(this, &QCheckBox::toggled, this, &AutoCheckBox::onToggled);
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoCheckBox::~AutoCheckBox()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoCheckBox::setField(bool & field, GenericPanel * panel, bool invert)
|
||||||
|
{
|
||||||
|
m_field = &field;
|
||||||
|
m_invert = invert;
|
||||||
|
setPanel(panel);
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoCheckBox::setInvert(bool invert)
|
||||||
|
{
|
||||||
|
m_invert = invert;
|
||||||
|
updateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoCheckBox::onToggled(bool checked)
|
||||||
|
{
|
||||||
|
if (!lock() && m_field) {
|
||||||
|
const bool val = m_invert ? !checked : checked;
|
||||||
|
*m_field = val;
|
||||||
|
emit currentDataChanged(val);
|
||||||
|
dataChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoCheckBox::updateValue()
|
||||||
|
{
|
||||||
|
if (m_field) {
|
||||||
|
setLock(true);
|
||||||
|
setChecked(m_invert ? !(*m_field) : *m_field);
|
||||||
|
setLock(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,72 +20,30 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include "autowidget.h"
|
||||||
#include "genericpanel.h"
|
|
||||||
|
|
||||||
class AutoCheckBox: public QCheckBox
|
#include <QCheckBox>
|
||||||
|
|
||||||
|
class AutoCheckBox : public QCheckBox, AutoWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AutoCheckBox(QWidget * parent = nullptr):
|
explicit AutoCheckBox(QWidget * parent = nullptr);
|
||||||
QCheckBox(parent),
|
~AutoCheckBox();
|
||||||
field(nullptr),
|
|
||||||
panel(nullptr),
|
|
||||||
lock(false),
|
|
||||||
invert(false)
|
|
||||||
{
|
|
||||||
connect(this, &AutoCheckBox::toggled, this, &AutoCheckBox::onToggled);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setField(bool & field, GenericPanel * panel = nullptr, bool invert = false)
|
virtual void updateValue() override;
|
||||||
{
|
|
||||||
this->field = &field;
|
|
||||||
this->panel = panel;
|
|
||||||
this->invert = invert;
|
|
||||||
updateValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setEnabled(bool enabled)
|
void setField(bool & field, GenericPanel * panel = nullptr, bool invert = false);
|
||||||
{
|
void setInvert(bool invert);
|
||||||
QCheckBox::setEnabled(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setInvert(bool invert)
|
|
||||||
{
|
|
||||||
this->invert = invert;
|
|
||||||
updateValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateValue()
|
|
||||||
{
|
|
||||||
if (field) {
|
|
||||||
lock = true;
|
|
||||||
setChecked(invert ? !(*field) : *field);
|
|
||||||
lock = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentDataChanged(bool value);
|
void currentDataChanged(bool value);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onToggled(bool checked)
|
void onToggled(bool checked);
|
||||||
{
|
|
||||||
if (panel && panel->lock)
|
|
||||||
return;
|
|
||||||
if (field && !lock) {
|
|
||||||
const bool val = invert ? !checked : checked;
|
|
||||||
*field = val;
|
|
||||||
emit currentDataChanged(val);
|
|
||||||
if (panel)
|
|
||||||
emit panel->modified();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
bool *field = nullptr;
|
bool *m_field;
|
||||||
GenericPanel *panel = nullptr;
|
bool m_invert;
|
||||||
bool lock = false;
|
|
||||||
bool invert = false;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "autowidget.h"
|
||||||
|
#include "genericpanel.h"
|
||||||
|
|
||||||
|
AutoWidget::AutoWidget():
|
||||||
|
m_panel(nullptr),
|
||||||
|
m_lock(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoWidget::~AutoWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AutoWidget::lock()
|
||||||
|
{
|
||||||
|
return panelLock() | m_lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoWidget::setLock(bool lock)
|
||||||
|
{
|
||||||
|
m_lock = lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoWidget::setPanel(GenericPanel * panel)
|
||||||
|
{
|
||||||
|
m_panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoWidget::dataChanged()
|
||||||
|
{
|
||||||
|
if (m_panel)
|
||||||
|
emit m_panel->modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AutoWidget::panelLock()
|
||||||
|
{
|
||||||
|
if (m_panel)
|
||||||
|
return m_panel->lock;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class GenericPanel;
|
||||||
|
|
||||||
|
// Note: cannot be a Qt object as it will create a compiler ambiguity in the inheriting class
|
||||||
|
class AutoWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit AutoWidget();
|
||||||
|
~AutoWidget();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void updateValue() = 0;
|
||||||
|
|
||||||
|
bool lock();
|
||||||
|
void setLock(bool lock);
|
||||||
|
void setPanel(GenericPanel * panel);
|
||||||
|
|
||||||
|
void dataChanged();
|
||||||
|
bool panelLock();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GenericPanel *m_panel;
|
||||||
|
bool m_lock;
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "autobitsetcheckbox.h"
|
||||||
|
#include "autocheckbox.h"
|
||||||
|
#include "autocombobox.h"
|
||||||
|
#include "autodoublespinbox.h"
|
||||||
|
#include "autohexspinbox.h"
|
||||||
|
#include "autolineedit.h"
|
||||||
|
#include "autoprecisioncombobox.h"
|
||||||
|
#include "autoslider.h"
|
||||||
|
#include "autospinbox.h"
|
||||||
|
#include "autotimeedit.h"
|
||||||
@@ -34,7 +34,6 @@ class GenericPanel : public QWidget
|
|||||||
|
|
||||||
friend class AutoComboBox;
|
friend class AutoComboBox;
|
||||||
friend class AutoDoubleSpinBox;
|
friend class AutoDoubleSpinBox;
|
||||||
friend class AutoCheckBox;
|
|
||||||
friend class AutoHexSpinBox;
|
friend class AutoHexSpinBox;
|
||||||
friend class AutoLineEdit;
|
friend class AutoLineEdit;
|
||||||
friend class GVarGroup;
|
friend class GVarGroup;
|
||||||
@@ -43,6 +42,8 @@ class GenericPanel : public QWidget
|
|||||||
friend class AutoTimeEdit;
|
friend class AutoTimeEdit;
|
||||||
friend class AutoSpinBox;
|
friend class AutoSpinBox;
|
||||||
friend class AutoSlider;
|
friend class AutoSlider;
|
||||||
|
// this should be the only auto friend required excl GVArGroup
|
||||||
|
friend class AutoWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware);
|
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||||
|
|||||||
Reference in New Issue
Block a user