Skip to content

Commit

Permalink
qmlui: handle channel capability conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jun 27, 2021
1 parent 0d33ce3 commit c9ea58f
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 68 deletions.
28 changes: 28 additions & 0 deletions engine/src/qlccapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ QLCCapability::QLCCapability(uchar min, uchar max, const QString& name, QObject
, m_min(min)
, m_max(max)
, m_name(name)
, m_warning(NoWarning)
{
}

QLCCapability *QLCCapability::createCopy()
{
QLCCapability *copy = new QLCCapability(m_min, m_max, m_name);
copy->setWarning(m_warning);
copy->setPreset(preset());
for (int i = 0; i < m_resources.count(); i++)
copy->setResource(i, m_resources.at(i));
Expand Down Expand Up @@ -159,7 +161,11 @@ uchar QLCCapability::min() const

void QLCCapability::setMin(uchar value)
{
if (m_min == value)
return;

m_min = value;
emit minChanged();
}

uchar QLCCapability::max() const
Expand All @@ -169,7 +175,11 @@ uchar QLCCapability::max() const

void QLCCapability::setMax(uchar value)
{
if (m_max == value)
return;

m_max = value;
emit maxChanged();
}

uchar QLCCapability::middle() const
Expand All @@ -184,7 +194,25 @@ QString QLCCapability::name() const

void QLCCapability::setName(const QString& name)
{
if (m_name == name)
return;

m_name = name;
emit nameChanged();
}

QLCCapability::WarningType QLCCapability::warning() const
{
return m_warning;
}

void QLCCapability::setWarning(QLCCapability::WarningType type)
{
if (m_warning == type)
return;

m_warning = type;
emit warningChanged();
}

QVariant QLCCapability::resource(int index)
Expand Down
31 changes: 28 additions & 3 deletions engine/src/qlccapability.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ class QLCCapability: public QObject
{
Q_OBJECT

Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(int min READ min CONSTANT)
Q_PROPERTY(int max READ max CONSTANT)
Q_PROPERTY(int min READ min WRITE setMin NOTIFY minChanged)
Q_PROPERTY(int max READ max WRITE setMax NOTIFY maxChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(WarningType warning READ warning WRITE setWarning NOTIFY warningChanged)
Q_PROPERTY(QVariantList resources READ resources CONSTANT)

/********************************************************************
Expand Down Expand Up @@ -216,6 +217,19 @@ class QLCCapability: public QObject
* Properties
********************************************************************/
public:
enum WarningType
{
NoWarning,
EmptyName,
Overlapping
};

#if QT_VERSION >= 0x050500
Q_ENUM(WarningType)
#else
Q_ENUMS(WarningType)
#endif

/** Get/Set the capability range minimum value */
uchar min() const;
void setMin(uchar value);
Expand All @@ -231,6 +245,10 @@ class QLCCapability: public QObject
QString name() const;
void setName(const QString& name);

/** Get/Set a warning for this capability */
WarningType warning() const;
void setWarning(WarningType type);

/** Get the resource at the provided index.
* Returns an empty QVariant on failure */
QVariant resource(int index);
Expand All @@ -244,10 +262,17 @@ class QLCCapability: public QObject
/** Check, whether the given capability overlaps with this */
bool overlaps(const QLCCapability* cap);

signals:
void minChanged();
void maxChanged();
void nameChanged();
void warningChanged();

protected:
uchar m_min;
uchar m_max;
QString m_name;
WarningType m_warning;
QVariantList m_resources;

/********************************************************************
Expand Down
5 changes: 5 additions & 0 deletions engine/src/qlcchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,12 @@ QLCChannel::PrimaryColour QLCChannel::stringToColour(const QString& str)

void QLCChannel::setColour(QLCChannel::PrimaryColour colour)
{
if (colour == m_colour)
return;

m_colour = colour;

emit colourChanged();
}

QLCChannel::PrimaryColour QLCChannel::colour() const
Expand Down
4 changes: 4 additions & 0 deletions engine/src/qlcchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class QLCChannel : public QObject
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(uchar defaultValue READ defaultValue WRITE setDefaultValue NOTIFY defaultValueChanged)
Q_PROPERTY(ControlByte controlByte READ controlByte WRITE setControlByte NOTIFY controlByteChanged)
Q_PROPERTY(PrimaryColour colour READ colour WRITE setColour NOTIFY colourChanged)

public:
/** Standard constructor */
Expand Down Expand Up @@ -334,6 +335,9 @@ class QLCChannel : public QObject
/** Get the colour that is controlled by this channel */
PrimaryColour colour() const;

signals:
void colourChanged();

private:
PrimaryColour m_colour;

Expand Down
149 changes: 105 additions & 44 deletions qmlui/fixtureeditor/channeledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,27 @@ ChannelEdit::ChannelEdit(QLCChannel *channel, QObject *parent)
: QObject(parent)
, m_channel(channel)
{
if (m_channel->capabilities().count() == 0)
{
QLCCapability *cap = new QLCCapability(0, UCHAR_MAX);
cap->setWarning(QLCCapability::EmptyName);
m_channel->addCapability(cap);
}

connect(m_channel, SIGNAL(presetChanged()), this, SIGNAL(channelChanged()));
connect(m_channel, SIGNAL(groupChanged()), this, SIGNAL(channelChanged()));
connect(m_channel, SIGNAL(nameChanged()), this, SIGNAL(channelChanged()));
connect(m_channel, SIGNAL(defaultValueChanged()), this, SIGNAL(channelChanged()));
connect(m_channel, SIGNAL(controlByteChanged()), this, SIGNAL(channelChanged()));

updateCapabilities();
}

ChannelEdit::~ChannelEdit()
{

disconnect(m_channel, SIGNAL(presetChanged()), this, SIGNAL(channelChanged()));
disconnect(m_channel, SIGNAL(nameChanged()), this, SIGNAL(channelChanged()));
disconnect(m_channel, SIGNAL(defaultValueChanged()), this, SIGNAL(channelChanged()));
disconnect(m_channel, SIGNAL(controlByteChanged()), this, SIGNAL(channelChanged()));
}

QLCChannel *ChannelEdit::channel()
Expand Down Expand Up @@ -91,11 +102,38 @@ QVariantList ChannelEdit::capabilityPresetList() const
return list;
}

int ChannelEdit::group() const
{
QLCChannel::Group grp = m_channel->group();

if (grp == QLCChannel::Intensity)
return int(m_channel->colour());
else
return int(grp);
}

void ChannelEdit::setGroup(int group)
{
if (group > QLCChannel::Nothing && group < QLCChannel::NoGroup)
{
m_channel->setColour(QLCChannel::PrimaryColour(group));
m_channel->setGroup(QLCChannel::Intensity);
}
else
{
m_channel->setColour(QLCChannel::NoColour);
m_channel->setGroup(QLCChannel::Group(group));
}

emit groupChanged();
emit channelChanged();
}

QVariantList ChannelEdit::channelTypeList() const
{
QVariantList list;

for (QString grp : QLCChannel::groupList())
for (QString &grp : QLCChannel::groupList())
{
QLCChannel ch;
ch.setGroup(QLCChannel::stringToGroup(grp));
Expand All @@ -108,7 +146,7 @@ QVariantList ChannelEdit::channelTypeList() const

if (ch.group() == QLCChannel::Intensity)
{
for (QString color : QLCChannel::colourList())
for (QString &color : QLCChannel::colourList())
{
QLCChannel cc;
cc.setGroup(QLCChannel::Intensity);
Expand All @@ -126,79 +164,102 @@ QVariantList ChannelEdit::channelTypeList() const
return list;
}

QVariantList ChannelEdit::capabilities() const
void ChannelEdit::updateCapabilities()
{
QVariantList list;
m_capabilities.clear();

for (QLCCapability *cap : m_channel->capabilities())
{
QVariantMap capMap;
capMap.insert("iMin", cap->min());
capMap.insert("iMax", cap->max());
capMap.insert("sDesc", cap->name());
list.append(capMap);
capMap.insert("cRef", QVariant::fromValue(cap));
m_capabilities.append(capMap);
}

return list;
emit capabilitiesChanged();
}

int ChannelEdit::getCapabilityPresetAtIndex(int index)
QVariantList ChannelEdit::capabilities() const
{
int i = 0;
return m_capabilities;
}

for (QLCCapability *cap : m_channel->capabilities())
QLCCapability *ChannelEdit::addCapability()
{
int min = 0;
if (m_channel->capabilities().count())
{
if (i == index)
return cap->preset();

i++;
QLCCapability *last = m_channel->capabilities().last();
min = last->max() + 1;
}
QLCCapability *cap = new QLCCapability(min, UCHAR_MAX);
cap->setWarning(QLCCapability::EmptyName);
if (m_channel->addCapability(cap))
updateCapabilities();

return 0;
return cap;
}

int ChannelEdit::getCapabilityPresetType(int index)
int ChannelEdit::getCapabilityPresetAtIndex(int index)
{
int i = 0;
QList<QLCCapability *> caps = m_channel->capabilities();

for (QLCCapability *cap : m_channel->capabilities())
{
if (i == index)
return cap->presetType();
if (index < 0 || index >= caps.count())
return 0;

i++;
}
return caps.at(index)->preset();
}

return QLCCapability::None;
int ChannelEdit::getCapabilityPresetType(int index)
{
QList<QLCCapability *> caps = m_channel->capabilities();

if (index < 0 || index >= caps.count())
return QLCCapability::None;

return caps.at(index)->presetType();
}

QString ChannelEdit::getCapabilityPresetUnits(int index)
{
int i = 0;
QList<QLCCapability *> caps = m_channel->capabilities();

for (QLCCapability *cap : m_channel->capabilities())
{
if (i == index)
return cap->presetUnits();
if (index < 0 || index >= caps.count())
return QString();

i++;
}

return QString();
return caps.at(index)->presetUnits();
}

QVariant ChannelEdit::getCapabilityValueAt(int index, int vIndex)
{
int i = 0;
QList<QLCCapability *> caps = m_channel->capabilities();

for (QLCCapability *cap : m_channel->capabilities())
if (index < 0 || index >= caps.count())
return QVariant();

return caps.at(index)->resource(vIndex);
}

void ChannelEdit::checkCapabilities()
{
QVector<bool>allocation;
allocation.fill(false, 256);

QListIterator <QLCCapability*> it(m_channel->capabilities());
while (it.hasNext() == true)
{
if (i == index)
return cap->resource(vIndex);
QLCCapability *cap = it.next();
cap->setWarning(QLCCapability::NoWarning);
if (cap->name().isEmpty())
cap->setWarning(QLCCapability::EmptyName);

i++;
for (int i = cap->min(); i <= cap->max(); i++)
{
if (allocation[i] == true)
cap->setWarning(QLCCapability::Overlapping);
else
allocation[i] = true;
}
}

return QVariant();
}


0 comments on commit c9ea58f

Please sign in to comment.