[Companion][MixesPanel] Fix disappearing mixer lines after an invalid line is removed. (#5957)

This commit is contained in:
Max Paperno
2018-06-13 22:27:45 +02:00
committed by Bertrand Songis
parent cd7c075b3b
commit 1de4d86661
2 changed files with 30 additions and 51 deletions
+28 -49
View File
@@ -64,31 +64,22 @@ MixesPanel::~MixesPanel()
void MixesPanel::update() void MixesPanel::update()
{ {
lock = true;
mixersListWidget->clear(); mixersListWidget->clear();
for (int i=0; i < firmware->getCapability(Outputs); ++i) {
unsigned int curDest = 0; bool filled = false;
unsigned int outputs = firmware->getCapability(Outputs); for (int j=0; j < firmware->getCapability(Mixes); ++j) {
const MixData & mix = model->mixData[j];
for (int i=0; i<firmware->getCapability(Mixes); i++) { if ((int)mix.destCh == i+1) {
MixData & mix = model->mixData[i]; AddMixerLine(j);
if (mix.destCh == 0 || mix.destCh > outputs) { filled = true;
// we reached the end of the mixes list }
break;
} }
QString str = ""; if (!filled) {
while (curDest < mix.destCh-1) { AddMixerLine(-i-1);
curDest++;
AddMixerLine(-int(curDest));
}
if (AddMixerLine(i)) {
curDest++;
} }
} }
lock = false;
while (curDest < outputs) {
curDest++;
AddMixerLine(-int(curDest));
}
} }
/** /**
@@ -97,30 +88,27 @@ void MixesPanel::update()
@note Mixer lines are now HTML formated in order to support bold text. @note Mixer lines are now HTML formated in order to support bold text.
@param[in] dest defines which mixer line to create. @param[in] dest defines which mixer line to create.
If dest < 0 then create empty channel slotr fo channel -dest ( dest=-2 -> CH2) If dest < 0 then create empty channel slot fo channel -dest ( dest=-2 -> CH2)
if dest >=0 then create used channel based on model mix data from slot dest (dest=4 -> model mix[4]) if dest >=0 then create used channel based on model mix data from slot dest (dest=4 -> model mix[4])
@retval true destination channel is different from the previous list item
false destination channle is the same as previous list item
*/ */
bool MixesPanel::AddMixerLine(int dest) void MixesPanel::AddMixerLine(int dest)
{ {
bool new_ch;
QString str = getMixerText(dest, &new_ch);
QListWidgetItem *itm = new QListWidgetItem(str);
QByteArray qba(1, (quint8)dest); QByteArray qba(1, (quint8)dest);
unsigned destId = abs(dest); unsigned destId = abs(dest);
bool newChan = false;
bool hasSibs = false; bool hasSibs = false;
if (dest >= 0) { if (dest >= 0) {
//add mix data //add mix data
MixData * md = &model->mixData[dest]; const MixData & md = model->mixData[dest];
qba.append((const char*)md, sizeof(MixData)); qba.append((const char*)&md, sizeof(MixData));
destId = md->destCh; destId = md.destCh;
hasSibs = (dest < CPN_MAX_MIXERS && model->mixData[dest+1].destCh == md->destCh); const QVector<const MixData *> mixes = model->mixes(md.destCh-1);
newChan = (mixes.constFirst() == &md);
hasSibs = (mixes.constLast() != &md);
} }
QListWidgetItem *itm = new QListWidgetItem(getMixerText(dest, newChan));
itm->setData(Qt::UserRole, qba); itm->setData(Qt::UserRole, qba);
mixersListWidget->addItem(itm, destId, new_ch, hasSibs); mixersListWidget->addItem(itm, destId, newChan, hasSibs);
return new_ch;
} }
/** /**
@@ -132,37 +120,28 @@ bool MixesPanel::AddMixerLine(int dest)
@retval string mixer line in HTML @retval string mixer line in HTML
*/ */
QString MixesPanel::getMixerText(int dest, bool * new_ch) QString MixesPanel::getMixerText(int dest, bool newChannel)
{ {
QString str; QString str;
bool newChannel = false;
if (dest < 0) { if (dest < 0) {
dest = abs(dest); dest = abs(dest);
str = modelPrinter.printChannelName(dest-1); str = modelPrinter.printChannelName(dest-1);
//highlight channel if needed //highlight channel if needed
if (dest == (int)highlightedSource) if (dest == (int)highlightedSource)
str = "<b>" + str + "</b>"; str = "<b>" + str + "</b>";
newChannel = true;
} }
else { else {
MixData & mix = model->mixData[dest]; const MixData & mix = model->mixData[dest];
//mix->destCh from 1 to 32 //mix->destCh from 1 to 32
str = modelPrinter.printChannelName(mix.destCh-1); str = modelPrinter.printChannelName(mix.destCh-1);
if ((dest == 0) || (model->mixData[dest-1].destCh != mix.destCh)) { if (!newChannel)
newChannel = true;
//highlight channel if needed
if (mix.destCh == highlightedSource)
str = "<b>" + str + "</b>";
}
else {
str.fill(' '); str.fill(' ');
} else if (mix.destCh == highlightedSource)
str = "<b>" + str + "</b>";
str += modelPrinter.printMixerLine(mix, !newChannel, highlightedSource); str += modelPrinter.printMixerLine(mix, !newChannel, highlightedSource);
} }
if (new_ch)
*new_ch = newChannel;
return str.replace(" ", "&nbsp;"); return str.replace(" ", "&nbsp;");
} }
+2 -2
View File
@@ -72,8 +72,8 @@ class MixesPanel : public ModelPanel
void mixersDeleteList(QList<int> list); void mixersDeleteList(QList<int> list);
QList<int> createMixListFromSelected(); QList<int> createMixListFromSelected();
void setSelectedByMixList(QList<int> list); void setSelectedByMixList(QList<int> list);
bool AddMixerLine(int dest); void AddMixerLine(int dest);
QString getMixerText(int dest, bool * new_ch); QString getMixerText(int dest, bool newChannel);
}; };
#endif // _MIXES_H_ #endif // _MIXES_H_