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
 
@@ -125,47 +125,66 @@ bool ChannelInfoModel::setData(const QMo
 
        if (role == Qt::DisplayRole || role == Qt::EditRole)
 
        {
 
            infos[index.row()].name = value.toString();
 
            return true;
 
        }
 
    }
 
    else if (index.column() == COLUMN_VISIBILITY)
 
    {
 
        if (role == Qt::CheckStateRole)
 
        {
 
            bool checked = value.toInt() == Qt::Checked;
 
            infos[index.row()].visibility = checked;
 
            return true;
 
        }
 
    }
 

	
 
    // invalid index/role
 
    return false;
 
}
 

	
 
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++)
 
        {
 
            infos.append({QString("Channel %1").arg(ci), true});
 
        }
 
    }
 

	
 
    // make sure newly available channels are visible, we don't
 
    // remember visibility option intentionally so that user doesn't
 
    // get confused
 
    if (number > _numOfChannels)
 
    {
 
        for (unsigned ci = _numOfChannels; ci < number; ci++)
 
        {
 
            infos[ci].visibility = true;
 
        }
 
    }
 

	
 
    _numOfChannels = number;
 

	
 
    if (isInserting)
 
    {
 
        endInsertRows();
 
    }
 
    else
 
    {
 
        endRemoveRows();
 
    }
 
}
src/main.cpp
Show inline comments
 
@@ -34,33 +34,37 @@ void messageHandler(QtMsgType type, cons
 
                    const QString &msg)
 
{
 
    // TODO: don't call MainWindow::messageHandler if window is destroyed
 
    pMainWindow->messageHandler(type, context, msg);
 
}
 

	
 
int main(int argc, char *argv[])
 
{
 
    QApplication a(argc, argv);
 
    MainWindow w;
 
    pMainWindow = &w;
 

	
 
    qInstallMessageHandler(messageHandler);
 

	
 
    ToolTipFilter ttf;
 
    a.installEventFilter(&ttf);
 

	
 
    // log application information
 
    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)