Project

General

Profile

bulkinsert.diff

admin, 08/30/2008 03:24 AM

View differences:

home/sphilips/projects/quassel/src/client/messagemodel.cpp 2008-08-30 03:15:00.000000000 +0000
25 25
MessageModel::MessageModel(QObject *parent)
26 26
  : QAbstractItemModel(parent)
27 27
{
28
   _grouping = false;
28 29
}
29 30

  
30 31
QVariant MessageModel::data(const QModelIndex &index, int role) const {
......
51 52
  return false;
52 53
}
53 54

  
55

  
56
/* Functions that allow intercepting the insertMessage() function.
57
   This way the rest of the program can still call insertMessage() without 
58
   knowing what's happening under the hood. */
59
void MessageModel::startGroupingMessages() {
60
  _grouping = true;
61
}
62

  
63
void MessageModel::stopGroupingMessages() {
64
  _grouping = false;
65
  if (_pendingList.isEmpty()) return;
66
  insertMessageGroup(_pendingList);
67
  _pendingList.clear();
68
}
69

  
70

  
54 71
bool MessageModel::insertMessage(const Message &msg, bool fakeMsg) {
55 72
  MsgId id = msg.msgId();
56 73
  int idx = indexForId(id);
......
59 76
      return false;
60 77
  }
61 78

  
79
  if (_grouping) {
80
    // Prevent inserting everything backwards
81
    if (!_pendingList.isEmpty() && _pendingList.first().msgId() > id)
82
      _pendingList.prepend(msg);
83
    else
84
      _pendingList.append(msg);
85
    return true;
86
  }
87

  
88
  // Grouping is disabled, insert it the normal way.
62 89
  MessageModelItem *item = createMessageModelItem(msg);
63 90
  beginInsertRows(QModelIndex(), idx, idx);
64 91
  _messageList.insert(idx, item);
......
66 93
  return true;
67 94
}
68 95

  
96

  
97
void MessageModel::insertMessageGroup(const QList<Message> &msglist) {
98
  if(msglist.isEmpty()) return;
99

  
100
  //qDebug() << "Inserting Group: " << msglist.count();
101

  
102
  int idx = indexForId(msglist.first().msgId());
103
  beginInsertRows(QModelIndex(), idx, idx+msglist.count()-1);
104

  
105
  foreach(Message msg, msglist) {
106
    MessageModelItem *item = createMessageModelItem(msg);
107
    _messageList.insert(idx, item);
108
    idx++;
109
  }
110

  
111
  endInsertRows();
112
}
113

  
114

  
115

  
116
// Old code, not sure if this is doing something or not.
69 117
void MessageModel::insertMessages(const QList<Message> &msglist) {
70 118
  if(msglist.isEmpty()) return;
119

  
71 120
  // FIXME make this more efficient by grouping msgs
72 121
  foreach(Message msg, msglist)
73 122
    insertMessage(msg);
74 123
}
75 124

  
125

  
76 126
void MessageModel::clear() {
77 127
  beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
78 128
  qDeleteAll(_messageList);
......
80 130
  endRemoveRows();
81 131
}
82 132

  
133

  
83 134
// returns index of msg with given Id or of the next message after that (i.e., the index where we'd insert this msg)
84 135
int MessageModel::indexForId(MsgId id) {
85 136
  if(_messageList.isEmpty() || id <= _messageList.value(0)->data(0, MsgIdRole).value<MsgId>()) return 0;
home/sphilips/projects/quassel/src/client/messagemodel.h 2008-08-30 01:53:12.000000000 +0000
65 65

  
66 66
  bool insertMessage(const Message &, bool fakeMsg = false);
67 67
  void insertMessages(const QList<Message> &);
68
  void insertMessageGroup(const QList<Message> &);
69

  
70
  void startGroupingMessages();
71
  void stopGroupingMessages();
68 72

  
69 73
  void clear();
70 74

  
......
73 77

  
74 78
private:
75 79
  QList<MessageModelItem *> _messageList;
80
  QList<Message> _pendingList; // About to be inserted.
81

  
82
  bool _grouping;
76 83

  
77 84
  int indexForId(MsgId);
78 85
};
home/sphilips/projects/quassel/src/qtui/chatline.cpp 2008-08-30 03:05:18.000000000 +0000
113 113
void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
114 114
  Q_UNUSED(option);
115 115
  Q_UNUSED(widget);
116

  
117
  // Some tweaks. They gain us a few ms, but every bit helps.
118
  painter->setPen(Qt::NoPen); // Apparently, using a Pen is slow when drawing text.
119
  painter->setClipRect(option->exposedRect);  // Don't repaint things that don't have to be repainted.
120

  
116 121
  if(_selection & Highlighted) {
117 122
    painter->fillRect(boundingRect(), QBrush(QtUi::style()->highlightColor()));
118 123
  }
home/sphilips/projects/quassel/src/qtui/chatview.cpp 2008-08-30 03:08:06.000000000 +0000
50 50
  setAlignment(Qt::AlignBottom);
51 51
  setInteractive(true);
52 52

  
53
  // We don't need any of those as we just draw text and horizontal/vertical lines.
54
  setOptimizationFlag(QGraphicsView::DontClipPainter);
55
  setOptimizationFlag(QGraphicsView::DontSavePainterState);
56
  setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
57

  
58
  // Not sure which of these two is the fastest.
59
  //setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
60
  setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
61

  
53 62
  _scene = new ChatScene(filter, filter->idString(), this);
54 63
  connect(_scene, SIGNAL(heightChangedAt(qreal, qreal)), this, SLOT(sceneHeightChangedAt(qreal, qreal)));
55 64
  setScene(_scene);
home/sphilips/projects/quassel/src/qtui/qtuimessageprocessor.cpp 2008-08-30 02:56:10.000000000 +0000
82 82

  
83 83
void QtUiMessageProcessor::processNextMessage() {
84 84
  if(_currentBatch.isEmpty()) {
85
    Client::messageModel()->stopGroupingMessages();
85 86
    if(_processQueue.isEmpty()) {
86 87
      _processTimer.stop();
87 88
      _processing = false;
......
90 91
      return;
91 92
    }
92 93
    _currentBatch = _processQueue.takeFirst();
94
    if (_currentBatch.count() > 1) // Otherwise it's a waste of resources
95
      Client::messageModel()->startGroupingMessages();
93 96
  }
94 97
  Message msg = _currentBatch.takeFirst();
95 98
  process(msg);
......
125 128
        nickList = myIdentity->nicks();
126 129
    }
127 130
    foreach(QString nickname, nickList) {
128
      QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$");
131
      QRegExp nickRegExp("^(?:.*\\W)?" + QRegExp::escape(nickname) + "(?:\\W.*)?$");
129 132
      if(nickRegExp.exactMatch(msg.contents())) {
130 133
        msg.setFlags(msg.flags() | Message::Highlight);
131 134
        return;
......
135 138
    for(int i = 0; i < _highlightRules.count(); i++) {
136 139
      const HighlightRule &rule = _highlightRules[i];
137 140
      if(!rule.isEnabled)
138
	continue;
141
        continue;
139 142

  
140 143
      QRegExp userRegExp;
141 144
      if(rule.isRegExp) {
142 145
        userRegExp = QRegExp(rule.name, rule.caseSensitive);
143 146
      } else {
144
        userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(rule.name) + "(\\W.*)?$", rule.caseSensitive);
147
        userRegExp = QRegExp("^(?:.*\\W)?" + QRegExp::escape(rule.name) + "(?:\\W.*)?$", rule.caseSensitive);
145 148
      }
146 149
      if(userRegExp.exactMatch(msg.contents())) {
147 150
        msg.setFlags(msg.flags() | Message::Highlight);