We should make sure that index() always returns an invalid model index for invalid
parameters (aka, out of bounds). This has been found with Qt's ModelTest.
I don't *think* this has any impact in Quassel, as we should never call index() with invalid
parameters anyway, but who knows. Maybe some of our crashes are related to this...
Better safe than sorry! :)
MessageModel(QObject *parent);
MessageModel(QObject *parent);
- inline QModelIndex index(int row, int column, const QModelIndex &/*parent*/ = QModelIndex()) const { return createIndex(row, column); }
+ inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
inline QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : messageCount(); }
inline int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 3; }
inline QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : messageCount(); }
inline int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 3; }
QHash<BufferId, int> _messagesWaiting;
};
QHash<BufferId, int> _messagesWaiting;
};
+// inlines
+QModelIndex MessageModel::index(int row, int column, const QModelIndex &parent) const {
+ if(row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent))
+ return QModelIndex();
+
+ return createIndex(row, column);
+}
+
// **************************************************
// MessageModelItem
// **************************************************
// **************************************************
// MessageModelItem
// **************************************************
_network = network;
connect(network, SIGNAL(networkNameSet(QString)),
_network = network;
connect(network, SIGNAL(networkNameSet(QString)),
- this, SLOT(setNetworkName(QString)));
+ this, SLOT(setNetworkName(QString)));
connect(network, SIGNAL(currentServerSet(QString)),
connect(network, SIGNAL(currentServerSet(QString)),
- this, SLOT(setCurrentServer(QString)));
+ this, SLOT(setCurrentServer(QString)));
connect(network, SIGNAL(ircChannelAdded(IrcChannel *)),
connect(network, SIGNAL(ircChannelAdded(IrcChannel *)),
- this, SLOT(attachIrcChannel(IrcChannel *)));
+ this, SLOT(attachIrcChannel(IrcChannel *)));
connect(network, SIGNAL(ircUserAdded(IrcUser *)),
connect(network, SIGNAL(ircUserAdded(IrcUser *)),
- this, SLOT(attachIrcUser(IrcUser *)));
+ this, SLOT(attachIrcUser(IrcUser *)));
connect(network, SIGNAL(connectedSet(bool)),
connect(network, SIGNAL(connectedSet(bool)),
- this, SIGNAL(networkDataChanged()));
+ this, SIGNAL(networkDataChanged()));
connect(network, SIGNAL(destroyed()),
connect(network, SIGNAL(destroyed()),
- this, SIGNAL(networkDataChanged()));
+ this, SIGNAL(networkDataChanged()));
emit networkDataChanged();
}
emit networkDataChanged();
}
stateChanged = true;
_firstUnreadMsgId = msg.msgId();
}
stateChanged = true;
_firstUnreadMsgId = msg.msgId();
}
BufferInfo::ActivityLevel oldLevel = activityLevel();
_activity |= BufferInfo::OtherActivity;
BufferInfo::ActivityLevel oldLevel = activityLevel();
_activity |= BufferInfo::OtherActivity;
{
QString newName = value.toString();
if(!newName.isEmpty()) {
{
QString newName = value.toString();
if(!newName.isEmpty()) {
- Client::renameBuffer(bufferId(), newName);
- return true;
+ Client::renameBuffer(bufferId(), newName);
+ return true;
QString _topic = topic();
if(_topic != "") {
_topic = stripFormatCodes(_topic);
QString _topic = topic();
if(_topic != "") {
_topic = stripFormatCodes(_topic);
- _topic = Qt::escape(_topic);
+ _topic = Qt::escape(_topic);
toolTip.append(QString("<font size='-2'> </font>"));
toolTip.append(tr("<b>Topic:</b> %1").arg(_topic));
}
toolTip.append(QString("<font size='-2'> </font>"));
toolTip.append(tr("<b>Topic:</b> %1").arg(_topic));
}
_ircChannel = ircChannel;
connect(ircChannel, SIGNAL(topicSet(QString)),
_ircChannel = ircChannel;
connect(ircChannel, SIGNAL(topicSet(QString)),
- this, SLOT(setTopic(QString)));
+ this, SLOT(setTopic(QString)));
connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *>)),
connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *>)),
- this, SLOT(join(QList<IrcUser *>)));
+ this, SLOT(join(QList<IrcUser *>)));
connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
- this, SLOT(part(IrcUser *)));
+ this, SLOT(part(IrcUser *)));
connect(ircChannel, SIGNAL(parted()),
connect(ircChannel, SIGNAL(parted()),
- this, SLOT(ircChannelParted()));
+ this, SLOT(ircChannelParted()));
connect(ircChannel, SIGNAL(ircUserModesSet(IrcUser *, QString)),
connect(ircChannel, SIGNAL(ircUserModesSet(IrcUser *, QString)),
- this, SLOT(userModeChanged(IrcUser *)));
+ this, SLOT(userModeChanged(IrcUser *)));
connect(ircChannel, SIGNAL(ircUserModeAdded(IrcUser *, QString)),
connect(ircChannel, SIGNAL(ircUserModeAdded(IrcUser *, QString)),
- this, SLOT(userModeChanged(IrcUser *)));
+ this, SLOT(userModeChanged(IrcUser *)));
connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
- this, SLOT(userModeChanged(IrcUser *)));
+ this, SLOT(userModeChanged(IrcUser *)));
if(!ircChannel->ircUsers().isEmpty())
join(ircChannel->ircUsers());
if(!ircChannel->ircUsers().isEmpty())
join(ircChannel->ircUsers());
categoryItem = qobject_cast<UserCategoryItem *>(child(i));
if(categoryItem->removeUser(ircUser)) {
if(categoryItem->childCount() == 0)
categoryItem = qobject_cast<UserCategoryItem *>(child(i));
if(categoryItem->removeUser(ircUser)) {
if(categoryItem->childCount() == 0)
: TreeModel(NetworkModel::defaultHeader(), parent)
{
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
: TreeModel(NetworkModel::defaultHeader(), parent)
{
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this, SLOT(checkForNewBuffers(const QModelIndex &, int, int)));
+ this, SLOT(checkForNewBuffers(const QModelIndex &, int, int)));
connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
- this, SLOT(checkForRemovedBuffers(const QModelIndex &, int, int)));
+ this, SLOT(checkForRemovedBuffers(const QModelIndex &, int, int)));
BufferSettings defaultSettings;
defaultSettings.notify("UserNoticesTarget", this, SLOT(messageRedirectionSettingsChanged()));
BufferSettings defaultSettings;
defaultSettings.notify("UserNoticesTarget", this, SLOT(messageRedirectionSettingsChanged()));
if(bufferType(msg.bufferId()) != BufferInfo::ChannelBuffer) {
msg.setFlags(msg.flags() | Message::Redirected);
if(msg.flags() & Message::ServerMsg) {
if(bufferType(msg.bufferId()) != BufferInfo::ChannelBuffer) {
msg.setFlags(msg.flags() | Message::Redirected);
if(msg.flags() & Message::ServerMsg) {
- // server notice
- redirectionTarget = _serverNoticesTarget;
+ // server notice
+ redirectionTarget = _serverNoticesTarget;
- redirectionTarget = _userNoticesTarget;
+ redirectionTarget = _userNoticesTarget;
if(redirectionTarget & BufferSettings::StatusBuffer) {
const NetworkItem *netItem = findNetworkItem(msg.bufferInfo().networkId());
if(netItem) {
if(redirectionTarget & BufferSettings::StatusBuffer) {
const NetworkItem *netItem = findNetworkItem(msg.bufferInfo().networkId());
if(netItem) {
- updateBufferActivity(netItem->statusBufferItem(), msg);
+ updateBufferActivity(netItem->statusBufferItem(), msg);
if(Quassel::isOptionSet("debugmodel")) {
connect(this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
if(Quassel::isOptionSet("debugmodel")) {
connect(this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
- this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int)));
+ this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int)));
connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
- this, SLOT(debug_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
+ this, SLOT(debug_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this, SLOT(debug_rowsInserted(const QModelIndex &, int, int)));
+ this, SLOT(debug_rowsInserted(const QModelIndex &, int, int)));
connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
- this, SLOT(debug_rowsRemoved(const QModelIndex &, int, int)));
+ this, SLOT(debug_rowsRemoved(const QModelIndex &, int, int)));
connect(this, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
connect(this, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
- this, SLOT(debug_dataChanged(const QModelIndex &, const QModelIndex &)));
+ this, SLOT(debug_dataChanged(const QModelIndex &, const QModelIndex &)));
}
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const {
}
QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const {
- if(!hasIndex(row, column, parent))
+ if(row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent))
return QModelIndex();
AbstractTreeItem *parentItem;
return QModelIndex();
AbstractTreeItem *parentItem;
QModelIndex TreeModel::parent(const QModelIndex &index) const {
if(!index.isValid()) {
QModelIndex TreeModel::parent(const QModelIndex &index) const {
if(!index.isValid()) {
- qWarning() << "TreeModel::parent(): has been asked for the rootItems Parent!";
+ // ModelTest does this
+ // qWarning() << "TreeModel::parent(): has been asked for the rootItems Parent!";
void TreeModel::connectItem(AbstractTreeItem *item) {
connect(item, SIGNAL(dataChanged(int)),
void TreeModel::connectItem(AbstractTreeItem *item) {
connect(item, SIGNAL(dataChanged(int)),
- this, SLOT(itemDataChanged(int)));
+ this, SLOT(itemDataChanged(int)));
connect(item, SIGNAL(beginAppendChilds(int, int)),
connect(item, SIGNAL(beginAppendChilds(int, int)),
- this, SLOT(beginAppendChilds(int, int)));
+ this, SLOT(beginAppendChilds(int, int)));
connect(item, SIGNAL(endAppendChilds()),
connect(item, SIGNAL(endAppendChilds()),
- this, SLOT(endAppendChilds()));
+ this, SLOT(endAppendChilds()));
connect(item, SIGNAL(beginRemoveChilds(int, int)),
connect(item, SIGNAL(beginRemoveChilds(int, int)),
- this, SLOT(beginRemoveChilds(int, int)));
+ this, SLOT(beginRemoveChilds(int, int)));
connect(item, SIGNAL(endRemoveChilds()),
connect(item, SIGNAL(endRemoveChilds()),
- this, SLOT(endRemoveChilds()));
+ this, SLOT(endRemoveChilds()));
}
void TreeModel::beginAppendChilds(int firstRow, int lastRow) {
}
void TreeModel::beginAppendChilds(int firstRow, int lastRow) {