Changeset - 07e03880baff
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-12-31 15:23:36
hy@ozderya.net
call begin/end functions so that view is updated about changes in model
2 files changed with 24 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/channelinfomodel.cpp
Show inline comments
 
@@ -143,12 +143,22 @@ bool ChannelInfoModel::setData(const QMo
 
}
 

	
 
void ChannelInfoModel::setNumOfChannels(unsigned number)
 
{
 
    if (number == _numOfChannels) return;
 

	
 
    bool isInserting = number > _numOfChannels;
 
    if (isInserting)
 
    {
 
        beginInsertRows(QModelIndex(), _numOfChannels, number-1);
 
    }
 
    else
 
    {
 
        beginRemoveRows(QModelIndex(), number, _numOfChannels-1);
 
    }
 

	
 
    // we create channel info but never remove channel info to
 
    // remember user entered info
 
    if ((int) number > infos.length())
 
    {
 
        for (unsigned ci = _numOfChannels; ci < number; ci++)
 
        {
 
@@ -165,7 +175,16 @@ void ChannelInfoModel::setNumOfChannels(
 
        {
 
            infos[ci].visibility = true;
 
        }
 
    }
 

	
 
    _numOfChannels = number;
 

	
 
    if (isInserting)
 
    {
 
        endInsertRows();
 
}
 
    else
 
    {
 
        endRemoveRows();
 
    }
 
}
src/main.cpp
Show inline comments
 
@@ -52,15 +52,19 @@ int main(int argc, char *argv[])
 
    qDebug() << "SerialPlot" << VERSION_STRING;
 
    qDebug() << "Revision" << VERSION_REVISION;
 

	
 
    w.show();
 

	
 
    // test code
 
    ChannelInfoModel cim(5, &a);
 
    ChannelInfoModel cim(10, &a);
 
    QTableView tv;
 

	
 
    tv.setModel(&cim);
 

	
 
    tv.show();
 

	
 
    // cim.setNumOfChannels(3);
 
    // cim.setNumOfChannels(10);
 
    // cim.setNumOfChannels(7);
 

	
 
    return a.exec();
 
}
0 comments (0 inline, 0 general)