From: Manuel Nickschas Date: Wed, 29 Aug 2018 20:11:46 +0000 (+0200) Subject: client: Don't store the list of properties in every PropertyMapItem X-Git-Tag: 0.13-rc2~50 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=48dda5f3e963e13e36300ddaef262660bf169672 client: Don't store the list of properties in every PropertyMapItem It's rather inefficient to store a QStringList in every item, since it is the same for every type of item anyway. Use a pure virtual accessor in the base class instead, and return a static QStringList in every item type. This prevents the usecase of adding properties dynamically after creation, but we didn't use that feature anyway, so remove it. --- diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 82149662..6df98c32 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -40,7 +40,7 @@ * Network Items *****************************************/ NetworkItem::NetworkItem(const NetworkId &netid, AbstractTreeItem *parent) - : PropertyMapItem(QList() << "networkName" << "currentServer" << "nickCount", parent), + : PropertyMapItem(parent), _networkId(netid), _statusBufferItem(0) { @@ -53,6 +53,13 @@ NetworkItem::NetworkItem(const NetworkId &netid, AbstractTreeItem *parent) } +QStringList NetworkItem::propertyOrder() const +{ + static QStringList order{"networkName", "currentServer", "nickCount"}; + return order; +} + + QVariant NetworkItem::data(int column, int role) const { switch (role) { @@ -283,7 +290,7 @@ void NetworkItem::onNetworkDestroyed() * Fancy Buffer Items *****************************************/ BufferItem::BufferItem(const BufferInfo &bufferInfo, AbstractTreeItem *parent) - : PropertyMapItem(QStringList() << "bufferName" << "topic" << "nickCount", parent), + : PropertyMapItem(parent), _bufferInfo(bufferInfo), _activity(BufferInfo::NoActivity) { @@ -291,6 +298,13 @@ BufferItem::BufferItem(const BufferInfo &bufferInfo, AbstractTreeItem *parent) } +QStringList BufferItem::propertyOrder() const +{ + static QStringList order{"bufferName", "topic", "nickCount"}; + return order; +} + + void BufferItem::setActivityLevel(BufferInfo::ActivityLevel level) { if (_activity != level) { @@ -992,7 +1006,7 @@ void ChannelBufferItem::userModeChanged(IrcUser *ircUser) const QList UserCategoryItem::categories = QList() << 'q' << 'a' << 'o' << 'h' << 'v'; UserCategoryItem::UserCategoryItem(int category, AbstractTreeItem *parent) - : PropertyMapItem(QStringList() << "categoryName", parent), + : PropertyMapItem(parent), _category(category) { setFlags(Qt::ItemIsEnabled); @@ -1001,6 +1015,13 @@ UserCategoryItem::UserCategoryItem(int category, AbstractTreeItem *parent) } +QStringList UserCategoryItem::propertyOrder() const +{ + static QStringList order{"categoryName"}; + return order; +} + + // caching this makes no sense, since we display the user number dynamically QString UserCategoryItem::categoryName() const { @@ -1094,7 +1115,7 @@ QVariant UserCategoryItem::data(int column, int role) const * Irc User Items *****************************************/ IrcUserItem::IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent) - : PropertyMapItem(QStringList() << "nickName", parent), + : PropertyMapItem(parent), _ircUser(ircUser) { setObjectName(ircUser->nick()); @@ -1104,6 +1125,13 @@ IrcUserItem::IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent) } +QStringList IrcUserItem::propertyOrder() const +{ + static QStringList order{"nickName"}; + return order; +} + + QVariant IrcUserItem::data(int column, int role) const { switch (role) { diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index 6b68191c..a97372e8 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -41,7 +41,9 @@ class NetworkItem : public PropertyMapItem Q_PROPERTY(int nickCount READ nickCount) public : - NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0); + NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0); + + virtual QStringList propertyOrder() const; virtual QVariant data(int column, int row) const; @@ -106,7 +108,9 @@ class BufferItem : public PropertyMapItem Q_PROPERTY(int nickCount READ nickCount) public : - BufferItem(const BufferInfo &bufferInfo, AbstractTreeItem *parent = 0); + BufferItem(const BufferInfo &bufferInfo, AbstractTreeItem *parent = 0); + + virtual QStringList propertyOrder() const; inline const BufferInfo &bufferInfo() const { return _bufferInfo; } virtual QVariant data(int column, int role) const; @@ -252,7 +256,9 @@ class UserCategoryItem : public PropertyMapItem Q_PROPERTY(QString categoryName READ categoryName) public : - UserCategoryItem(int category, AbstractTreeItem *parent); + UserCategoryItem(int category, AbstractTreeItem *parent); + + virtual QStringList propertyOrder() const; QString categoryName() const; inline int categoryId() const { return _category; } @@ -280,7 +286,9 @@ class IrcUserItem : public PropertyMapItem Q_PROPERTY(QString nickName READ nickName) public : - IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent); + IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent); + + virtual QStringList propertyOrder() const; inline QString nickName() const { return _ircUser ? _ircUser->nick() : QString(); } inline bool isActive() const { return _ircUser ? !_ircUser->isAway() : false; } diff --git a/src/client/treemodel.cpp b/src/client/treemodel.cpp index f87d3367..a8cd86b7 100644 --- a/src/client/treemodel.cpp +++ b/src/client/treemodel.cpp @@ -275,21 +275,8 @@ int SimpleTreeItem::columnCount() const /***************************************** * PropertyMapItem *****************************************/ -PropertyMapItem::PropertyMapItem(const QStringList &propertyOrder, AbstractTreeItem *parent) - : AbstractTreeItem(parent), - _propertyOrder(propertyOrder) -{ -} - - PropertyMapItem::PropertyMapItem(AbstractTreeItem *parent) - : AbstractTreeItem(parent), - _propertyOrder(QStringList()) -{ -} - - -PropertyMapItem::~PropertyMapItem() + : AbstractTreeItem(parent) { } @@ -304,7 +291,7 @@ QVariant PropertyMapItem::data(int column, int role) const return toolTip(column); case Qt::DisplayRole: case TreeModel::SortRole: // fallthrough, since SortRole should default to DisplayRole - return property(_propertyOrder[column].toLatin1()); + return property(propertyOrder()[column].toLatin1()); default: return QVariant(); } @@ -316,7 +303,7 @@ bool PropertyMapItem::setData(int column, const QVariant &value, int role) if (column >= columnCount() || role != Qt::DisplayRole) return false; - setProperty(_propertyOrder[column].toLatin1(), value); + setProperty(propertyOrder()[column].toLatin1(), value); emit dataChanged(column); return true; } @@ -324,13 +311,7 @@ bool PropertyMapItem::setData(int column, const QVariant &value, int role) int PropertyMapItem::columnCount() const { - return _propertyOrder.count(); -} - - -void PropertyMapItem::appendProperty(const QString &property) -{ - _propertyOrder << property; + return propertyOrder().count(); } diff --git a/src/client/treemodel.h b/src/client/treemodel.h index e4979ae2..12da2ed2 100644 --- a/src/client/treemodel.h +++ b/src/client/treemodel.h @@ -126,21 +126,15 @@ class PropertyMapItem : public AbstractTreeItem Q_OBJECT public: - PropertyMapItem(const QStringList &propertyOrder, AbstractTreeItem *parent = 0); PropertyMapItem(AbstractTreeItem *parent = 0); - virtual ~PropertyMapItem(); + virtual QStringList propertyOrder() const = 0; virtual QVariant data(int column, int role) const; virtual bool setData(int column, const QVariant &value, int role); virtual QString toolTip(int column) const { Q_UNUSED(column) return QString(); } virtual int columnCount() const; - - void appendProperty(const QString &property); - -private: - QStringList _propertyOrder; };