diff --git a/src/channelinfomodel.cpp b/src/channelinfomodel.cpp --- a/src/channelinfomodel.cpp +++ b/src/channelinfomodel.cpp @@ -66,7 +66,7 @@ Qt::ItemFlags ChannelInfoModel::flags(co QVariant ChannelInfoModel::data(const QModelIndex &index, int role) const { // check index - if (index.row() >= (int) _numOfChannels) + if (index.row() >= (int) _numOfChannels || index.row() < 0) { return QVariant(); } @@ -127,7 +127,7 @@ QVariant ChannelInfoModel::headerData(in bool ChannelInfoModel::setData(const QModelIndex &index, const QVariant &value, int role) { // check index - if (index.row() >= (int) _numOfChannels) + if (index.row() >= (int) _numOfChannels || index.row() < 0) { return false; } @@ -245,18 +245,20 @@ void ChannelInfoModel::loadSettings(QSet chanInfo.color = settings->value(SG_Channels_Color, colors[ci % 8]).value(); chanInfo.visibility = settings->value(SG_Channels_Visible, true).toBool(); - if ((int) ci >= infos.size()) + if ((int) ci < infos.size()) { - infos.append(chanInfo); + infos[ci] = chanInfo; + + if (ci < _numOfChannels) + { + auto roles = QVector({ + Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole, Qt::CheckStateRole}); + emit dataChanged(index(ci, 0), index(ci, COLUMN_COUNT-1), roles); + } } else { - infos[ci] = chanInfo; - - auto roles = QVector({ - Qt::DisplayRole, Qt::EditRole, Qt::ForegroundRole, Qt::CheckStateRole}); - - emit dataChanged(index(ci, 0), index(ci, COLUMN_COUNT-1), roles); + infos.append(chanInfo); } }