Merge pull request #6038 from opentx/mpaperno/cpn_src_models
Conitnued RawSource/RawSwitch data models refactoring
This commit is contained in:
@@ -204,6 +204,7 @@ set(CPN_COMMON_LIB common)
|
||||
|
||||
############# Supporting libraries ###############
|
||||
|
||||
add_subdirectory(datamodels)
|
||||
add_subdirectory(firmwares)
|
||||
add_subdirectory(shared)
|
||||
add_subdirectory(modeledit)
|
||||
@@ -248,7 +249,7 @@ set(companion_SRCS
|
||||
wizarddata.cpp
|
||||
wizarddialog.cpp
|
||||
styleeditdialog.cpp
|
||||
dialogs/filesyncdialog.cpp
|
||||
dialogs/filesyncdialog.cpp # TODO move to own lib with other dialogs
|
||||
)
|
||||
|
||||
set(companion_MOC_HDRS
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
set(datamodels_SRCS
|
||||
rawitemdatamodels.cpp
|
||||
rawitemfilteredmodel.cpp
|
||||
)
|
||||
|
||||
set(datamodels_HDRS
|
||||
rawitemdatamodels.h
|
||||
rawitemfilteredmodel.h
|
||||
)
|
||||
|
||||
qt5_wrap_cpp(datamodels_SRCS ${datamodels_HDRS})
|
||||
|
||||
add_library(datamodels ${datamodels_SRCS} ${datamodels_HDRS})
|
||||
target_link_libraries(datamodels PRIVATE ${CPN_COMMON_LIB})
|
||||
|
||||
target_include_directories(datamodels
|
||||
PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"${COMPANION_SRC_DIRECTORY}"
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_LIST_DIR}"
|
||||
)
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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 "rawitemdatamodels.h"
|
||||
#include "generalsettings.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "modeldata.h"
|
||||
|
||||
RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent) :
|
||||
AbstractRawItemDataModel(generalSettings, modelData, parent)
|
||||
{
|
||||
const Boards board = Boards(getCurrentBoard());
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
const int anasCount = CPN_MAX_STICKS + board.getCapability(Board::Pots) + board.getCapability(Board::Sliders) + board.getCapability(Board::MouseAnalogs);
|
||||
|
||||
addItems(SOURCE_TYPE_NONE, RawSource::NoneGroup, 1);
|
||||
for (int i=0; i < fw->getCapability(LuaScripts); i++)
|
||||
addItems(SOURCE_TYPE_LUA_OUTPUT, RawSource::ScriptsGroup, fw->getCapability(LuaOutputsPerScript), i * 16);
|
||||
addItems(SOURCE_TYPE_VIRTUAL_INPUT, RawSource::InputsGroup, fw->getCapability(VirtualInputs));
|
||||
addItems(SOURCE_TYPE_STICK, RawSource::SourcesGroup, anasCount);
|
||||
addItems(SOURCE_TYPE_ROTARY_ENCODER, RawSource::SourcesGroup, fw->getCapability(RotaryEncoders));
|
||||
addItems(SOURCE_TYPE_TRIM, RawSource::TrimsGroup, board.getCapability(Board::NumTrims));
|
||||
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, 1);
|
||||
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, board.getCapability(Board::Switches));
|
||||
addItems(SOURCE_TYPE_CUSTOM_SWITCH, RawSource::SwitchesGroup, fw->getCapability(LogicalSwitches));
|
||||
addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, CPN_MAX_CYC);
|
||||
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, fw->getCapability(TrainerInputs));
|
||||
addItems(SOURCE_TYPE_CH, RawSource::SourcesGroup, fw->getCapability(Outputs));
|
||||
addItems(SOURCE_TYPE_SPECIAL, RawSource::TelemGroup, 5);
|
||||
addItems(SOURCE_TYPE_TELEMETRY, RawSource::TelemGroup, CPN_MAX_SENSORS * 3);
|
||||
addItems(SOURCE_TYPE_GVAR, RawSource::GVarsGroup, fw->getCapability(Gvars));
|
||||
}
|
||||
|
||||
void RawSourceItemModel::setDynamicItemData(QStandardItem * item, const RawSource & src) const
|
||||
{
|
||||
Board::Type board = getCurrentBoard();
|
||||
item->setText(src.toString(modelData, generalSettings, board));
|
||||
item->setData(src.isAvailable(modelData, generalSettings, board), IsAvailableRole);
|
||||
}
|
||||
|
||||
void RawSourceItemModel::addItems(const RawSourceType & type, const int group, const int count, const int start)
|
||||
{
|
||||
for (int i = start; i < start + count; i++) {
|
||||
const RawSource src = RawSource(type, i);
|
||||
QStandardItem * modelItem = new QStandardItem();
|
||||
modelItem->setData(src.toValue(), ItemIdRole);
|
||||
modelItem->setData(type, ItemTypeRole);
|
||||
modelItem->setData(group, ItemFlagsRole);
|
||||
setDynamicItemData(modelItem, src);
|
||||
appendRow(modelItem);
|
||||
}
|
||||
}
|
||||
|
||||
void RawSourceItemModel::update() const
|
||||
{
|
||||
for (int i=0; i < rowCount(); ++i)
|
||||
setDynamicItemData(item(i), RawSource(item(i)->data(ItemIdRole).toInt()));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// RawSwitchItemModel
|
||||
//
|
||||
|
||||
RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent) :
|
||||
AbstractRawItemDataModel(generalSettings, modelData, parent)
|
||||
{
|
||||
Boards board = Boards(getCurrentBoard());
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
// Descending switch direction: NOT (!) switches
|
||||
addItems(SWITCH_TYPE_SENSOR, -CPN_MAX_SENSORS);
|
||||
addItems(SWITCH_TYPE_TELEMETRY, -1);
|
||||
addItems(SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes));
|
||||
addItems(SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches));
|
||||
addItems(SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders));
|
||||
addItems(SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches));
|
||||
addItems(SWITCH_TYPE_MULTIPOS_POT, -(board.getCapability(Board::MultiposPots) * board.getCapability(Board::MultiposPotsPositions)));
|
||||
addItems(SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions));
|
||||
|
||||
// Ascending switch direction (including zero)
|
||||
addItems(SWITCH_TYPE_TIMER_MODE, 5);
|
||||
addItems(SWITCH_TYPE_NONE, 1);
|
||||
addItems(SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions));
|
||||
addItems(SWITCH_TYPE_MULTIPOS_POT, board.getCapability(Board::MultiposPots) * board.getCapability(Board::MultiposPotsPositions));
|
||||
addItems(SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches));
|
||||
addItems(SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders));
|
||||
addItems(SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches));
|
||||
addItems(SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes));
|
||||
addItems(SWITCH_TYPE_TELEMETRY, 1);
|
||||
addItems(SWITCH_TYPE_SENSOR, CPN_MAX_SENSORS);
|
||||
addItems(SWITCH_TYPE_ON, 1);
|
||||
addItems(SWITCH_TYPE_ONE, 1);
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::setDynamicItemData(QStandardItem * item, const RawSwitch & rsw) const
|
||||
{
|
||||
const Board::Type board = getCurrentBoard();
|
||||
item->setText(rsw.toString(board, generalSettings, modelData));
|
||||
item->setData(rsw.isAvailable(modelData, generalSettings, board), IsAvailableRole);
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::addItems(const RawSwitchType & type, int count)
|
||||
{
|
||||
// Most RawSwitch() indices are one-based (vs. typical zero); these are exceptions to the rule:
|
||||
const static QVector<int> rawSwitchIndexBaseZeroTypes = QVector<int>() << SWITCH_TYPE_NONE << SWITCH_TYPE_ON << SWITCH_TYPE_OFF << SWITCH_TYPE_TIMER_MODE;
|
||||
// handle exceptions in RawSwitch() index values
|
||||
const short rawIdxAdj = rawSwitchIndexBaseZeroTypes.contains(type) ? -1 : 0;
|
||||
|
||||
// determine cotext flags
|
||||
int context = RawSwitch::AllSwitchContexts;
|
||||
switch (type) {
|
||||
case SWITCH_TYPE_FLIGHT_MODE:
|
||||
context &= ~RawSwitch::MixesContext;
|
||||
// fallthrough
|
||||
case SWITCH_TYPE_VIRTUAL:
|
||||
case SWITCH_TYPE_SENSOR:
|
||||
context &= ~RawSwitch::GlobalFunctionsContext;
|
||||
break;
|
||||
|
||||
case SWITCH_TYPE_TIMER_MODE:
|
||||
context = RawSwitch::TimersContext;
|
||||
break;
|
||||
|
||||
case SWITCH_TYPE_NONE:
|
||||
context &= ~RawSwitch::TimersContext;
|
||||
break;
|
||||
|
||||
case SWITCH_TYPE_ON:
|
||||
case SWITCH_TYPE_ONE:
|
||||
context = RawSwitch::SpecialFunctionsContext | RawSwitch::GlobalFunctionsContext;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int i = (count < 0 ? count : 1);
|
||||
count = (i < 0 ? 0 : count + i);
|
||||
for ( ; i < count; ++i) {
|
||||
RawSwitch rs(type, i + rawIdxAdj);
|
||||
QStandardItem * modelItem = new QStandardItem();
|
||||
modelItem->setData(rs.toValue(), ItemIdRole);
|
||||
modelItem->setData(type, ItemTypeRole);
|
||||
modelItem->setData(context, ItemFlagsRole);
|
||||
setDynamicItemData(modelItem, rs);
|
||||
appendRow(modelItem);
|
||||
}
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::update() const
|
||||
{
|
||||
for (int i=0; i < rowCount(); ++i)
|
||||
setDynamicItemData(item(i), RawSwitch(item(i)->data(ItemIdRole).toInt()));
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef RAWITEMDATAMODELS_H
|
||||
#define RAWITEMDATAMODELS_H
|
||||
|
||||
#include "rawsource.h"
|
||||
#include "rawswitch.h"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
class GeneralSettings;
|
||||
class ModelData;
|
||||
|
||||
class AbstractRawItemDataModel: public QStandardItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum DataRoles { ItemIdRole = Qt::UserRole, ItemTypeRole, ItemFlagsRole, IsAvailableRole };
|
||||
Q_ENUM(DataRoles)
|
||||
|
||||
explicit AbstractRawItemDataModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent = nullptr) :
|
||||
QStandardItemModel(parent),
|
||||
generalSettings(generalSettings),
|
||||
modelData(modelData)
|
||||
{}
|
||||
|
||||
public slots:
|
||||
virtual void update() const = 0;
|
||||
|
||||
protected:
|
||||
const GeneralSettings * generalSettings;
|
||||
const ModelData * modelData;
|
||||
};
|
||||
|
||||
|
||||
class RawSourceItemModel: public AbstractRawItemDataModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RawSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void update() const override;
|
||||
|
||||
protected:
|
||||
void setDynamicItemData(QStandardItem * item, const RawSource & src) const;
|
||||
void addItems(const RawSourceType & type, const int group, const int count, const int start = 0);
|
||||
};
|
||||
|
||||
|
||||
class RawSwitchItemModel: public AbstractRawItemDataModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void update() const override;
|
||||
|
||||
protected:
|
||||
void setDynamicItemData(QStandardItem * item, const RawSwitch & rsw) const;
|
||||
void addItems(const RawSwitchType & type, int count);
|
||||
};
|
||||
|
||||
|
||||
#endif // RAWITEMDATAMODELS_H
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 "rawitemfilteredmodel.h"
|
||||
#include "rawitemdatamodels.h"
|
||||
|
||||
RawItemFilteredModel::RawItemFilteredModel(QAbstractItemModel * sourceModel, int flags, QObject * parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
filterFlags(0)
|
||||
{
|
||||
setFilterRole(AbstractRawItemDataModel::IsAvailableRole);
|
||||
setFilterKeyColumn(0);
|
||||
setFilterFlags(flags);
|
||||
setDynamicSortFilter(true);
|
||||
setSourceModel(sourceModel);
|
||||
}
|
||||
|
||||
void RawItemFilteredModel::setFilterFlags(int flags)
|
||||
{
|
||||
if (filterFlags != flags) {
|
||||
filterFlags = flags;
|
||||
invalidateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
bool RawItemFilteredModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
const QModelIndex & srcIdx = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
if (!srcIdx.isValid() || !sourceModel()->data(srcIdx, filterRole()).toBool())
|
||||
return false;
|
||||
|
||||
if (!filterFlags)
|
||||
return true;
|
||||
|
||||
bool ok;
|
||||
const int flags = sourceModel()->data(srcIdx, AbstractRawItemDataModel::ItemFlagsRole).toInt(&ok);
|
||||
return (ok && (!flags || (filterFlags & flags)));
|
||||
}
|
||||
|
||||
void RawItemFilteredModel::update() const
|
||||
{
|
||||
AbstractRawItemDataModel * model = qobject_cast<AbstractRawItemDataModel *>(sourceModel());
|
||||
if (model)
|
||||
model->update();
|
||||
}
|
||||
|
||||
|
||||
RawSourceFilterItemModel::RawSourceFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, int flags, QObject * parent) :
|
||||
RawItemFilteredModel(new RawSourceItemModel(generalSettings, modelData, parent), flags, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RawSwitchFilterItemModel::RawSwitchFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, int context, QObject * parent) :
|
||||
RawItemFilteredModel(new RawSwitchItemModel(generalSettings, modelData, parent), context, parent)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef RAWITEMFILTEREDMODEL_H
|
||||
#define RAWITEMFILTEREDMODEL_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class GeneralSettings;
|
||||
class ModelData;
|
||||
class RawSourceItemModel;
|
||||
class RawSwitchItemModel;
|
||||
|
||||
class RawItemFilteredModel: public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RawItemFilteredModel(QAbstractItemModel * sourceModel, int flags, QObject * parent = nullptr);
|
||||
explicit RawItemFilteredModel(QAbstractItemModel * sourceModel, QObject * parent = nullptr) : RawItemFilteredModel(sourceModel, 0, parent) {}
|
||||
|
||||
public slots:
|
||||
void setFilterFlags(int flags);
|
||||
void update() const;
|
||||
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||
|
||||
int filterFlags;
|
||||
};
|
||||
|
||||
|
||||
// The specialized "convenience" types below can go away once centralalized RawSource/RawSwitch item models are established.
|
||||
// These proxy classes will automatically create a source model of the corresponding type.
|
||||
|
||||
class RawSwitchFilterItemModel: public RawItemFilteredModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using RawItemFilteredModel::RawItemFilteredModel;
|
||||
|
||||
explicit RawSwitchFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, int context, QObject * parent = nullptr);
|
||||
};
|
||||
|
||||
|
||||
class RawSourceFilterItemModel: public RawItemFilteredModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using RawItemFilteredModel::RawItemFilteredModel;
|
||||
|
||||
explicit RawSourceFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, int flags, QObject * parent = nullptr);
|
||||
|
||||
explicit RawSourceFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, QObject * parent = nullptr) :
|
||||
RawSourceFilterItemModel(generalSettings, modelData, 0, parent) {}
|
||||
};
|
||||
|
||||
#endif // RAWITEMFILTEREDMODEL_H
|
||||
@@ -495,7 +495,7 @@ bool RawSource::isTimeBased(Board::Type board) const
|
||||
return (type==SOURCE_TYPE_TELEMETRY && (index==TELEMETRY_SOURCE_TX_TIME || index==TELEMETRY_SOURCE_TIMER1 || index==TELEMETRY_SOURCE_TIMER2 || index==TELEMETRY_SOURCE_TIMER3));
|
||||
}
|
||||
|
||||
bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board)
|
||||
bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const
|
||||
{
|
||||
if (board == Board::BOARD_UNKNOWN)
|
||||
board = getCurrentBoard();
|
||||
|
||||
@@ -213,6 +213,20 @@ class RawSource {
|
||||
Q_DECLARE_TR_FUNCTIONS(RawSource)
|
||||
|
||||
public:
|
||||
enum SourceGroups {
|
||||
NoneGroup = 0x001,
|
||||
SourcesGroup = 0x002,
|
||||
TrimsGroup = 0x004,
|
||||
SwitchesGroup = 0x008,
|
||||
GVarsGroup = 0x010,
|
||||
TelemGroup = 0x020,
|
||||
InputsGroup = 0x040,
|
||||
ScriptsGroup = 0x080,
|
||||
|
||||
InputSourceGroups = NoneGroup | SourcesGroup | TrimsGroup | SwitchesGroup | InputsGroup,
|
||||
AllSourceGroups = InputSourceGroups | GVarsGroup | TelemGroup | ScriptsGroup
|
||||
};
|
||||
|
||||
RawSource():
|
||||
type(SOURCE_TYPE_NONE),
|
||||
index(0)
|
||||
@@ -243,7 +257,7 @@ class RawSource {
|
||||
bool isPot(int * potsIndex = NULL, Board::Type board = Board::BOARD_UNKNOWN) const;
|
||||
bool isSlider(int * sliderIndex = NULL, Board::Type board = Board::BOARD_UNKNOWN) const;
|
||||
bool isTimeBased(Board::Type board = Board::BOARD_UNKNOWN) const;
|
||||
bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN) const;
|
||||
|
||||
bool operator == ( const RawSource & other) {
|
||||
return (this->type == other.type) && (this->index == other.index);
|
||||
|
||||
@@ -142,7 +142,7 @@ QString RawSwitch::toString(Board::Type board, const GeneralSettings * const gen
|
||||
}
|
||||
}
|
||||
|
||||
bool RawSwitch::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board)
|
||||
bool RawSwitch::isAvailable(const ModelData * const model, const GeneralSettings * const gs, Board::Type board) const
|
||||
{
|
||||
if (board == Board::BOARD_UNKNOWN)
|
||||
board = getCurrentBoard();
|
||||
|
||||
@@ -52,6 +52,18 @@ class RawSwitch {
|
||||
Q_DECLARE_TR_FUNCTIONS(RawSwitch)
|
||||
|
||||
public:
|
||||
enum SwitchContext
|
||||
{
|
||||
LogicalSwitchesContext = 0x01,
|
||||
SpecialFunctionsContext = 0x02,
|
||||
GlobalFunctionsContext = 0x04,
|
||||
TimersContext = 0x08,
|
||||
MixesContext = 0x10,
|
||||
|
||||
AllModelContexts = SpecialFunctionsContext | LogicalSwitchesContext | TimersContext | MixesContext,
|
||||
AllSwitchContexts = AllModelContexts | GlobalFunctionsContext
|
||||
};
|
||||
|
||||
RawSwitch():
|
||||
type(SWITCH_TYPE_NONE),
|
||||
index(0)
|
||||
@@ -77,7 +89,7 @@ class RawSwitch {
|
||||
|
||||
RawSwitch convert(RadioDataConversionState & cstate);
|
||||
QString toString(Board::Type board = Board::BOARD_UNKNOWN, const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL) const;
|
||||
bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN);
|
||||
bool isAvailable(const ModelData * const model = NULL, const GeneralSettings * const gs = NULL, Board::Type board = Board::BOARD_UNKNOWN) const;
|
||||
|
||||
bool operator== ( const RawSwitch& other) {
|
||||
return (this->type == other.type) && (this->index == other.index);
|
||||
|
||||
@@ -465,85 +465,6 @@ void Helpers::getFileComboBoxValue(QComboBox * b, char * dest, int length)
|
||||
}
|
||||
}
|
||||
|
||||
void Helpers::addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings,
|
||||
const ModelData * const model, const int start)
|
||||
{
|
||||
for (int i = start; i < start + count; i++) {
|
||||
RawSource src = RawSource(type, i);
|
||||
if (!src.isAvailable(model, generalSettings, getCurrentBoard()))
|
||||
continue;
|
||||
|
||||
QStandardItem * modelItem = new QStandardItem(src.toString(model, generalSettings));
|
||||
modelItem->setData(src.toValue(), Qt::UserRole);
|
||||
itemModel->appendRow(modelItem);
|
||||
}
|
||||
}
|
||||
|
||||
QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * const generalSettings, const ModelData * const model, unsigned int flags)
|
||||
{
|
||||
QStandardItemModel * itemModel = new QStandardItemModel();
|
||||
Boards board = Boards(getCurrentBoard());
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
if (flags & POPULATE_NONE) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_NONE, 1, generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_SCRIPT_OUTPUTS) {
|
||||
for (int i=0; i < getCurrentFirmware()->getCapability(LuaScripts); i++) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_LUA_OUTPUT, fw->getCapability(LuaOutputsPerScript), generalSettings, model, i * 16);
|
||||
}
|
||||
}
|
||||
|
||||
if (model && (flags & POPULATE_VIRTUAL_INPUTS)) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_VIRTUAL_INPUT, fw->getCapability(VirtualInputs), generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_SOURCES) {
|
||||
int totalSources = CPN_MAX_STICKS + board.getCapability(Board::Pots) + board.getCapability(Board::Sliders) + board.getCapability(Board::MouseAnalogs);
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_STICK, totalSources, generalSettings, model);
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders), generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_TRIMS) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_TRIM, board.getCapability(Board::NumTrims), generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_SOURCES) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_MAX, 1, generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_SWITCHES) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_SWITCH, board.getCapability(Board::Switches), generalSettings, model);
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_CUSTOM_SWITCH, fw->getCapability(LogicalSwitches), generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_SOURCES) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_CYC, CPN_MAX_CYC, generalSettings, model);
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_PPM, fw->getCapability(TrainerInputs), generalSettings, model);
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_CH, fw->getCapability(Outputs), generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_TELEMETRY) {
|
||||
int count = 0;
|
||||
if (IS_ARM(board.getBoardType())) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_SPECIAL, 5, generalSettings, model);
|
||||
count = CPN_MAX_SENSORS * 3;
|
||||
}
|
||||
else {
|
||||
count = ((flags & POPULATE_TELEMETRYEXT) ? TELEMETRY_SOURCES_STATUS_COUNT : TELEMETRY_SOURCES_COUNT);
|
||||
}
|
||||
if (model && count)
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_TELEMETRY, count, generalSettings, model);
|
||||
}
|
||||
|
||||
if (flags & POPULATE_GVARS) {
|
||||
addRawSourceItems(itemModel, SOURCE_TYPE_GVAR, fw->getCapability(Gvars), generalSettings, model);
|
||||
}
|
||||
|
||||
return itemModel;
|
||||
}
|
||||
|
||||
void Helpers::exportAppSettings(QWidget * dlgParent)
|
||||
{
|
||||
static QString lastExpFile = CPN_SETTINGS_INI_PATH.arg(QDateTime::currentDateTime().toString("dd-MMM-yy"));
|
||||
|
||||
@@ -117,26 +117,8 @@ class CurveGroup : public QObject {
|
||||
int lastType;
|
||||
};
|
||||
|
||||
|
||||
#define POPULATE_NONE (1<<0)
|
||||
#define POPULATE_SOURCES (1<<1)
|
||||
#define POPULATE_TRIMS (1<<2)
|
||||
#define POPULATE_SWITCHES (1<<3)
|
||||
#define POPULATE_GVARS (1<<4)
|
||||
#define POPULATE_TELEMETRY (1<<5)
|
||||
#define POPULATE_TELEMETRYEXT (1<<6)
|
||||
#define POPULATE_VIRTUAL_INPUTS (1<<7)
|
||||
#define POPULATE_SCRIPT_OUTPUTS (1<<8)
|
||||
|
||||
#define GVARS_VARIANT 0x0001
|
||||
#define FRSKY_VARIANT 0x0002
|
||||
|
||||
namespace Helpers
|
||||
{
|
||||
void addRawSourceItems(QStandardItemModel * itemModel, const RawSourceType & type, int count, const GeneralSettings * const generalSettings = NULL,
|
||||
const ModelData * const model = NULL, const int start = 0);
|
||||
QStandardItemModel * getRawSourceItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const model = NULL, unsigned int flags = 0);
|
||||
|
||||
void populateGvarUseCB(QComboBox *b, unsigned int phase);
|
||||
void populateGVCB(QComboBox & b, int value, const ModelData & model);
|
||||
QString getAdjustmentString(int16_t val, const ModelData * model = NULL, bool sign = false);
|
||||
|
||||
@@ -16,7 +16,6 @@ set(modeledit_NAMES
|
||||
)
|
||||
|
||||
set(modeledit_SRCS
|
||||
switchitemmodel.cpp
|
||||
flightmodes.cpp
|
||||
inputs.cpp
|
||||
mixes.cpp
|
||||
@@ -58,4 +57,4 @@ qt5_wrap_ui(modeledit_SRCS ${modeledit_UIS})
|
||||
qt5_wrap_cpp(modeledit_SRCS ${modeledit_HDRS})
|
||||
|
||||
add_library(modeledit ${modeledit_SRCS})
|
||||
target_link_libraries(modeledit PRIVATE ${CPN_COMMON_LIB} Qt5::Multimedia)
|
||||
target_link_libraries(modeledit PRIVATE datamodels ${CPN_COMMON_LIB} Qt5::Multimedia)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "customfunctions.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
|
||||
@@ -69,9 +69,6 @@ void RepeatComboBox::update()
|
||||
CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
GenericPanel(parent, model, generalSettings, firmware),
|
||||
functions(model ? model->customFn : generalSettings.customFn),
|
||||
rawSwitchItemModel(NULL),
|
||||
rawSrcInputsItemModel(NULL),
|
||||
rawSrcAllItemModel(NULL),
|
||||
mediaPlayerCurrent(-1),
|
||||
mediaPlayer(NULL)
|
||||
{
|
||||
@@ -79,7 +76,10 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
||||
lock = true;
|
||||
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
||||
|
||||
setDataModels();
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? RawSwitch::SpecialFunctionsContext : RawSwitch::GlobalFunctionsContext, this);
|
||||
rawSrcAllItemModel = new RawSourceFilterItemModel(&generalSettings, model, this);
|
||||
rawSrcInputsItemModel = new RawSourceFilterItemModel(rawSrcAllItemModel->sourceModel(), RawSource::InputSourceGroups, this);
|
||||
rawSrcGVarsItemModel = new RawSourceFilterItemModel(rawSrcAllItemModel->sourceModel(), RawSource::GVarsGroup, this);
|
||||
|
||||
if (!firmware->getCapability(VoicesAsNumbers)) {
|
||||
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
|
||||
@@ -253,24 +253,13 @@ CustomFunctionsPanel::~CustomFunctionsPanel()
|
||||
stopSound(mediaPlayerCurrent);
|
||||
}
|
||||
|
||||
void CustomFunctionsPanel::setDataModels()
|
||||
void CustomFunctionsPanel::updateDataModels()
|
||||
{
|
||||
if (rawSwitchItemModel)
|
||||
rawSwitchItemModel->update();
|
||||
else
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, model, model ? SpecialFunctionsContext : GlobalFunctionsContext);
|
||||
|
||||
// The RawSource item models have to be reloaded on every update(). TODO: convert to filtered model like for RawSwitches
|
||||
|
||||
if (rawSrcInputsItemModel)
|
||||
rawSrcInputsItemModel->deleteLater();
|
||||
if (rawSrcAllItemModel)
|
||||
rawSrcAllItemModel->deleteLater();
|
||||
|
||||
rawSrcInputsItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_TRIMS|POPULATE_SWITCHES);
|
||||
rawSrcInputsItemModel->setParent(this);
|
||||
rawSrcAllItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE|POPULATE_SOURCES|POPULATE_VIRTUAL_INPUTS|POPULATE_SWITCHES|POPULATE_GVARS|POPULATE_TRIMS|POPULATE_TELEMETRY|POPULATE_TELEMETRYEXT|POPULATE_SCRIPT_OUTPUTS);
|
||||
rawSrcAllItemModel->setParent(this);
|
||||
const bool oldLock = lock;
|
||||
lock = true;
|
||||
rawSwitchItemModel->update();
|
||||
rawSrcAllItemModel->update();
|
||||
lock = oldLock;
|
||||
}
|
||||
|
||||
void CustomFunctionsPanel::onMediaPlayerStateChanged(QMediaPlayer::State state)
|
||||
@@ -603,8 +592,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
|
||||
void CustomFunctionsPanel::update()
|
||||
{
|
||||
setDataModels();
|
||||
|
||||
updateDataModels();
|
||||
lock = true;
|
||||
int num_fsw = model ? firmware->getCapability(CustomFunctions) : firmware->getCapability(GlobalFunctions);
|
||||
for (int i=0; i<num_fsw; i++) {
|
||||
@@ -749,7 +737,7 @@ void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsi
|
||||
b->setCurrentIndex(b->findData(value));
|
||||
break;
|
||||
case 2:
|
||||
b->setModel(Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_GVARS));
|
||||
b->setModel(rawSrcGVarsItemModel);
|
||||
b->setCurrentIndex(b->findData(value));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <QMediaPlayer>
|
||||
|
||||
class RawSourceFilterItemModel;
|
||||
class RawSwitchFilterItemModel;
|
||||
class TimerEdit;
|
||||
|
||||
@@ -61,7 +62,7 @@ class CustomFunctionsPanel : public GenericPanel
|
||||
CustomFunctionData * functions;
|
||||
|
||||
private slots:
|
||||
void setDataModels();
|
||||
void updateDataModels();
|
||||
void customFunctionEdited();
|
||||
void functionEdited();
|
||||
void fsw_customContextMenuRequested(QPoint pos);
|
||||
@@ -82,8 +83,9 @@ class CustomFunctionsPanel : public GenericPanel
|
||||
void populateGVmodeCB(QComboBox *b, unsigned int value);
|
||||
void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
QStandardItemModel * rawSrcInputsItemModel;
|
||||
QStandardItemModel * rawSrcAllItemModel;
|
||||
RawSourceFilterItemModel * rawSrcAllItemModel;
|
||||
RawSourceFilterItemModel * rawSrcInputsItemModel;
|
||||
RawSourceFilterItemModel * rawSrcGVarsItemModel;
|
||||
|
||||
QSet<QString> tracksSet;
|
||||
QSet<QString> scriptsSet;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "expodialog.h"
|
||||
#include "ui_expodialog.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, GeneralSettings & generalSettings,
|
||||
@@ -62,7 +62,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G
|
||||
curveGroup = new CurveGroup(ui->curveTypeCB, ui->curveGVarCB, ui->curveValueCB, ui->curveValueSB, ed->curve, model,
|
||||
firmware->getCapability(HasInputDiff) ? 0 : (HIDE_DIFF | HIDE_NEGATIVE_CURVES));
|
||||
|
||||
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext));
|
||||
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::MixesContext, this));
|
||||
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(ed->swtch.toValue()));
|
||||
|
||||
ui->sideCB->setCurrentIndex(ed->mode-1);
|
||||
@@ -93,7 +93,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G
|
||||
|
||||
if (firmware->getCapability(VirtualInputs)) {
|
||||
ui->inputName->setMaxLength(firmware->getCapability(InputsLength));
|
||||
ui->sourceCB->setModel(Helpers::getRawSourceItemModel(&generalSettings, &model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_SWITCHES | POPULATE_TRIMS | POPULATE_TELEMETRY));
|
||||
ui->sourceCB->setModel(new RawSourceFilterItemModel(&generalSettings, &model, (RawSource::InputSourceGroups & ~RawSource::InputsGroup) | RawSource::TelemGroup, this));
|
||||
ui->sourceCB->setCurrentIndex(ui->sourceCB->findData(ed->srcRaw.toValue()));
|
||||
ui->sourceCB->removeItem(0);
|
||||
ui->inputName->setValidator(new QRegExpValidator(rx, this));
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
|
||||
#include "flightmodes.h"
|
||||
#include "ui_flightmode.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
#include "helpers.h"
|
||||
#include "customdebug.h"
|
||||
|
||||
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseIdx, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchFilterItemModel * switchModel):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::FlightMode),
|
||||
phaseIdx(phaseIdx),
|
||||
@@ -53,10 +53,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI
|
||||
|
||||
// Phase switch
|
||||
if (phaseIdx > 0) {
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext);
|
||||
ui->swtch->setModel(rawSwitchItemModel);
|
||||
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
||||
connect(ui->swtch, SIGNAL(currentIndexChanged(int)), this, SLOT(phaseSwitch_currentIndexChanged(int)));
|
||||
ui->swtch->setModel(switchModel);
|
||||
connect(ui->swtch, SIGNAL(activated(int)), this, SLOT(phaseSwitchChanged(int)));
|
||||
}
|
||||
else {
|
||||
ui->swtch->hide();
|
||||
@@ -287,11 +285,8 @@ FlightModePanel::~FlightModePanel()
|
||||
|
||||
void FlightModePanel::update()
|
||||
{
|
||||
if (rawSwitchItemModel) {
|
||||
rawSwitchItemModel->update();
|
||||
}
|
||||
|
||||
ui->name->setText(phase.name);
|
||||
ui->swtch->setCurrentIndex(ui->swtch->findData(phase.swtch.toValue()));
|
||||
|
||||
int scale = firmware->getCapability(SlowScale);
|
||||
ui->fadeIn->setValue(float(phase.fadeIn)/scale);
|
||||
@@ -382,11 +377,15 @@ void FlightModePanel::phaseName_editingFinished()
|
||||
emit nameModified();
|
||||
}
|
||||
|
||||
void FlightModePanel::phaseSwitch_currentIndexChanged(int index)
|
||||
void FlightModePanel::phaseSwitchChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
|
||||
phase.swtch = RawSwitch(comboBox->itemData(index).toInt());
|
||||
if (lock)
|
||||
return;
|
||||
|
||||
bool ok;
|
||||
const RawSwitch rs(ui->swtch->itemData(index).toInt(&ok));
|
||||
if (ok && phase.swtch.toValue() != rs.toValue()) {
|
||||
phase.swtch = rs;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -719,14 +718,18 @@ FlightModesPanel::FlightModesPanel(QWidget * parent, ModelData & model, GeneralS
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
modesCount(firmware->getCapability(FlightModes))
|
||||
{
|
||||
|
||||
RawSwitchFilterItemModel * swModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::MixesContext, this);
|
||||
connect(this, &FlightModesPanel::updated, swModel, &RawSwitchFilterItemModel::update);
|
||||
|
||||
QGridLayout * gridLayout = new QGridLayout(this);
|
||||
tabWidget = new QTabWidget(this);
|
||||
for (int i=0; i<modesCount; i++) {
|
||||
FlightModePanel * tab = new FlightModePanel(tabWidget, model, i, generalSettings, firmware);
|
||||
FlightModePanel * tab = new FlightModePanel(tabWidget, model, i, generalSettings, firmware, swModel);
|
||||
tab->setProperty("index", i);
|
||||
panels << tab;
|
||||
connect(tab, SIGNAL(modified()), this, SLOT(onPhaseModified()));
|
||||
connect(tab, SIGNAL(nameModified()), this, SLOT(onPhaseNameChanged()));
|
||||
connect(tab, &FlightModePanel::modified, this, &FlightModesPanel::modified);
|
||||
connect(tab, &FlightModePanel::nameModified, this, &FlightModesPanel::onPhaseNameChanged);
|
||||
connect(this, &FlightModesPanel::updated, tab, &FlightModePanel::update);
|
||||
tabWidget->addTab(tab, getTabName(i));
|
||||
}
|
||||
gridLayout->addWidget(tabWidget, 0, 0, 1, 1);
|
||||
@@ -737,11 +740,6 @@ FlightModesPanel::~FlightModesPanel()
|
||||
{
|
||||
}
|
||||
|
||||
void FlightModesPanel::onPhaseModified()
|
||||
{
|
||||
emit modified();
|
||||
}
|
||||
|
||||
QString FlightModesPanel::getTabName(int index)
|
||||
{
|
||||
QString result = tr("Flight Mode %1").arg(index);
|
||||
@@ -764,10 +762,5 @@ void FlightModesPanel::onPhaseNameChanged()
|
||||
|
||||
void FlightModesPanel::update()
|
||||
{
|
||||
on_tabWidget_currentChanged(tabWidget->currentIndex());
|
||||
}
|
||||
|
||||
void FlightModesPanel::on_tabWidget_currentChanged(int index)
|
||||
{
|
||||
panels[index]->update();
|
||||
emit updated();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class FlightModePanel : public ModelPanel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FlightModePanel(QWidget *parent, ModelData &model, int modeIdx, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
FlightModePanel(QWidget *parent, ModelData &model, int modeIdx, GeneralSettings & generalSettings, Firmware * firmware, RawSwitchFilterItemModel * switchModel);
|
||||
virtual ~FlightModePanel();
|
||||
|
||||
virtual void update();
|
||||
@@ -45,7 +45,7 @@ class FlightModePanel : public ModelPanel
|
||||
|
||||
private slots:
|
||||
void phaseName_editingFinished();
|
||||
void phaseSwitch_currentIndexChanged(int index);
|
||||
void phaseSwitchChanged(int index);
|
||||
void phaseFadeIn_editingFinished();
|
||||
void phaseFadeOut_editingFinished();
|
||||
void phaseTrimUse_currentIndexChanged(int index);
|
||||
@@ -104,18 +104,20 @@ class FlightModesPanel : public ModelPanel
|
||||
FlightModesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
virtual ~FlightModesPanel();
|
||||
|
||||
virtual void update();
|
||||
public slots:
|
||||
virtual void update() override;
|
||||
|
||||
signals:
|
||||
void updated();
|
||||
|
||||
private slots:
|
||||
void onPhaseModified();
|
||||
void onPhaseNameChanged();
|
||||
void on_tabWidget_currentChanged(int index);
|
||||
|
||||
private:
|
||||
QString getTabName(int index);
|
||||
|
||||
int modesCount;
|
||||
QTabWidget *tabWidget;
|
||||
QString getTabName(int index);
|
||||
QVector<FlightModePanel *> panels;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
#include "heli.h"
|
||||
#include "ui_heli.h"
|
||||
#include "helpers.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
|
||||
HeliPanel::HeliPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::Heli),
|
||||
rawSourceItemModel(nullptr)
|
||||
ui(new Ui::Heli)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setDataModels();
|
||||
rawSourceItemModel = new RawSourceFilterItemModel(&generalSettings, &model, RawSource::InputSourceGroups, this);
|
||||
|
||||
connect(ui->swashType, SIGNAL(currentIndexChanged(int)), this, SLOT(edited()));
|
||||
connect(ui->swashRingVal, SIGNAL(editingFinished()), this, SLOT(edited()));
|
||||
@@ -66,19 +66,18 @@ HeliPanel::~HeliPanel()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void HeliPanel::setDataModels()
|
||||
void HeliPanel::updateDataModels()
|
||||
{
|
||||
if (rawSourceItemModel)
|
||||
rawSourceItemModel->deleteLater();
|
||||
|
||||
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS);
|
||||
rawSourceItemModel->setParent(this);
|
||||
const bool oldLock = lock;
|
||||
lock = true;
|
||||
rawSourceItemModel->update();
|
||||
lock = oldLock;
|
||||
}
|
||||
|
||||
void HeliPanel::update()
|
||||
{
|
||||
lock = true;
|
||||
setDataModels();
|
||||
updateDataModels();
|
||||
|
||||
ui->swashType->setCurrentIndex(model->swashRingData.type);
|
||||
ui->swashCollectiveSource->setModel(rawSourceItemModel);
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "modeledit.h"
|
||||
|
||||
class RawSourceFilterItemModel;
|
||||
|
||||
namespace Ui {
|
||||
class Heli;
|
||||
}
|
||||
@@ -37,12 +39,12 @@ class HeliPanel : public ModelPanel
|
||||
void update();
|
||||
|
||||
private slots:
|
||||
void setDataModels();
|
||||
void updateDataModels();
|
||||
void edited();
|
||||
|
||||
private:
|
||||
Ui::Heli *ui;
|
||||
QStandardItemModel * rawSourceItemModel;
|
||||
RawSourceFilterItemModel * rawSourceItemModel;
|
||||
};
|
||||
|
||||
#endif // _HELI_H_
|
||||
|
||||
@@ -19,22 +19,21 @@
|
||||
*/
|
||||
|
||||
#include "logicalswitches.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
rawSourceItemModel(NULL),
|
||||
selectedSwitch(0)
|
||||
{
|
||||
Stopwatch s1("LogicalSwitchesPanel");
|
||||
|
||||
int channelsMax = model.getChannelsMax(true);
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, LogicalSwitchesContext);
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::LogicalSwitchesContext, this);
|
||||
|
||||
setDataModels();
|
||||
const int srcGroups = firmware->getCapability(GvarsInCS) ? 0 : (RawSource::AllSourceGroups & ~RawSource::GVarsGroup);
|
||||
rawSourceItemModel = new RawSourceFilterItemModel(&generalSettings, &model, srcGroups, this);
|
||||
|
||||
QStringList headerLabels;
|
||||
headerLabels << "#" << tr("Function") << tr("V1") << tr("V2") << tr("AND Switch");
|
||||
@@ -45,6 +44,8 @@ LogicalSwitchesPanel::LogicalSwitchesPanel(QWidget * parent, ModelData & model,
|
||||
|
||||
s1.report("header");
|
||||
|
||||
const int channelsMax = model.getChannelsMax(true);
|
||||
|
||||
lock = true;
|
||||
for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) {
|
||||
// The label
|
||||
@@ -161,14 +162,13 @@ LogicalSwitchesPanel::~LogicalSwitchesPanel()
|
||||
{
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::setDataModels()
|
||||
void LogicalSwitchesPanel::updateDataModels()
|
||||
{
|
||||
if (rawSourceItemModel)
|
||||
rawSourceItemModel->deleteLater();
|
||||
|
||||
int srcFlags = POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0);
|
||||
rawSourceItemModel = Helpers::getRawSourceItemModel(&generalSettings, model, srcFlags);
|
||||
rawSourceItemModel->setParent(this);
|
||||
const bool oldLock = lock;
|
||||
lock = true;
|
||||
rawSwitchItemModel->update();
|
||||
rawSourceItemModel->update();
|
||||
lock = oldLock;
|
||||
}
|
||||
|
||||
void LogicalSwitchesPanel::functionChanged()
|
||||
@@ -179,6 +179,7 @@ void LogicalSwitchesPanel::functionChanged()
|
||||
if (model->logicalSw[i].func == newFunc)
|
||||
return;
|
||||
|
||||
const unsigned oldFunc = model->logicalSw[i].func;
|
||||
CSFunctionFamily oldFuncFamily = model->logicalSw[i].getFunctionFamily();
|
||||
model->logicalSw[i].func = newFunc;
|
||||
CSFunctionFamily newFuncFamily = model->logicalSw[i].getFunctionFamily();
|
||||
@@ -194,7 +195,11 @@ void LogicalSwitchesPanel::functionChanged()
|
||||
model->logicalSw[i].val2 = -129;
|
||||
}
|
||||
}
|
||||
update();
|
||||
if (bool(oldFunc) != bool(newFunc))
|
||||
update();
|
||||
else
|
||||
updateLine(i);
|
||||
|
||||
emit modified();
|
||||
}
|
||||
|
||||
@@ -435,7 +440,6 @@ void LogicalSwitchesPanel::updateLine(int i)
|
||||
cswitchDelay[i]->setValue(model->logicalSw[i].delay/10.0);
|
||||
}
|
||||
|
||||
rawSwitchItemModel->update();
|
||||
lock = false;
|
||||
}
|
||||
|
||||
@@ -508,7 +512,7 @@ void LogicalSwitchesPanel::populateAndSwitchCB(QComboBox *b)
|
||||
|
||||
void LogicalSwitchesPanel::update()
|
||||
{
|
||||
setDataModels();
|
||||
updateDataModels();
|
||||
for (int i=0; i<firmware->getCapability(LogicalSwitches); i++) {
|
||||
updateLine(i);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "radiodata.h"
|
||||
|
||||
class RawSwitchFilterItemModel;
|
||||
class RawSourceFilterItemModel;
|
||||
class TimerEdit;
|
||||
|
||||
class LogicalSwitchesPanel : public ModelPanel
|
||||
@@ -38,7 +39,7 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
virtual void update();
|
||||
|
||||
private slots:
|
||||
void setDataModels();
|
||||
void updateDataModels();
|
||||
void functionChanged();
|
||||
void v1Edited(int value);
|
||||
void v2Edited(int value);
|
||||
@@ -66,7 +67,7 @@ class LogicalSwitchesPanel : public ModelPanel
|
||||
QComboBox * cswitchSource1[CPN_MAX_LOGICAL_SWITCHES];
|
||||
QComboBox * cswitchSource2[CPN_MAX_LOGICAL_SWITCHES];
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
QStandardItemModel * rawSourceItemModel;
|
||||
RawSourceFilterItemModel * rawSourceItemModel;
|
||||
int selectedSwitch;
|
||||
|
||||
void populateCSWCB(QComboBox *b);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "mixerdialog.h"
|
||||
#include "ui_mixerdialog.h"
|
||||
#include "radiodata.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
#include "helpers.h"
|
||||
|
||||
MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata, GeneralSettings & generalSettings, Firmware * firmware) :
|
||||
@@ -43,7 +43,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata,
|
||||
|
||||
this->setWindowTitle(tr("DEST -> %1").arg(RawSource(SOURCE_TYPE_CH, md->destCh-1).toString(&model, &generalSettings)));
|
||||
|
||||
ui->sourceCB->setModel(Helpers::getRawSourceItemModel(&generalSettings, &model, POPULATE_NONE | POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS));
|
||||
ui->sourceCB->setModel(new RawSourceFilterItemModel(&generalSettings, &model, RawSource::InputSourceGroups | RawSource::ScriptsGroup, this));
|
||||
ui->sourceCB->setCurrentIndex(ui->sourceCB->findData(md->srcRaw.toValue()));
|
||||
ui->sourceCB->removeItem(0);
|
||||
|
||||
@@ -104,7 +104,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData * mixdata,
|
||||
}
|
||||
}
|
||||
|
||||
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, MixesContext));
|
||||
ui->switchesCB->setModel(new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::MixesContext, this));
|
||||
ui->switchesCB->setCurrentIndex(ui->switchesCB->findData(md->swtch.toValue()));
|
||||
ui->warningCB->setCurrentIndex(md->mixWarn);
|
||||
ui->mltpxCB->setCurrentIndex(md->mltpx);
|
||||
|
||||
@@ -22,13 +22,13 @@
|
||||
#include "ui_setup.h"
|
||||
#include "ui_setup_timer.h"
|
||||
#include "ui_setup_module.h"
|
||||
#include "switchitemmodel.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
#include "appdata.h"
|
||||
#include "modelprinter.h"
|
||||
#include "multiprotocols.h"
|
||||
#include "checklistdialog.h"
|
||||
|
||||
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus):
|
||||
TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget * prevFocus, RawSwitchFilterItemModel * switchModel):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
timer(timer),
|
||||
ui(new Ui::Timer)
|
||||
@@ -50,9 +50,9 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
|
||||
}
|
||||
|
||||
// Mode
|
||||
rawSwitchItemModel = new RawSwitchFilterItemModel(&generalSettings, &model, TimersContext);
|
||||
ui->mode->setModel(rawSwitchItemModel);
|
||||
ui->mode->setModel(switchModel);
|
||||
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||
connect(ui->mode, SIGNAL(activated(int)), this, SLOT(onModeChanged(int)));
|
||||
|
||||
if (!firmware->getCapability(PermTimers)) {
|
||||
ui->persistent->hide();
|
||||
@@ -92,12 +92,11 @@ TimerPanel::~TimerPanel()
|
||||
|
||||
void TimerPanel::update()
|
||||
{
|
||||
rawSwitchItemModel->update();
|
||||
|
||||
int hour = timer.val / 3600;
|
||||
int min = (timer.val - (hour * 3600)) / 60;
|
||||
int sec = (timer.val - (hour * 3600)) % 60;
|
||||
|
||||
ui->mode->setCurrentIndex(ui->mode->findData(timer.mode.toValue()));
|
||||
ui->value->setTime(QTime(hour, min, sec));
|
||||
|
||||
if (firmware->getCapability(PermTimers)) {
|
||||
@@ -131,10 +130,15 @@ void TimerPanel::on_value_editingFinished()
|
||||
}
|
||||
}
|
||||
|
||||
void TimerPanel::on_mode_currentIndexChanged(int index)
|
||||
void TimerPanel::onModeChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
timer.mode = RawSwitch(ui->mode->itemData(index).toInt());
|
||||
if (lock)
|
||||
return;
|
||||
|
||||
bool ok;
|
||||
const RawSwitch rs(ui->mode->itemData(index).toInt(&ok));
|
||||
if (ok && timer.mode.toValue() != rs.toValue()) {
|
||||
timer.mode = rs;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -937,11 +941,15 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
}
|
||||
|
||||
QWidget * prevFocus = ui->image;
|
||||
RawSwitchFilterItemModel * swModel = new RawSwitchFilterItemModel(&generalSettings, &model, RawSwitch::TimersContext, this);
|
||||
connect(this, &SetupPanel::updated, swModel, &RawSwitchFilterItemModel::update);
|
||||
|
||||
for (int i=0; i<CPN_MAX_TIMERS; i++) {
|
||||
if (i<firmware->getCapability(Timers)) {
|
||||
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus);
|
||||
timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus, swModel);
|
||||
ui->gridLayout->addWidget(timers[i], 1+i, 1);
|
||||
connect(timers[i], &TimerPanel::modified, this, &SetupPanel::modified);
|
||||
connect(this, &SetupPanel::updated, timers[i], &TimerPanel::update);
|
||||
prevFocus = timers[i]->getLastFocus();
|
||||
}
|
||||
else {
|
||||
@@ -1219,15 +1227,13 @@ void SetupPanel::update()
|
||||
updatePotWarnings();
|
||||
}
|
||||
|
||||
for (int i=0; i<firmware->getCapability(Timers); i++) {
|
||||
timers[i]->update();
|
||||
}
|
||||
|
||||
for (int i=0; i<CPN_MAX_MODULES+1; i++) {
|
||||
if (modules[i]) {
|
||||
modules[i]->update();
|
||||
}
|
||||
}
|
||||
|
||||
emit updated();
|
||||
}
|
||||
|
||||
void SetupPanel::updateBeepCenter()
|
||||
|
||||
@@ -37,14 +37,14 @@ class TimerPanel : public ModelPanel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget *prevFocus);
|
||||
TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, GeneralSettings & generalSettings, Firmware * firmware, QWidget *prevFocus, RawSwitchFilterItemModel * switchModel);
|
||||
virtual ~TimerPanel();
|
||||
|
||||
virtual void update();
|
||||
QWidget * getLastFocus();
|
||||
|
||||
private slots:
|
||||
void on_mode_currentIndexChanged(int index);
|
||||
void onModeChanged(int index);
|
||||
void on_value_editingFinished();
|
||||
void on_minuteBeep_toggled(bool checked);
|
||||
void on_name_editingFinished();
|
||||
@@ -52,7 +52,6 @@ class TimerPanel : public ModelPanel
|
||||
private:
|
||||
TimerData & timer;
|
||||
Ui::Timer * ui;
|
||||
RawSwitchFilterItemModel * rawSwitchItemModel;
|
||||
};
|
||||
|
||||
class ModulePanel : public ModelPanel
|
||||
@@ -126,6 +125,7 @@ class SetupPanel : public ModelPanel
|
||||
|
||||
signals:
|
||||
void extendedLimitsToggled();
|
||||
void updated();
|
||||
|
||||
private slots:
|
||||
void on_name_editingFinished();
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* 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 "switchitemmodel.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
RawSwitchItemModel::RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData):
|
||||
generalSettings(generalSettings),
|
||||
modelData(modelData)
|
||||
{
|
||||
Boards board = Boards(getCurrentBoard());
|
||||
Board::Type btype = board.getBoardType();
|
||||
Firmware * fw = getCurrentFirmware();
|
||||
|
||||
// Descending switch direction: NOT (!) switches
|
||||
if (IS_ARM(btype)) {
|
||||
add(SWITCH_TYPE_SENSOR, -CPN_MAX_SENSORS);
|
||||
add(SWITCH_TYPE_TELEMETRY, -1);
|
||||
add(SWITCH_TYPE_FLIGHT_MODE, -fw->getCapability(FlightModes));
|
||||
}
|
||||
add(SWITCH_TYPE_VIRTUAL, -fw->getCapability(LogicalSwitches));
|
||||
add(SWITCH_TYPE_ROTARY_ENCODER, -fw->getCapability(RotaryEncoders));
|
||||
add(SWITCH_TYPE_TRIM, -board.getCapability(Board::NumTrimSwitches));
|
||||
add(SWITCH_TYPE_MULTIPOS_POT, -(board.getCapability(Board::MultiposPots) * board.getCapability(Board::MultiposPotsPositions)));
|
||||
add(SWITCH_TYPE_SWITCH, -board.getCapability(Board::SwitchPositions));
|
||||
|
||||
// Ascending switch direction (including zero)
|
||||
add(SWITCH_TYPE_TIMER_MODE, 5);
|
||||
add(SWITCH_TYPE_NONE, 1);
|
||||
add(SWITCH_TYPE_SWITCH, board.getCapability(Board::SwitchPositions));
|
||||
add(SWITCH_TYPE_MULTIPOS_POT, board.getCapability(Board::MultiposPots) * board.getCapability(Board::MultiposPotsPositions));
|
||||
add(SWITCH_TYPE_TRIM, board.getCapability(Board::NumTrimSwitches));
|
||||
add(SWITCH_TYPE_ROTARY_ENCODER, fw->getCapability(RotaryEncoders));
|
||||
add(SWITCH_TYPE_VIRTUAL, fw->getCapability(LogicalSwitches));
|
||||
if (IS_ARM(btype)) {
|
||||
add(SWITCH_TYPE_FLIGHT_MODE, fw->getCapability(FlightModes));
|
||||
add(SWITCH_TYPE_TELEMETRY, 1);
|
||||
add(SWITCH_TYPE_SENSOR, CPN_MAX_SENSORS);
|
||||
}
|
||||
add(SWITCH_TYPE_ON, 1);
|
||||
add(SWITCH_TYPE_ONE, 1);
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::add(const RawSwitchType & type, int count)
|
||||
{
|
||||
// Most RawSwitch() indices are one-based (vs. typical zero); these are exceptions to the rule:
|
||||
const static QVector<int> rawSwitchIndexBaseZeroTypes = QVector<int>() << SWITCH_TYPE_NONE << SWITCH_TYPE_ON << SWITCH_TYPE_OFF << SWITCH_TYPE_TIMER_MODE;
|
||||
|
||||
int rawIdxAdj = 0;
|
||||
const Board::Type board = getCurrentBoard();
|
||||
int i = (count < 0 ? count : 1);
|
||||
const int maxCount = (i < 0 ? 0 : count + i);
|
||||
|
||||
// handle exceptions in RawSwitch() index values
|
||||
if (rawSwitchIndexBaseZeroTypes.contains(type))
|
||||
rawIdxAdj = -1;
|
||||
|
||||
for ( ; i < maxCount; ++i) {
|
||||
RawSwitch rs(type, i + rawIdxAdj);
|
||||
QStandardItem * modelItem = new QStandardItem(rs.toString(board, generalSettings, modelData));
|
||||
modelItem->setData(rs.toValue(), Qt::UserRole);
|
||||
appendRow(modelItem);
|
||||
}
|
||||
}
|
||||
|
||||
void RawSwitchItemModel::update()
|
||||
{
|
||||
for (int i=0; i<rowCount(); i++) {
|
||||
QStandardItem * modelItem = item(i, 0);
|
||||
RawSwitch swtch(modelItem->data(Qt::UserRole).toInt());
|
||||
modelItem->setText(swtch.toString(getCurrentBoard(), generalSettings, modelData));
|
||||
}
|
||||
}
|
||||
|
||||
RawSwitchFilterItemModel::RawSwitchFilterItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData, SwitchContext context):
|
||||
generalSettings(generalSettings),
|
||||
modelData(modelData),
|
||||
context(context),
|
||||
parent(new RawSwitchItemModel(generalSettings, modelData))
|
||||
{
|
||||
setSourceModel(parent);
|
||||
setDynamicSortFilter(false);
|
||||
}
|
||||
|
||||
bool RawSwitchFilterItemModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
|
||||
{
|
||||
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
RawSwitch swtch(sourceModel()->data(index, Qt::UserRole).toInt());
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_FLIGHT_MODE && (context == MixesContext || context == GlobalFunctionsContext))
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_VIRTUAL && context == GlobalFunctionsContext)
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_TIMER_MODE && context != TimersContext)
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_NONE && context == TimersContext)
|
||||
return false;
|
||||
|
||||
if (swtch.type == SWITCH_TYPE_SENSOR && context == GlobalFunctionsContext)
|
||||
return false;
|
||||
|
||||
if ((swtch.type == SWITCH_TYPE_ON || swtch.type == SWITCH_TYPE_ONE) && (context != SpecialFunctionsContext && context != GlobalFunctionsContext))
|
||||
return false;
|
||||
|
||||
if (!swtch.isAvailable(modelData, generalSettings, getCurrentBoard()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RawSwitchFilterItemModel::update()
|
||||
{
|
||||
parent->update();
|
||||
invalidate();
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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 <QStandardItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "radiodata.h"
|
||||
|
||||
enum SwitchContext
|
||||
{
|
||||
LogicalSwitchesContext,
|
||||
SpecialFunctionsContext,
|
||||
GlobalFunctionsContext,
|
||||
TimersContext,
|
||||
MixesContext
|
||||
};
|
||||
|
||||
class RawSwitchItemModel: public QStandardItemModel {
|
||||
public:
|
||||
RawSwitchItemModel(const GeneralSettings * const generalSettings, const ModelData * const modelData);
|
||||
void update();
|
||||
|
||||
protected:
|
||||
void add(const RawSwitchType & type, int count);
|
||||
|
||||
const GeneralSettings * generalSettings;
|
||||
const ModelData * modelData;
|
||||
};
|
||||
|
||||
class RawSwitchFilterItemModel: public QSortFilterProxyModel {
|
||||
public:
|
||||
RawSwitchFilterItemModel(const GeneralSettings * const generalSettings = NULL, const ModelData * const modelData = NULL, SwitchContext context = LogicalSwitchesContext);
|
||||
void update();
|
||||
|
||||
protected:
|
||||
const GeneralSettings * generalSettings;
|
||||
const ModelData * modelData;
|
||||
SwitchContext context;
|
||||
RawSwitchItemModel * parent;
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const override;
|
||||
};
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "ui_telemetry_sensor.h"
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
#include "rawitemfilteredmodel.h"
|
||||
|
||||
#include <TimerEdit>
|
||||
|
||||
@@ -316,7 +317,7 @@ TelemetryAnalog::~TelemetryAnalog()
|
||||
|
||||
/******************************************************/
|
||||
|
||||
TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware, RawSourceFilterItemModel * srcModel):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::TelemetryCustomScreen),
|
||||
screen(screen)
|
||||
@@ -327,15 +328,17 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
|
||||
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
|
||||
fieldsCB[l][c] = new QComboBox(this);
|
||||
fieldsCB[l][c]->setProperty("index", c + (l<<8));
|
||||
fieldsCB[l][c]->setModel(srcModel);
|
||||
ui->screenNumsLayout->addWidget(fieldsCB[l][c], l, c, 1, 1);
|
||||
connect(fieldsCB[l][c], SIGNAL(currentIndexChanged(int)), this, SLOT(customFieldChanged(int)));
|
||||
connect(fieldsCB[l][c], SIGNAL(activated(int)), this, SLOT(customFieldChanged(int)));
|
||||
}
|
||||
}
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
barsCB[l] = new QComboBox(this);
|
||||
barsCB[l]->setProperty("index", l);
|
||||
connect(barsCB[l], SIGNAL(currentIndexChanged(int)), this, SLOT(barSourceChanged(int)));
|
||||
barsCB[l]->setModel(srcModel);
|
||||
connect(barsCB[l], SIGNAL(activated(int)), this, SLOT(barSourceChanged(int)));
|
||||
ui->screenBarsLayout->addWidget(barsCB[l], l, 0, 1, 1);
|
||||
|
||||
minSB[l] = new QDoubleSpinBox(this);
|
||||
@@ -393,19 +396,6 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
|
||||
update();
|
||||
}
|
||||
|
||||
void TelemetryCustomScreen::populateTelemetrySourceCB(QComboBox * b, RawSource & source, bool last)
|
||||
{
|
||||
int flags = POPULATE_NONE | POPULATE_TELEMETRY;
|
||||
if (IS_ARM(firmware->getBoard())) {
|
||||
flags |= POPULATE_SOURCES | POPULATE_SCRIPT_OUTPUTS | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | (firmware->getCapability(GvarsInCS) ? POPULATE_GVARS : 0);
|
||||
}
|
||||
else if (last) {
|
||||
flags |= POPULATE_TELEMETRYEXT;
|
||||
}
|
||||
b->setModel(Helpers::getRawSourceItemModel(&generalSettings, model, flags));
|
||||
b->setCurrentIndex(b->findData(source.toValue()));
|
||||
}
|
||||
|
||||
TelemetryCustomScreen::~TelemetryCustomScreen()
|
||||
{
|
||||
delete ui;
|
||||
@@ -421,12 +411,12 @@ void TelemetryCustomScreen::update()
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
for (int c=0; c<firmware->getCapability(TelemetryCustomScreensFieldsPerLine); c++) {
|
||||
populateTelemetrySourceCB(fieldsCB[l][c], screen.body.lines[l].source[c], l==3);
|
||||
fieldsCB[l][c]->setCurrentIndex(fieldsCB[l][c]->findData(screen.body.lines[l].source[c].toValue()));
|
||||
}
|
||||
}
|
||||
|
||||
for (int l=0; l<4; l++) {
|
||||
populateTelemetrySourceCB(barsCB[l], screen.body.bars[l].source);
|
||||
barsCB[l]->setCurrentIndex(barsCB[l]->findData(screen.body.bars[l].source.toValue()));
|
||||
}
|
||||
|
||||
if (screen.type == TELEMETRY_SCREEN_BARS) {
|
||||
@@ -526,24 +516,36 @@ void TelemetryCustomScreen::scriptNameEdited()
|
||||
|
||||
void TelemetryCustomScreen::customFieldChanged(int value)
|
||||
{
|
||||
if (!lock) {
|
||||
int index = sender()->property("index").toInt();
|
||||
screen.body.lines[index/256].source[index%256] = RawSource(((QComboBox *)sender())->itemData(value).toInt());
|
||||
if (lock || !sender() || !qobject_cast<QComboBox *>(sender()))
|
||||
return;
|
||||
|
||||
bool ok;
|
||||
const int index = sender()->property("index").toInt(&ok),
|
||||
i = index / 256,
|
||||
m = index % 256;
|
||||
const RawSource src(qobject_cast<QComboBox *>(sender())->itemData(value).toInt());
|
||||
if (ok && screen.body.lines[i].source[m].toValue() != src.toValue()) {
|
||||
screen.body.lines[i].source[m] = src;
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetryCustomScreen::barSourceChanged(int value)
|
||||
{
|
||||
if (!lock) {
|
||||
QComboBox * cb = qobject_cast<QComboBox*>(sender());
|
||||
int index = cb->property("index").toInt();
|
||||
screen.body.bars[index].source = RawSource(((QComboBox *)sender())->itemData(value).toInt());
|
||||
screen.body.bars[index].barMin = 0;
|
||||
screen.body.bars[index].barMax = 0;
|
||||
updateBar(index);
|
||||
emit modified();
|
||||
}
|
||||
if (lock || !sender() || !qobject_cast<QComboBox *>(sender()))
|
||||
return;
|
||||
|
||||
bool ok;
|
||||
const int index = sender()->property("index").toInt(&ok);
|
||||
const RawSource src(qobject_cast<QComboBox *>(sender())->itemData(value).toInt());
|
||||
if (!ok || screen.body.bars[index].source.toValue() == src.toValue())
|
||||
return;
|
||||
|
||||
screen.body.bars[index].source = src;
|
||||
screen.body.bars[index].barMin = 0;
|
||||
screen.body.bars[index].barMax = 0;
|
||||
updateBar(index);
|
||||
emit modified();
|
||||
}
|
||||
|
||||
void TelemetryCustomScreen::barMinChanged(double value)
|
||||
@@ -854,11 +856,15 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
|
||||
ui->topbarGB->hide();
|
||||
}
|
||||
|
||||
RawSourceFilterItemModel * srcModel = (new RawSourceFilterItemModel(&generalSettings, &model, this));
|
||||
connect(this, &TelemetryPanel::updated, srcModel, &RawSourceFilterItemModel::update);
|
||||
|
||||
for (int i=0; i<firmware->getCapability(TelemetryCustomScreens); i++) {
|
||||
TelemetryCustomScreen * tab = new TelemetryCustomScreen(this, model, model.frsky.screens[i], generalSettings, firmware);
|
||||
TelemetryCustomScreen * tab = new TelemetryCustomScreen(this, model, model.frsky.screens[i], generalSettings, firmware, srcModel);
|
||||
ui->customScreens->addTab(tab, tr("Telemetry screen %1").arg(i+1));
|
||||
telemetryCustomScreens[i] = tab;
|
||||
connect(tab, SIGNAL(modified()), this, SLOT(onModified()));
|
||||
connect(tab, &TelemetryCustomScreen::modified, this, &TelemetryPanel::onModified);
|
||||
connect(this, &TelemetryPanel::updated, tab, &TelemetryCustomScreen::update);
|
||||
}
|
||||
|
||||
disableMouseScrolling();
|
||||
@@ -891,10 +897,9 @@ void TelemetryPanel::update()
|
||||
for (int i=0; i<CPN_MAX_SENSORS; ++i) {
|
||||
sensorPanels[i]->update();
|
||||
}
|
||||
for (int i=0; i<firmware->getCapability(TelemetryCustomScreens); i++) {
|
||||
telemetryCustomScreens[i]->update();
|
||||
}
|
||||
}
|
||||
|
||||
emit updated();
|
||||
}
|
||||
|
||||
void TelemetryPanel::setup()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "eeprominterface.h"
|
||||
|
||||
class AutoComboBox;
|
||||
class RawSourceFilterItemModel;
|
||||
class TimerEdit;
|
||||
|
||||
namespace Ui {
|
||||
@@ -72,7 +73,7 @@ class TelemetryCustomScreen: public ModelPanel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
TelemetryCustomScreen(QWidget *parent, ModelData & model, FrSkyScreenData & screen, GeneralSettings & generalSettings, Firmware * firmware, RawSourceFilterItemModel * srcModel);
|
||||
~TelemetryCustomScreen();
|
||||
void update();
|
||||
|
||||
@@ -85,9 +86,6 @@ class TelemetryCustomScreen: public ModelPanel
|
||||
void barMaxChanged(double value);
|
||||
void barTimeChanged();
|
||||
|
||||
protected:
|
||||
void populateTelemetrySourceCB(QComboBox * b, RawSource & source, bool last=false);
|
||||
|
||||
private:
|
||||
void updateBar(int line);
|
||||
Ui::TelemetryCustomScreen * ui;
|
||||
@@ -137,6 +135,9 @@ class TelemetryPanel : public ModelPanel
|
||||
virtual ~TelemetryPanel();
|
||||
virtual void update();
|
||||
|
||||
signals:
|
||||
void updated();
|
||||
|
||||
private slots:
|
||||
void on_telemetryProtocol_currentIndexChanged(int index);
|
||||
void onModified();
|
||||
|
||||
Reference in New Issue
Block a user