Files
edgetx-gx12/companion/src/shared/autobitsetcheckbox.cpp
T
Neil HorneandGitHub a9812688b0 Companion 2.5 (#555)
* Introduce yaml in Companion

* EdgeTX Companion
Replace some OpenTX refs
Data conversion to v220
Update Timers ui to cater for mode field split

* Fix some simulators crashing when started from Companion

* Disable firmware and app update checking and downloads from companion

* Some more rebranding

* Disable manual download actions and another rebrand

* Fix cmake warning

* Fix mode ON conversion gtests and enable switch in model edit

* Stop update message when updates turned off

* OpenTX #8580 Fixes missing negative sign for telemetry sources

* OpenTX #8604 fix curves tooltip colors

* OpenTX #8616 Fix release notes url references

* OpenTX #8548 Align file sync folder references

* OpenTX #8548 Link field once

* OpenTX #8550 Confirmation prompt before write models and settings to radio

* OpenTX #8550 Translate strings

* Title and splash images

* Change DEB package maintainer

* Start NV14

* NV14 continued

* NV14 sim

* Timer countdownStart data conversion and ui fixes

* Fix screen width

* Merge OpenTX PR 8675

* NV14 sim add computer keys and mouse to activate some functions

* Only allow supported protocols for each module on conversion

* Clear mismatched modules on conversion

* Replace colorlcd theme and layout blobs with detailed data structs in companion

* NV14 has 2 topbar zones

* Fix layout init

* Fix layout init again

* Reset to eepromimportexport.h to main branch

* Import/export does not like enum fields

* Model edit add custom screens tab for color and bw telemetry

* Free memory
2021-09-08 10:56:39 +10:00

162 lines
3.8 KiB
C++

/*
* 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 "autobitsetcheckbox.h"
AutoBitsetCheckBox::AutoBitsetCheckBox(QWidget * parent) :
AutoBitsetCheckBox(QString(), parent)
{
}
AutoBitsetCheckBox::AutoBitsetCheckBox(const QString & text, QWidget * parent) :
QCheckBox(text, parent),
AutoWidget()
{
init();
}
// int field constructors
AutoBitsetCheckBox::AutoBitsetCheckBox(int & field, int bitmask, const QString & text, QWidget * parent) :
AutoBitsetCheckBox(field, bitmask, false, text, parent)
{
}
AutoBitsetCheckBox::AutoBitsetCheckBox(int & field, int bitmask, bool invert, const QString & text, QWidget * parent) :
QCheckBox(text, parent),
AutoWidget()
{
setField(field, bitmask, invert);
init();
}
AutoBitsetCheckBox::AutoBitsetCheckBox(int & field, int bitmask, int toggleMask, const QString & text, QWidget * parent) :
QCheckBox(text, parent),
AutoWidget()
{
setField(field, bitmask, false, toggleMask);
init();
}
// unsigned field constructors
AutoBitsetCheckBox::AutoBitsetCheckBox(unsigned & field, int bitmask, const QString & text, QWidget * parent) :
AutoBitsetCheckBox(field, bitmask, false, text, parent)
{
}
AutoBitsetCheckBox::AutoBitsetCheckBox(unsigned & field, int bitmask, bool invert, const QString & text, QWidget * parent) :
QCheckBox(text, parent),
AutoWidget()
{
setField(field, bitmask, invert);
init();
}
AutoBitsetCheckBox::AutoBitsetCheckBox(unsigned & field, int bitmask, int toggleMask, const QString & text, QWidget * parent) :
QCheckBox(text, parent),
AutoWidget()
{
setField(field, bitmask, false, toggleMask);
init();
}
AutoBitsetCheckBox::~AutoBitsetCheckBox()
{
}
void AutoBitsetCheckBox::setField(int & field, int bitmask, bool invert, int toggleMask)
{
m_field = &field;
initField(bitmask, invert, toggleMask);
}
void AutoBitsetCheckBox::setField(unsigned & field, int bitmask, bool invert, int toggleMask)
{
m_field = (int *)&field;
initField(bitmask, invert, toggleMask);
}
void AutoBitsetCheckBox::setBitmask(int bitmask)
{
m_bitmask = bitmask;
updateValue();
}
void AutoBitsetCheckBox::setToggleMask(int toggleMask)
{
m_toggleMask = toggleMask;
updateValue();
}
void AutoBitsetCheckBox::setInverted(bool invert)
{
m_invert = invert;
updateValue();
}
void AutoBitsetCheckBox::updateValue()
{
if (m_field) {
setLock(true);
setChecked((m_invert && !m_toggleMask) != bool(*m_field & m_bitmask));
setLock(false);
}
}
void AutoBitsetCheckBox::onToggled(bool checked)
{
if (!m_field || lock())
return;
if (m_toggleMask) {
if (checked) {
*m_field &= ~m_toggleMask;
*m_field |= m_bitmask;
}
else {
*m_field &= ~m_bitmask;
*m_field |= m_toggleMask;
}
}
else {
if (m_invert)
checked = !checked;
if (checked)
*m_field |= m_bitmask;
else
*m_field &= ~m_bitmask;
}
emit currentDataChanged(checked);
dataChanged();
}
void AutoBitsetCheckBox::init()
{
connect(this, &QCheckBox::toggled, this, &AutoBitsetCheckBox::onToggled);
}
void AutoBitsetCheckBox::initField(int bitmask, bool invert, int toggleMask)
{
m_bitmask = bitmask;
m_toggleMask = toggleMask;
m_invert = toggleMask ? false : invert;
updateValue();
}