Optimized some internals in the news feed items

- std::string -> const std::string&
- QObjectList -> QSet<QObject*>

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4870 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-02-01 12:21:14 +00:00
parent 7cfdbd2d8d
commit ff0d6ff25a
24 changed files with 105 additions and 165 deletions

View file

@ -181,7 +181,7 @@ void NewsFeed::addFeedItem(QWidget *item)
item->setAttribute(Qt::WA_DeleteOnClose, true);
connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(itemDestroyed(QObject*)));
widgetList.push_back(item);
widgets.insert(item);
sendNewsFeedChanged();
@ -192,12 +192,10 @@ void NewsFeed::addFeedItem(QWidget *item)
}
}
void NewsFeed::addFeedItemIfUnique(QWidget *item, int itemType, std::string sslId, bool replace)
void NewsFeed::addFeedItemIfUnique(QWidget *item, int itemType, const std::string &sslId, bool replace)
{
QObjectList::iterator it;
for (it = widgetList.begin(); it != widgetList.end(); it++)
{
SecurityItem *secitem = dynamic_cast<SecurityItem*>(*it);
foreach (QObject *itemObject, widgets) {
SecurityItem *secitem = dynamic_cast<SecurityItem*>(itemObject);
if ((secitem) && (secitem->isSame(sslId, itemType)))
{
if (!replace)
@ -496,7 +494,7 @@ void NewsFeed::addFeedItemChatNew(RsFeedItem &fi)
}
/* make new widget */
ChatMsgItem *cm = new ChatMsgItem(this, NEWSFEED_CHATMSGLIST, fi.mId1, fi.mId2, true);
ChatMsgItem *cm = new ChatMsgItem(this, NEWSFEED_CHATMSGLIST, fi.mId1, fi.mId2);
/* store in forum list */
@ -553,11 +551,7 @@ void NewsFeed::openChat(std::string peerId)
void NewsFeed::itemDestroyed(QObject *item)
{
int index = widgetList.indexOf(item);
if (index >= 0) {
widgetList.removeAt(index);
}
widgets.remove(item);
sendNewsFeedChanged();
}
@ -566,23 +560,21 @@ void NewsFeed::removeAll()
#ifdef NEWS_DEBUG
std::cerr << "NewsFeed::removeAll()" << std::endl;
#endif
while (widgetList.count()) {
QObject *item = widgetList.first();
widgetList.pop_front();
foreach (QObject *item, widgets) {
if (item) {
item->deleteLater();
}
}
widgets.clear();
}
void NewsFeed::sendNewsFeedChanged()
{
int count = 0;
QObjectList::iterator it;
for (it = widgetList.begin(); it != widgetList.end(); it++) {
if (dynamic_cast<PeerItem*>(*it) == NULL) {
foreach (QObject *item, widgets) {
if (dynamic_cast<PeerItem*>(item) == NULL) {
/* don't count PeerItem's */
count++;
}

View file

@ -58,7 +58,7 @@ private slots:
private:
void addFeedItem(QWidget *item);
void addFeedItemIfUnique(QWidget *item, int itemType, std::string sslId, bool replace);
void addFeedItemIfUnique(QWidget *item, int itemType, const std::string &sslId, bool replace);
void addFeedItemPeerConnect(RsFeedItem &fi);
void addFeedItemPeerDisconnect(RsFeedItem &fi);
@ -85,7 +85,7 @@ private:
void sendNewsFeedChanged();
QLayout *mLayout;
QObjectList widgetList;
QSet<QObject*> widgets;
/* lists of feedItems */
std::list<ForumNewItem *> mForumNewItems;

View file

@ -48,8 +48,6 @@ public:
AttachFileItem(const QString& localpath);
AttachFileItem(const std::string& hash, const QString& name, uint64_t size, uint32_t flags, const std::string& srcId);
/** Default Destructor */
const std::string& FileHash() { return mFileHash; }
const QString& FileName() { return mFileName; }
uint64_t FileSize() { return mFileSize; }

View file

@ -34,9 +34,7 @@ class BlogMsgItem : public QWidget, private Ui::BlogMsgItem
public:
/** Default Constructor */
BlogMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string msgId, bool isHome);
/** Default Destructor */
BlogMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &msgId, bool isHome);
void updateItemStatic();
void small();
@ -63,7 +61,5 @@ private:
std::list<SubFileItem *> mFileItems;
};
#endif

View file

@ -33,9 +33,7 @@ class BlogNewItem : public QWidget, private Ui::BlogNewItem
public:
/** Default Constructor */
BlogNewItem(FeedHolder *parent, uint32_t feedId, std::string blogId, bool isHome, bool isNew);
/** Default Destructor */
BlogNewItem(FeedHolder *parent, uint32_t feedId, const std::string &blogId, bool isHome, bool isNew);
void updateItemStatic();
void small();
@ -60,7 +58,5 @@ private:
bool mIsNew;
};
#endif

View file

@ -40,7 +40,7 @@
****/
/** Constructor */
ChanMsgItem::ChanMsgItem(FeedHolder *parent, uint32_t feedId, std::string chanId, std::string msgId, bool isHome)
ChanMsgItem::ChanMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, const std::string &msgId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mChanId(chanId), mMsgId(msgId), mIsHome(isHome)
{

View file

@ -34,7 +34,7 @@ class ChanMsgItem : public QWidget, private Ui::ChanMsgItem
public:
/** Default Constructor */
ChanMsgItem(FeedHolder *parent, uint32_t feedId, std::string chanId, std::string msgId, bool isHome);
ChanMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, const std::string &msgId, bool isHome);
void updateItemStatic();
void small();

View file

@ -32,7 +32,7 @@
****/
/** Constructor */
ChanNewItem::ChanNewItem(FeedHolder *parent, uint32_t feedId, std::string chanId, bool isHome, bool isNew)
ChanNewItem::ChanNewItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, bool isHome, bool isNew)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mChanId(chanId), mIsHome(isHome), mIsNew(isNew)
{

View file

@ -33,9 +33,7 @@ class ChanNewItem : public QWidget, private Ui::ChanNewItem
public:
/** Default Constructor */
ChanNewItem(FeedHolder *parent, uint32_t feedId, std::string chanId, bool isHome, bool isNew);
/** Default Destructor */
ChanNewItem(FeedHolder *parent, uint32_t feedId, const std::string &chanId, bool isHome, bool isNew);
void updateItemStatic();
void small();
@ -59,7 +57,5 @@ private:
bool mIsNew;
};
#endif

View file

@ -42,9 +42,8 @@
****/
/** Constructor */
ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mPeerId(peerId), mIsHome(isHome)
ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &message)
:QWidget(NULL), mParent(parent), mFeedId(feedId), mPeerId(peerId)
{
/* Invoke the Qt Designer generated object setup routine */
setupUi(this);
@ -140,7 +139,7 @@ void ChatMsgItem::updateItem()
return;
}
void ChatMsgItem::insertChat(std::string &message)
void ChatMsgItem::insertChat(const std::string &message)
{
#ifdef DEBUG_ITEM
std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl;

View file

@ -25,19 +25,15 @@
#include "ui_ChatMsgItem.h"
#include <stdint.h>
class FeedHolder;
class ChatMsgItem : public QWidget, private Ui::ChatMsgItem
{
Q_OBJECT
public:
/** Default Constructor */
ChatMsgItem(FeedHolder *parent, uint32_t feedId, std::string peerId, std::string message, bool isHome);
/** Default Destructor */
ChatMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, const std::string &message);
void updateItemStatic();
@ -57,15 +53,12 @@ private slots:
void on_quickmsgText_textChanged();
private:
void insertChat(std::string &message);
void insertChat(const std::string &message);
FeedHolder *mParent;
uint32_t mFeedId;
std::string mPeerId;
bool mIsHome;
};
#endif

View file

@ -32,10 +32,9 @@ const uint32_t FEEDHOLDER_MSG_BLOG = 0x0004;
class FeedHolder
{
public:
virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0;
virtual void openChat(std::string peerId) = 0;
public:
virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0;
virtual void openChat(std::string peerId) = 0;
};
#endif

View file

@ -35,8 +35,6 @@ public:
/** Default Constructor */
ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome);
/** Default Destructor */
void updateItemStatic();
void small();
@ -63,7 +61,5 @@ private:
bool mIsTop;
};
#endif

View file

@ -31,7 +31,7 @@
****/
/** Constructor */
ForumNewItem::ForumNewItem(FeedHolder *parent, uint32_t feedId, std::string forumId, bool isHome, bool isNew)
ForumNewItem::ForumNewItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, bool isHome, bool isNew)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mForumId(forumId), mIsHome(isHome), mIsNew(isNew)
{
@ -203,4 +203,3 @@ void ForumNewItem::postToForum()
cfm->show();
}
}

View file

@ -33,9 +33,7 @@ class ForumNewItem : public QWidget, private Ui::ForumNewItem
public:
/** Default Constructor */
ForumNewItem(FeedHolder *parent, uint32_t feedId, std::string forumId, bool isHome, bool isNew);
/** Default Destructor */
ForumNewItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, bool isHome, bool isNew);
void updateItemStatic();
void small();
@ -60,7 +58,5 @@ private:
bool mIsNew;
};
#endif

View file

@ -38,7 +38,7 @@
****/
/** Constructor */
MsgItem::MsgItem(FeedHolder *parent, uint32_t feedId, std::string msgId, bool isHome)
MsgItem::MsgItem(FeedHolder *parent, uint32_t feedId, const std::string &msgId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), mMsgId(msgId), mIsHome(isHome)
{
/* Invoke the Qt Designer generated object setup routine */

View file

@ -34,9 +34,7 @@ class MsgItem : public QWidget, private Ui::MsgItem
public:
/** Default Constructor */
MsgItem(FeedHolder *parent, uint32_t feedId, std::string msgId, bool isHome);
/** Default Destructor */
MsgItem(FeedHolder *parent, uint32_t feedId, const std::string &msgId, bool isHome);
void updateItemStatic();
void small();
@ -65,7 +63,5 @@ private:
std::list<SubFileItem *> mFileItems;
};
#endif

View file

@ -41,7 +41,7 @@
****/
/** Constructor */
PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, std::string peerId, uint32_t type, bool isHome)
PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, uint32_t type, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mPeerId(peerId), mType(type), mIsHome(isHome)
{

View file

@ -32,16 +32,13 @@ const uint32_t PEER_TYPE_NEW_FOF = 0x0004; /* new Friend of Friend */
class FeedHolder;
class PeerItem : public QWidget, private Ui::PeerItem
{
Q_OBJECT
public:
/** Default Constructor */
PeerItem(FeedHolder *parent, uint32_t feedId, std::string peerId, uint32_t type, bool isHome);
/** Default Destructor */
PeerItem(FeedHolder *parent, uint32_t feedId, const std::string &peerId, uint32_t type, bool isHome);
void updateItemStatic();
void small();
@ -63,7 +60,6 @@ private slots:
void on_quickmsgText_textChanged();
private:
FeedHolder *mParent;
uint32_t mFeedId;
@ -73,7 +69,5 @@ private:
bool mIsHome;
};
#endif

View file

@ -43,7 +43,7 @@
****/
/** Constructor */
SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, std::string gpgId, std::string sslId, uint32_t type, bool isHome)
SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const std::string &gpgId, const std::string &sslId, uint32_t type, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId),
mSslId(sslId), mGpgId(gpgId), mType(type), mIsHome(isHome)
{

View file

@ -38,7 +38,7 @@ class SecurityItem : public QWidget, private Ui::SecurityItem
public:
/** Default Constructor */
SecurityItem(FeedHolder *parent, uint32_t feedId, std::string gpgId, std::string sslId, uint32_t type, bool isHome);
SecurityItem(FeedHolder *parent, uint32_t feedId, const std::string &gpgId, const std::string &sslId, uint32_t type, bool isHome);
void updateItemStatic();
void small();
@ -73,7 +73,5 @@ private:
bool mIsHome;
};
#endif

View file

@ -31,7 +31,7 @@
****/
/** Constructor */
SubDestItem::SubDestItem(uint32_t type, std::string groupId, std::string inReplyTo)
SubDestItem::SubDestItem(uint32_t type, const std::string &groupId, const std::string &inReplyTo)
:QWidget(NULL), mType(type), mGroupId(groupId), mInReplyTo(inReplyTo)
{
/* Invoke the Qt Designer generated object setup routine */

View file

@ -31,15 +31,13 @@ class SubDestItem : public QWidget, private Ui::SubDestItem
public:
/** Default Constructor */
SubDestItem(uint32_t type, std::string groupId, std::string inReplyTo);
/** Default Destructor */
SubDestItem(uint32_t type, const std::string &groupId, const std::string &inReplyTo);
uint32_t DestType() { return mType; }
std::string DestGroupId() { return mGroupId; }
std::string DestInReplyTo() { return mInReplyTo; }
void updateItemStatic();
void updateItemStatic();
private slots:
/* default stuff */
@ -51,7 +49,5 @@ private:
std::string mInReplyTo;
};
#endif

View file

@ -57,8 +57,6 @@ public:
/** Default Constructor */
SubFileItem(const std::string &hash, const std::string &name, const std::string &path, uint64_t size, uint32_t flags, const std::string &srcId);
/** Default Destructor */
void smaller();
std::string FileHash() { return mFileHash; }
@ -88,7 +86,6 @@ private slots:
void updateItem();
private:
void Setup();
std::string mPath;
@ -107,7 +104,6 @@ private:
signals:
void fileFinished(SubFileItem * subFileItem);
};
#endif