From 6af2fc9af52731ac3630c9019c0bfebd877666b9 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 2 Sep 2010 17:15:20 +0200 Subject: Code Review. General clean up let member variables have better names, starting with _ and the needed get functions signals/slots --> Q_SIGNALS/Q_SLOTS moc headers --- src/bookmarks/bookmarkowner.cpp | 1 + src/bookmarks/bookmarkowner.h | 27 +++++++++++++------------- src/bookmarks/bookmarkprovider.cpp | 1 + src/bookmarks/bookmarkprovider.h | 18 ++++++++---------- src/bookmarks/bookmarkspanel.cpp | 37 ++++++++++++++++++------------------ src/bookmarks/bookmarkspanel.h | 15 ++++++++------- src/bookmarks/bookmarkstreemodel.cpp | 1 + src/bookmarks/bookmarkstreemodel.h | 13 ++++++++----- src/history/historypanel.cpp | 21 ++++++++++---------- src/history/historypanel.h | 3 +-- src/urlbar/urlresolver.cpp | 1 + src/urlbar/urlresolver.h | 18 ++++++++++-------- src/urlfilterproxymodel.cpp | 1 + src/urlfilterproxymodel.h | 6 ++++-- src/urlpanel.cpp | 17 +++++++++-------- src/urlpanel.h | 16 ++++++++-------- 16 files changed, 105 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/bookmarks/bookmarkowner.cpp b/src/bookmarks/bookmarkowner.cpp index 530ad199..f1d4df1f 100644 --- a/src/bookmarks/bookmarkowner.cpp +++ b/src/bookmarks/bookmarkowner.cpp @@ -29,6 +29,7 @@ // Self Includes #include "bookmarkowner.h" +#include "bookmarkowner.moc" // Local Includes #include "application.h" diff --git a/src/bookmarks/bookmarkowner.h b/src/bookmarks/bookmarkowner.h index e0c2a8ad..795ccbf0 100644 --- a/src/bookmarks/bookmarkowner.h +++ b/src/bookmarks/bookmarkowner.h @@ -40,6 +40,7 @@ // Forward Declarations class KAction; + /** * Reimplementation of KBookmarkOwner, this class allows to manage * bookmarks as actions. @@ -111,14 +112,7 @@ public: */ virtual void openFolderinTabs(const KBookmarkGroup &bookmark); -signals: - /** - * This signal is emitted when an url has to be loaded - * @param url the URL to load - */ - void openUrl(const KUrl &, const Rekonq::OpenType &); - -public slots: +public Q_SLOTS: void setCurrentBookmark(const KBookmark &bookmark); void openBookmark(const KBookmark &bookmark = KBookmark()); @@ -132,16 +126,23 @@ public slots: void editBookmark(KBookmark bookmark = KBookmark()); bool deleteBookmark(KBookmark bookmark = KBookmark()); -private: - KBookmarkManager *m_manager; - - QVector m_actions; - KBookmark m_currentBookmark; +Q_SIGNALS: + /** + * This signal is emitted when an url has to be loaded + * @param url the URL to load + */ + void openUrl(const KUrl &, const Rekonq::OpenType &); +private: void setupActions(); void createAction(const BookmarkAction &action, const QString &text, const QString &icon, const QString &help, const char *slot); + + + KBookmarkManager *m_manager; + QVector m_actions; + KBookmark m_currentBookmark; }; #endif // BOOKMARKOWNER_H diff --git a/src/bookmarks/bookmarkprovider.cpp b/src/bookmarks/bookmarkprovider.cpp index f5021916..ccf60641 100644 --- a/src/bookmarks/bookmarkprovider.cpp +++ b/src/bookmarks/bookmarkprovider.cpp @@ -29,6 +29,7 @@ // Self Includes #include "bookmarkprovider.h" +#include "bookmarkprovider.moc" // Local Includes #include "application.h" diff --git a/src/bookmarks/bookmarkprovider.h b/src/bookmarks/bookmarkprovider.h index 36724d75..6f2d8b8e 100644 --- a/src/bookmarks/bookmarkprovider.h +++ b/src/bookmarks/bookmarkprovider.h @@ -114,14 +114,7 @@ public: KBookmark bookmarkForUrl(const KUrl &url); -signals: - /** - * @short This signal is emitted when an url has to be loaded - */ - void openUrl(const KUrl &, const Rekonq::OpenType &); - - -public slots: +public Q_SLOTS: /** * @short Waits for signal that the group with the address has been modified by the caller. * Waits for signal that the group (or any of its children) with the address @@ -133,13 +126,18 @@ public slots: void slotBookmarksChanged(const QString &groupAddress, const QString &caller); void fillBookmarkBar(BookmarkToolBar *toolBar); -private slots: +private Q_SLOTS: void slotAddBookmark(); void slotPanelChanged(); + +Q_SIGNALS: + /** + * @short This signal is emitted when an url has to be loaded + */ + void openUrl(const KUrl &, const Rekonq::OpenType &); private: void find(QList *list, const KBookmark &bookmark, const QString &text); - KBookmark bookmarkForUrl(const KBookmark &bookmark, const KUrl &url); KBookmarkManager *m_manager; diff --git a/src/bookmarks/bookmarkspanel.cpp b/src/bookmarks/bookmarkspanel.cpp index d082b557..27c60e46 100644 --- a/src/bookmarks/bookmarkspanel.cpp +++ b/src/bookmarks/bookmarkspanel.cpp @@ -27,6 +27,7 @@ // Self Includes #include "bookmarkspanel.h" +#include "bookmarkspanel.moc" // Auto Includes #include "rekonq.h" @@ -43,12 +44,12 @@ BookmarksPanel::BookmarksPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) : UrlPanel(title, parent, flags) - , model(new BookmarksTreeModel(this)) - , m_loadingState(false) + , _bkTreeModel(new BookmarksTreeModel(this)) + , _loadingState(false) { setObjectName("bookmarksPanel"); setVisible(ReKonfig::showBookmarksPanel()); - connect(model, SIGNAL(bookmarksUpdated()), this, SLOT(startLoadFoldedState())); + connect(_bkTreeModel, SIGNAL(bookmarksUpdated()), this, SLOT(startLoadFoldedState())); } @@ -60,24 +61,24 @@ BookmarksPanel::~BookmarksPanel() void BookmarksPanel::startLoadFoldedState() { - m_loadingState = true; + _loadingState = true; loadFoldedState(QModelIndex()); - m_loadingState = false; + _loadingState = false; } void BookmarksPanel::contextMenu(const QPoint &pos) { - if (m_loadingState) + if (_loadingState) return; - BookmarksContextMenu menu(bookmarkForIndex( m_treeView->indexAt(pos) ), + BookmarksContextMenu menu(bookmarkForIndex( panelTreeView()->indexAt(pos) ), Application::bookmarkProvider()->bookmarkManager(), Application::bookmarkProvider()->bookmarkOwner(), this ); - menu.exec(m_treeView->mapToGlobal(pos)); + menu.exec(panelTreeView()->mapToGlobal(pos)); } @@ -101,8 +102,8 @@ void BookmarksPanel::contextMenuEmpty(const QPoint &pos) void BookmarksPanel::deleteBookmark() { - QModelIndex index = m_treeView->currentIndex(); - if (m_loadingState || !index.isValid()) + QModelIndex index = panelTreeView()->currentIndex(); + if (_loadingState || !index.isValid()) return; Application::bookmarkProvider()->bookmarkOwner()->deleteBookmark(bookmarkForIndex(index)); @@ -111,7 +112,7 @@ void BookmarksPanel::deleteBookmark() void BookmarksPanel::onCollapse(const QModelIndex &index) { - if (m_loadingState) + if (_loadingState) return; bookmarkForIndex(index).internalElement().setAttribute("folded", "yes"); @@ -121,7 +122,7 @@ void BookmarksPanel::onCollapse(const QModelIndex &index) void BookmarksPanel::onExpand(const QModelIndex &index) { - if (m_loadingState) + if (_loadingState) return; bookmarkForIndex(index).internalElement().setAttribute("folded", "no"); @@ -131,7 +132,7 @@ void BookmarksPanel::onExpand(const QModelIndex &index) void BookmarksPanel::loadFoldedState(const QModelIndex &root) { - QAbstractItemModel *model = m_treeView->model(); + QAbstractItemModel *model = panelTreeView()->model(); int count = model->rowCount(root); QModelIndex index; @@ -143,7 +144,7 @@ void BookmarksPanel::loadFoldedState(const QModelIndex &root) KBookmark bm = bookmarkForIndex(index); if (bm.isGroup()) { - m_treeView->setExpanded(index, bm.toGroup().isOpen()); + panelTreeView()->setExpanded(index, bm.toGroup().isOpen()); loadFoldedState(index); } } @@ -156,9 +157,9 @@ void BookmarksPanel::setup() UrlPanel::setup(); kDebug() << "Bookmarks panel..."; - connect(m_treeView, SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark())); - connect(m_treeView, SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &))); - connect(m_treeView, SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &))); + connect(panelTreeView(), SIGNAL(delKeyPressed()), this, SLOT(deleteBookmark())); + connect(panelTreeView(), SIGNAL(collapsed(const QModelIndex &)), this, SLOT(onCollapse(const QModelIndex &))); + connect(panelTreeView(), SIGNAL(expanded(const QModelIndex &)), this, SLOT(onExpand(const QModelIndex &))); startLoadFoldedState(); } @@ -179,5 +180,5 @@ KBookmark BookmarksPanel::bookmarkForIndex(const QModelIndex &index) QAbstractItemModel* BookmarksPanel::getModel() { - return model; + return _bkTreeModel; } diff --git a/src/bookmarks/bookmarkspanel.h b/src/bookmarks/bookmarkspanel.h index 6ee2dc85..f042d4c8 100644 --- a/src/bookmarks/bookmarkspanel.h +++ b/src/bookmarks/bookmarkspanel.h @@ -42,6 +42,7 @@ class BookmarksTreeModel; class KBookmark; class QModelIndex; + class REKONQ_TESTS_EXPORT BookmarksPanel : public UrlPanel { Q_OBJECT @@ -50,13 +51,10 @@ public: explicit BookmarksPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); virtual ~BookmarksPanel(); -signals: - void expansionChanged(); - -public slots: +public Q_SLOTS: void startLoadFoldedState(); -private slots: +private Q_SLOTS: void contextMenu(const QPoint &pos); virtual void contextMenuItem(const QPoint &pos); virtual void contextMenuGroup(const QPoint &pos); @@ -67,14 +65,17 @@ private slots: void onExpand(const QModelIndex &index); void loadFoldedState(const QModelIndex &root); +Q_SIGNALS: + void expansionChanged(); + private: virtual void setup(); KBookmark bookmarkForIndex(const QModelIndex &index); virtual QAbstractItemModel* getModel(); - BookmarksTreeModel *model; - bool m_loadingState; + BookmarksTreeModel *_bkTreeModel; + bool _loadingState; }; #endif // BOOKMARKSPANEL_H diff --git a/src/bookmarks/bookmarkstreemodel.cpp b/src/bookmarks/bookmarkstreemodel.cpp index 254a914f..7a1193e4 100644 --- a/src/bookmarks/bookmarkstreemodel.cpp +++ b/src/bookmarks/bookmarkstreemodel.cpp @@ -27,6 +27,7 @@ // Self Includes #include "bookmarkstreemodel.h" +#include "bookmarkstreemodel.moc" // Local Includes #include "application.h" diff --git a/src/bookmarks/bookmarkstreemodel.h b/src/bookmarks/bookmarkstreemodel.h index 6b85365b..7bbce339 100644 --- a/src/bookmarks/bookmarkstreemodel.h +++ b/src/bookmarks/bookmarkstreemodel.h @@ -38,6 +38,7 @@ // Qt Includes #include + class BtmItem { public: @@ -60,10 +61,12 @@ private: }; +// ------------------------------------------------------------------------------------------------- + + class REKONQ_TESTS_EXPORT BookmarksTreeModel : public QAbstractItemModel { Q_OBJECT - Q_DISABLE_COPY(BookmarksTreeModel) public: explicit BookmarksTreeModel(QObject *parent = 0); @@ -95,19 +98,19 @@ public: virtual Qt::DropActions supportedDropActions() const; virtual QMimeData *mimeData(const QModelIndexList &indexes) const; -private slots: +private Q_SLOTS: void bookmarksChanged(const QString &groupAddress); -signals: +Q_SIGNALS: void bookmarksUpdated(); private: - BtmItem *m_root; - void resetModel(); void setRoot(KBookmarkGroup bmg); void populate(BtmItem *node, KBookmarkGroup bmg); KBookmark bookmarkForIndex(const QModelIndex &index) const; + + BtmItem *m_root; }; #endif // BOOKMARKSTREEMODEL_H diff --git a/src/history/historypanel.cpp b/src/history/historypanel.cpp index 84f2296e..28f7f4ee 100644 --- a/src/history/historypanel.cpp +++ b/src/history/historypanel.cpp @@ -27,6 +27,7 @@ // Self Includes #include "historypanel.h" +#include "historypanel.moc" // Auto Includes #include "rekonq.h" @@ -67,22 +68,22 @@ void HistoryPanel::contextMenuItem(const QPoint &pos) KAction* action; action = new KAction(KIcon("tab-new"), i18n("Open"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInCurrentTab())); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInCurrentTab())); menu.addAction(action); action = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInNewTab())); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInNewTab())); menu.addAction(action); action = new KAction(KIcon("window-new"), i18n("Open in New Window"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(openInNewWindow())); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInNewWindow())); menu.addAction(action); action = new KAction(KIcon("edit-copy"), i18n("Copy Link Address"), this); - connect(action, SIGNAL(triggered()), m_treeView, SLOT(copyToClipboard())); + connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(copyToClipboard())); menu.addAction(action); - menu.exec(m_treeView->mapToGlobal(pos)); + menu.exec(panelTreeView()->mapToGlobal(pos)); } @@ -95,7 +96,7 @@ void HistoryPanel::contextMenuGroup(const QPoint &pos) connect(action, SIGNAL(triggered()), this, SLOT(openAll())); menu.addAction(action); - menu.exec(m_treeView->mapToGlobal(pos)); + menu.exec(panelTreeView()->mapToGlobal(pos)); } @@ -106,7 +107,7 @@ void HistoryPanel::contextMenuEmpty(const QPoint& /*pos*/) void HistoryPanel::openAll() { - QModelIndex index = m_treeView->currentIndex(); + QModelIndex index = panelTreeView()->currentIndex(); if (!index.isValid()) return; @@ -136,10 +137,10 @@ void HistoryPanel::setup() UrlPanel::setup(); kDebug() << "History panel..."; - m_treeView->header()->hideSection(1); + panelTreeView()->header()->hideSection(1); - const UrlFilterProxyModel *proxy = static_cast(m_treeView->model()); - m_treeView->expand(proxy->index(0, 0)); + const UrlFilterProxyModel *proxy = static_cast(panelTreeView()->model()); + panelTreeView()->expand(proxy->index(0, 0)); } diff --git a/src/history/historypanel.h b/src/history/historypanel.h index 9c9d4a4e..0a5ae216 100644 --- a/src/history/historypanel.h +++ b/src/history/historypanel.h @@ -44,7 +44,7 @@ public: explicit HistoryPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); virtual ~HistoryPanel(); -private slots: +private Q_SLOTS: virtual void contextMenuItem(const QPoint &pos); virtual void contextMenuGroup(const QPoint &pos); virtual void contextMenuEmpty(const QPoint &pos); @@ -53,7 +53,6 @@ private slots: private: virtual void setup(); - virtual QAbstractItemModel* getModel(); }; diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index dfb3289f..7f6a7f4f 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -26,6 +26,7 @@ // Self Includes #include "urlresolver.h" +#include "urlresolver.moc" // Local Includes #include "application.h" diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index 700fd460..f16c44f8 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -40,6 +40,7 @@ #include #include + class UrlSearchItem { public: @@ -123,14 +124,6 @@ Q_SIGNALS: void suggestionsReady(const UrlSearchList &, const QString &); private: - QString _typedString; - - UrlSearchList _webSearches; - UrlSearchList _qurlFromUserInput; - UrlSearchList _history; - UrlSearchList _bookmarks; - UrlSearchList _suggestions; - void computeWebSearches(); void computeHistory(); void computeQurlFromUserInput(); @@ -139,6 +132,15 @@ private: UrlSearchItem privilegedItem(UrlSearchList* list); UrlSearchList orderLists(); + + QString _typedString; + + UrlSearchList _webSearches; + UrlSearchList _qurlFromUserInput; + UrlSearchList _history; + UrlSearchList _bookmarks; + UrlSearchList _suggestions; + static QRegExp _browseRegexp; static QRegExp _searchEnginesRegexp; diff --git a/src/urlfilterproxymodel.cpp b/src/urlfilterproxymodel.cpp index b8e68342..f1d60002 100644 --- a/src/urlfilterproxymodel.cpp +++ b/src/urlfilterproxymodel.cpp @@ -27,6 +27,7 @@ // Self Includes #include "urlfilterproxymodel.h" +#include "urlfilterproxymodel.moc" UrlFilterProxyModel::UrlFilterProxyModel(QObject *parent) diff --git a/src/urlfilterproxymodel.h b/src/urlfilterproxymodel.h index f4f15395..06592c27 100644 --- a/src/urlfilterproxymodel.h +++ b/src/urlfilterproxymodel.h @@ -35,15 +35,17 @@ // Qt Includes #include + /** * QSortFilterProxyModel hides all children which parent doesn't * match the filter. This class is used to change this behavior. - * If a url matches the filter it'll be shown, even if it's parent doesn't match it. + * If a url matches the filter it'll be shown, + * even if it's parent doesn't match it. + * */ class REKONQ_TESTS_EXPORT UrlFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT - Q_DISABLE_COPY(UrlFilterProxyModel) public: UrlFilterProxyModel(QObject *parent = 0); diff --git a/src/urlpanel.cpp b/src/urlpanel.cpp index 86246fd9..cf6aec7b 100644 --- a/src/urlpanel.cpp +++ b/src/urlpanel.cpp @@ -27,6 +27,7 @@ // Self Includes #include "urlpanel.h" +#include "urlpanel.moc" // Auto Includes #include "rekonq.h" @@ -47,7 +48,7 @@ UrlPanel::UrlPanel(const QString &title, QWidget *parent, Qt::WindowFlags flags) : QDockWidget(title, parent, flags) - , m_treeView(new PanelTreeView(this)) + , _treeView(new PanelTreeView(this)) , _loaded(false) { setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); @@ -88,14 +89,14 @@ void UrlPanel::setup() searchLabel->setBuddy(search); // setup tree view - m_treeView->setUniformRowHeights(true); - m_treeView->header()->hide(); + _treeView->setUniformRowHeights(true); + _treeView->header()->hide(); // put everything together QVBoxLayout *vBoxLayout = new QVBoxLayout; vBoxLayout->setContentsMargins(0, 0, 0, 0); vBoxLayout->addLayout(searchLayout); - vBoxLayout->addWidget(m_treeView); + vBoxLayout->addWidget(_treeView); // add it to the UI ui->setLayout(vBoxLayout); @@ -104,11 +105,11 @@ void UrlPanel::setup() QAbstractItemModel *model = getModel(); UrlFilterProxyModel *proxy = new UrlFilterProxyModel(this); proxy->setSourceModel(model); - m_treeView->setModel(proxy); + _treeView->setModel(proxy); connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString))); - connect(m_treeView, SIGNAL(contextMenuItemRequested(const QPoint &)), this, SLOT(contextMenuItem(const QPoint &))); - connect(m_treeView, SIGNAL(contextMenuGroupRequested(const QPoint &)), this, SLOT(contextMenuGroup(const QPoint &))); - connect(m_treeView, SIGNAL(contextMenuEmptyRequested(const QPoint &)), this, SLOT(contextMenuEmpty(const QPoint &))); + connect(_treeView, SIGNAL(contextMenuItemRequested(const QPoint &)), this, SLOT(contextMenuItem(const QPoint &))); + connect(_treeView, SIGNAL(contextMenuGroupRequested(const QPoint &)), this, SLOT(contextMenuGroup(const QPoint &))); + connect(_treeView, SIGNAL(contextMenuEmptyRequested(const QPoint &)), this, SLOT(contextMenuEmpty(const QPoint &))); } diff --git a/src/urlpanel.h b/src/urlpanel.h index b4ca2aa5..2bf1c3fe 100644 --- a/src/urlpanel.h +++ b/src/urlpanel.h @@ -49,26 +49,26 @@ public: explicit UrlPanel(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0); virtual ~UrlPanel(); -public slots: + inline PanelTreeView *panelTreeView() const { return _treeView; }; + +public Q_SLOTS: void showing(bool); -signals: - void openUrl(const KUrl &, const Rekonq::OpenType &); - void itemHovered(const QString &); - -protected slots: +protected Q_SLOTS: virtual void contextMenuItem(const QPoint &pos) = 0; virtual void contextMenuGroup(const QPoint &pos) = 0; virtual void contextMenuEmpty(const QPoint &pos) = 0; protected: virtual void setup(); - virtual QAbstractItemModel* getModel() = 0; - PanelTreeView *m_treeView; +Q_SIGNALS: + void openUrl(const KUrl &, const Rekonq::OpenType &); + void itemHovered(const QString &); private: + PanelTreeView *_treeView; bool _loaded; }; -- cgit v1.2.1