~ubuntu-branches/ubuntu/quantal/kdevplatform/quantal-proposed

« back to all changes in this revision

Viewing changes to outputview/outputmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-24 00:06:18 UTC
  • mfrom: (0.3.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101024000618-7otebin77mfcmt3b
Tags: 1.1.0-0ubuntu1
* New upstream release
  - Bump build-dependencies
  - Build against libboost-serialization1.42-dev
  - Update kdevplatform1-libs.install
  - Update kdevplatform-dev.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
2
 *   This file is part of KDevelop                                         *
3
 
 *   Copyright 2007 Andreas Pakulat <apaku@gmx.de>                     *
 
3
 *   Copyright 2007 Andreas Pakulat <apaku@gmx.de>                         *
 
4
 *   Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org>                  *
4
5
 *                                                                         *
5
6
 *   This program is free software; you can redistribute it and/or modify  *
6
7
 *   it under the terms of the GNU Library General Public License as       *
21
22
#include "outputmodel.h"
22
23
 
23
24
#include <QtCore/QStringList>
 
25
#include <QtCore/QTimer>
24
26
 
25
27
#include <kglobalsettings.h>
26
28
 
27
29
namespace KDevelop
28
30
{
29
31
 
 
32
struct OutputModelPrivate
 
33
{
 
34
    QTimer* timer;
 
35
    QVector<QStandardItem*> pending;
 
36
    
 
37
    static const int MAX_SIZE;
 
38
    static const int INTERVAL_MS;
 
39
};
 
40
 
 
41
const int OutputModelPrivate::MAX_SIZE=10000;
 
42
const int OutputModelPrivate::INTERVAL_MS=50;
 
43
 
30
44
OutputModel::OutputModel( QObject* parent )
31
 
    : QStandardItemModel( parent ), d(0)
 
45
    : QStandardItemModel( parent ), d(new OutputModelPrivate)
32
46
{
 
47
    d->timer = new QTimer(this);
 
48
    d->timer->setInterval(OutputModelPrivate::INTERVAL_MS);
 
49
    d->timer->setSingleShot(true);
 
50
    
 
51
    d->pending.reserve(OutputModelPrivate::MAX_SIZE);
 
52
    
 
53
    connect(d->timer, SIGNAL(timeout()), SLOT(addPending()));
 
54
}
33
55
 
 
56
OutputModel::~OutputModel()
 
57
{
 
58
    addPending();
 
59
    delete d;
34
60
}
35
61
 
36
62
void OutputModel::appendLine( const QString& line )
37
63
{
38
64
    QStandardItem* item = new QStandardItem( line );
39
65
    item->setFont( KGlobalSettings::fixedFont() );
40
 
    appendRow( item );
 
66
    
 
67
    d->pending.append(item);
 
68
    if(d->pending.size()<OutputModelPrivate::MAX_SIZE)
 
69
        d->timer->start();
 
70
    else
 
71
        addPending();
41
72
}
42
73
 
43
74
void OutputModel::appendLines( const QStringList& lines)
48
79
    }
49
80
}
50
81
 
 
82
void OutputModel::addPending()
 
83
{
 
84
    if(!d->pending.isEmpty())
 
85
        invisibleRootItem()->appendRows(d->pending.toList());
 
86
    
 
87
    d->pending.clear();
 
88
}
 
89
 
51
90
}
52
91
 
53
92
#include "outputmodel.moc"