[Qt-interest] Widget to use on Model/View

João Mesquita jmesquita at gmail.com
Wed Aug 26 09:30:01 CEST 2009


Guys, I have not yet being able to get to what I want here with this.

I have developed my own model as follows:

 class ConsoleModel : public QAbstractListModel

{

Q_OBJECT

public:

ConsoleModel (QObject *parent = 0);

int rowCount ( const QModelIndex & parent = QModelIndex() ) const;

QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole )
const;

void appendRow ( QStandardItem* item );

void clear();

QList<QStandardItem *> modelData() { return _listDisplayModel; }

 enum {

LogLevelRole = Qt::UserRole,

UUIDRole

};

protected:

void timerEvent(QTimerEvent *);

private:

QList<QStandardItem *> _listDisplayModel;

QList<QStandardItem *> _listInsertModel;

int batchSize;

QBasicTimer *insertionTimer;

};


The relevant code here is the timerEvent as follows:


void ConsoleModel::timerEvent(QTimerEvent *e)

{

if (e->timerId() == insertionTimer->timerId())

{

if (!_listInsertModel.isEmpty())

{

int inserted_items = 0;

int toBeInserted = 0;

if (_listInsertModel.size() < batchSize)

{

toBeInserted = _listInsertModel.size() - 1;

} else {

toBeInserted = batchSize - 1;

}

beginInsertRows( QModelIndex(), _listDisplayModel.size(),
_listDisplayModel.size() + toBeInserted );

emit layoutAboutToBeChanged();

while( !_listInsertModel.isEmpty() && inserted_items < batchSize)

{

_listDisplayModel.append(_listInsertModel.takeFirst());

inserted_items++;

}

endInsertRows();

emit layoutChanged();

}

}

}



This works, but if log messages roll too fast here, I end up blocking for
good. Let's say that I eased the problem but did not solve it.
There is one step more that I have not yet implemented here which is the
"buffer" behavior. When X amount of logs messages is shown, the logs will
delete the oldest lines. I guess this will not make the problem any easier
because it is one more task to be added to the timer here.

Any suggestions on how I can improve this? It seems to me that the
bottleneck is when the list is repainted. I trying playing with batchSize
but no better results.

Thank you,

jmesquita


On Thu, Aug 20, 2009 at 6:20 AM, Arnold Krille <arnold at arnoldarts.de> wrote:

> Hi,
>
> On Thursday 20 August 2009 07:03:26 João Mesquita wrote:
> > I am developing an application that has a console like interface and I
> > thought of using QListView to represent this console. Each line on the
> > console would be an item that is then appended to the QListView model.
> The
> > advantage of using such a widget is that the console log messages can be
> > sorted easily. I could easily make checkboxes to hide certain messages
> that
> > do not belong to certain log levels or apply Regex or even filters using
> a
> > custom QSortProxyModel. If anyone is familiar with Wireshark, that is
> > exactly the same behavior I am trying to achieve.
> > Problem here is performance. When sorting, not a problem, but when
> > inserting a large number of lines per second, I make the UI unresponsive
> > and even unusable. Should I change the widget, the model or not possible
> at
> > all?
>
> For these requirements you should write your own model (its not that
> hard!).
> When appending new lines, you would then cache the indizes of the new rows
> until a certain amount of time has passed (like 0.1 seconds). Otherwise the
> gui (and all asorted proxymodels used for sorting and filtering) would
> update
> on every appended/changed row, which makes the gui very slow when lots of
> lines are appended.
>
> Arnold
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090826/e8c21cb6/attachment.html 


More information about the Qt-interest-old mailing list