Files
edgetx-gx12/companion/src/shared/autocombobox.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

178 lines
3.5 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 "autocombobox.h"
AutoComboBox::AutoComboBox(QWidget * parent):
QComboBox(parent),
AutoWidget(),
m_field(nullptr),
m_next(0),
m_hasModel(false),
m_rawSource(nullptr),
m_rawSwitch(nullptr)
{
connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AutoComboBox::onCurrentIndexChanged);
}
AutoComboBox::~AutoComboBox()
{
}
void AutoComboBox::clear()
{
if (m_hasModel)
return;
setLock(true);
QComboBox::clear();
m_next = 0;
setLock(false);
}
void AutoComboBox::insertItems(int index, const QStringList & items)
{
if (m_hasModel)
return;
foreach(QString item, items) {
addItem(item);
}
}
void AutoComboBox::addItem(const QString & item)
{
if (m_hasModel)
return;
addItem(item, m_next++);
}
void AutoComboBox::addItem(const QString & item, int value)
{
if (m_hasModel)
return;
setLock(true);
QComboBox::addItem(item, value);
setLock(false);
updateValue();
}
void AutoComboBox::setField(unsigned int & field, GenericPanel * panel)
{
m_field = (int *)&field;
m_rawSource = nullptr;
m_rawSwitch = nullptr;
setFieldInit(panel);
}
void AutoComboBox::setField(int & field, GenericPanel * panel)
{
m_field = &field;
m_rawSource = nullptr;
m_rawSwitch = nullptr;
setFieldInit(panel);
}
void AutoComboBox::setField(RawSource & field, GenericPanel * panel)
{
m_rawSource = &field;
m_rawSwitch = nullptr;
m_field = nullptr;
setFieldInit(panel);
}
void AutoComboBox::setField(RawSwitch & field, GenericPanel * panel)
{
m_rawSwitch = &field;
m_rawSource = nullptr;
m_field = nullptr;
setFieldInit(panel);
}
void AutoComboBox::setFieldInit(GenericPanel * panel)
{
setPanel(panel);
updateValue();
}
void AutoComboBox::setModel(QAbstractItemModel * model)
{
setLock(true);
QComboBox::setModel(model);
setLock(false);
m_hasModel = true;
updateValue();
}
void AutoComboBox::setAutoIndexes()
{
if (m_hasModel)
return;
for (int i = 0; i < count(); ++i)
setItemData(i, i);
updateValue();
}
void AutoComboBox::updateValue()
{
if (!m_field && !m_rawSource && !m_rawSwitch)
return;
setLock(true);
if (m_field)
setCurrentIndex(findData(*m_field));
else if (m_rawSource)
setCurrentIndex(findData(m_rawSource->toValue()));
else if (m_rawSwitch)
setCurrentIndex(findData(m_rawSwitch->toValue()));
setLock(false);
}
void AutoComboBox::onCurrentIndexChanged(int index)
{
if (lock() || index < 0)
return;
bool ok;
const int val = itemData(index).toInt(&ok);
if (!ok)
return;
if (m_field && *m_field != val) {
*m_field = val;
}
else if (m_rawSource && m_rawSource->toValue() != val) {
*m_rawSource = RawSource(val);
}
else if (m_rawSwitch && m_rawSwitch->toValue() != val) {
*m_rawSwitch = RawSwitch(val);
}
else
return;
emit currentDataChanged(val);
dataChanged();
}