Rename member variables.

- Move camelCase.
- Use the prefix `m_` and `mp_` for member and pointer member.
This commit is contained in:
Matthieu Gautier 2018-07-19 15:56:27 +02:00
parent e15e8cf642
commit c712a7a760
12 changed files with 88 additions and 79 deletions

View File

@ -1,7 +1,7 @@
#include "blobbuffer.h"
BlobBuffer::BlobBuffer(zim::Blob blob)
: blob(blob)
: m_blob(blob)
{
setData(blob.data(), blob.size());
}

View File

@ -7,11 +7,11 @@
class BlobBuffer : public QBuffer
{
public:
BlobBuffer(zim::Blob blob);
BlobBuffer(zim::Blob m_blob);
virtual ~BlobBuffer() = default;
private:
zim::Blob blob;
zim::Blob m_blob;
};
#endif // BLOBBUFFER_H

View File

@ -41,17 +41,17 @@ KiwixApp::KiwixApp(int& argc, char *argv[])
auto font = QFont(fontName);
setFont(font);
mainWindow = new MainWindow;
mainWindow->show();
tabWidget = mainWindow->getTabWidget();
mp_mainWindow = new MainWindow;
mp_mainWindow->show();
mp_tabWidget = mp_mainWindow->getTabWidget();
errorDialog = new QErrorMessage(mainWindow);
mp_errorDialog = new QErrorMessage(mp_mainWindow);
}
KiwixApp::~KiwixApp()
{
delete errorDialog;
delete mainWindow;
delete mp_errorDialog;
delete mp_mainWindow;
}
KiwixApp *KiwixApp::instance()
@ -63,7 +63,7 @@ void KiwixApp::openZimFile(const QString &zimfile)
{
QString zimId;
try {
zimId = library.openBook(zimfile);
zimId = m_library.openBook(zimfile);
} catch (const std::exception& e) {
showMessage("Cannot open " + zimfile + ": \n" + e.what());
return;
@ -72,10 +72,10 @@ void KiwixApp::openZimFile(const QString &zimfile)
}
void KiwixApp::openUrl(const QUrl &url, bool newTab) {
tabWidget->openUrl(url, newTab);
mp_tabWidget->openUrl(url, newTab);
}
void KiwixApp::showMessage(const QString &message)
{
errorDialog->showMessage(message);
mp_errorDialog->showMessage(message);
}

View File

@ -23,21 +23,21 @@ public:
void showMessage(const QString& message);
UrlSchemeHandler* getSchemeHandler() { return &schemeHandler; }
RequestInterceptor* getRequestInterceptor() { return &requestIntercetor; }
Library* getLibrary() { return &library; }
MainWindow* getMainWindow() { return mainWindow; }
TabWidget* getTabWidget() { return tabWidget; }
UrlSchemeHandler* getSchemeHandler() { return &m_schemeHandler; }
RequestInterceptor* getRequestInterceptor() { return &m_requestInterceptor; }
Library* getLibrary() { return &m_library; }
MainWindow* getMainWindow() { return mp_mainWindow; }
TabWidget* getTabWidget() { return mp_tabWidget; }
private:
Library library;
MainWindow* mainWindow;
TabWidget* tabWidget;
QErrorMessage* errorDialog;
Library m_library;
MainWindow* mp_mainWindow;
TabWidget* mp_tabWidget;
QErrorMessage* mp_errorDialog;
UrlSchemeHandler schemeHandler;
RequestInterceptor requestIntercetor;
UrlSchemeHandler m_schemeHandler;
RequestInterceptor m_requestInterceptor;
};
#endif // KIWIXAPP_H

View File

@ -8,8 +8,8 @@ Library::Library()
QString Library::openBook(const QString &zimPath)
{
for(auto it=readers_map.begin();
it != readers_map.end();
for(auto it=m_readersMap.begin();
it != m_readersMap.end();
it++)
{
if(QString::fromStdString(it->second->getZimFilePath()) == zimPath)
@ -19,14 +19,14 @@ QString Library::openBook(const QString &zimPath)
const std::string zimPath_ = zimPath.toLocal8Bit().constData();
auto reader = std::shared_ptr<kiwix::Reader>(new kiwix::Reader(zimPath_));
auto id = QString::fromStdString(reader->getId() + ".zim");
readers_map[id] = reader;
m_readersMap[id] = reader;
return id;
}
std::shared_ptr<kiwix::Reader> Library::getReader(const QString &zimId)
{
auto it = readers_map.find(zimId);
if (it != readers_map.end())
auto it = m_readersMap.find(zimId);
if (it != m_readersMap.end())
return it->second;
return nullptr;
}

View File

@ -12,7 +12,7 @@ public:
QString openBook(const QString& zimPath);
std::shared_ptr<kiwix::Reader> getReader(const QString& zimId);
private:
std::map<QString, std::shared_ptr<kiwix::Reader>> readers_map;
std::map<QString, std::shared_ptr<kiwix::Reader>> m_readersMap;
};
#endif // LIBRARY_H

View File

@ -9,10 +9,10 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
mp_ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->setExpanding(false);
mp_ui->setupUi(this);
mp_ui->tabWidget->tabBar()->setExpanding(false);
#if !SYSTEMTITLEBAR
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint);
#endif
@ -20,11 +20,11 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow()
{
delete ui;
delete mp_ui;
}
TabWidget* MainWindow::getTabWidget()
{
return ui->tabWidget;
return mp_ui->tabWidget;
}

View File

@ -20,7 +20,7 @@ public:
TabWidget* getTabWidget();
private:
Ui::MainWindow *ui;
Ui::MainWindow *mp_ui;
};

View File

@ -7,61 +7,69 @@
TopWidget::TopWidget(QWidget *parent) :
QToolBar(parent),
fullScreen(false)
m_fullScreen(false)
{
m_historyBackAction = new QAction(this);
m_historyBackAction->setIcon(QIcon(":/icons/back.svg"));
m_historyBackAction->setText("back");
m_historyBackAction->setToolTip("back");
connect(m_historyBackAction, &QAction::triggered, [this](){
mp_historyBackAction = new QAction(this);
mp_historyBackAction->setIcon(QIcon(":/icons/back.svg"));
mp_historyBackAction->setText("back");
mp_historyBackAction->setToolTip("back");
connect(mp_historyBackAction, &QAction::triggered, [this](){
KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Back);
});
addAction(m_historyBackAction);
m_historyForwardAction = new QAction(this);
m_historyForwardAction->setIcon(QIcon(":/icons/forward.svg"));
m_historyForwardAction->setText("forward");
m_historyForwardAction->setToolTip("forward");
connect(m_historyForwardAction, &QAction::triggered, [this](){
addAction(mp_historyBackAction);
mp_historyForwardAction = new QAction(this);
mp_historyForwardAction->setIcon(QIcon(":/icons/forward.svg"));
mp_historyForwardAction->setText("forward");
mp_historyForwardAction->setToolTip("forward");
connect(mp_historyForwardAction, &QAction::triggered, [this](){
KiwixApp::instance()->getTabWidget()->triggerWebPageAction(QWebEnginePage::Forward);
});
addAction(m_historyForwardAction);
addAction(mp_historyForwardAction);
addSeparator();
addWidget(&searchEntry);
addWidget(&m_searchEntry);
addSeparator();
#if !SYSTEMTITLEBAR
addAction(QIcon(":/icons/minimize.svg"), "minimize", parent, SLOT(showMinimized()));
#endif
fullScreenAction = addAction(QIcon(":/icons/full-screen-enter.svg"), "fullscreen", this, SLOT(toggleFullScreen()));
normalScreenAction = addAction(QIcon(":/icons/full-screen-exit.svg"), "unfullscreen", this, SLOT(toggleFullScreen()));
normalScreenAction->setVisible(false);
mp_fullScreenAction = addAction(QIcon(":/icons/full-screen-enter.svg"), "fullscreen", this, SLOT(toggleFullScreen()));
mp_normalScreenAction = addAction(QIcon(":/icons/full-screen-exit.svg"), "unfullscreen", this, SLOT(toggleFullScreen()));
mp_normalScreenAction->setVisible(false);
#if !SYSTEMTITLEBAR
addAction(QIcon(":/icons/close.svg"), "close", parent, SLOT(close()));
#endif
setMovable(false);
}
TopWidget::~TopWidget()
{
delete mp_historyBackAction;
delete mp_historyForwardAction;
delete mp_fullScreenAction;
delete mp_normalScreenAction;
}
void TopWidget::toggleFullScreen() {
if (fullScreen)
if (m_fullScreen)
parentWidget()->showNormal();
else
parentWidget()->showFullScreen();
fullScreen = !fullScreen;
fullScreenAction->setVisible(!fullScreen);
normalScreenAction->setVisible(fullScreen);
m_fullScreen = !m_fullScreen;
mp_fullScreenAction->setVisible(!m_fullScreen);
mp_normalScreenAction->setVisible(m_fullScreen);
}
void TopWidget::handleWebActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled)
{
switch (action) {
case QWebEnginePage::Back:
m_historyBackAction->setEnabled(enabled);
mp_historyBackAction->setEnabled(enabled);
break;
case QWebEnginePage::Forward:
m_historyForwardAction->setEnabled(enabled);
mp_historyForwardAction->setEnabled(enabled);
break;
default:
break;
@ -73,17 +81,17 @@ void TopWidget::mousePressEvent(QMouseEvent *event) {
if(event->button() != Qt::LeftButton)
return;
m_pCursor = event->globalPos() + frameGeometry().topLeft() - parentWidget()->frameGeometry().topLeft();
timestamp = event->timestamp();
m_cursorPos = event->globalPos() + frameGeometry().topLeft() - parentWidget()->frameGeometry().topLeft();
m_timestamp = event->timestamp();
event->accept();
}
void TopWidget::mouseMoveEvent(QMouseEvent *event) {
if(event->timestamp() <= timestamp)
if(event->timestamp() <= m_timestamp)
return;
timestamp = event->timestamp();
auto delta = event->globalPos() - m_pCursor;
m_timestamp = event->timestamp();
auto delta = event->globalPos() - m_cursorPos;
parentWidget()->move(delta);
event->accept();
}

View File

@ -10,20 +10,21 @@ class TopWidget : public QToolBar
Q_OBJECT
public:
explicit TopWidget(QWidget *parent = nullptr);
virtual ~TopWidget();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
QLineEdit searchEntry;
QAction* m_historyBackAction;
QAction* m_historyForwardAction;
QAction* fullScreenAction;
QAction* normalScreenAction;
bool fullScreen;
QPoint m_pCursor;
ulong timestamp;
QLineEdit m_searchEntry;
QAction* mp_historyBackAction;
QAction* mp_historyForwardAction;
QAction* mp_fullScreenAction;
QAction* mp_normalScreenAction;
bool m_fullScreen;
QPoint m_cursorPos;
ulong m_timestamp;
protected slots:
void toggleFullScreen();

View File

@ -35,15 +35,15 @@ QWebEngineView* WebView::createWindow(QWebEnginePage::WebWindowType type)
}
void WebView::onUrlChanged(const QUrl& url) {
if (currentHost != url.host() ) {
currentHost = url.host();
if (m_currentHost != url.host() ) {
m_currentHost = url.host();
auto app = KiwixApp::instance();
auto reader = app->getLibrary()->getReader(currentHost);
auto reader = app->getLibrary()->getReader(m_currentHost);
std::string favicon, _mimetype;
reader->getFavicon(favicon, _mimetype);
QPixmap pixmap;
pixmap.loadFromData((const uchar*)favicon.data(), favicon.size());
_icon = QIcon(pixmap);
emit iconChanged(_icon);
m_icon = QIcon(pixmap);
emit iconChanged(m_icon);
}
}

View File

@ -16,7 +16,7 @@ public:
virtual ~WebView();
bool isWebActionEnabled(QWebEnginePage::WebAction webAction) const;
const QIcon &icon() { return _icon; }
const QIcon &icon() { return m_icon; }
public slots:
void onUrlChanged(const QUrl& url);
@ -26,8 +26,8 @@ signals:
protected:
virtual QWebEngineView* createWindow(QWebEnginePage::WebWindowType type);
QString currentHost;
QIcon _icon;
QString m_currentHost;
QIcon m_icon;
};
#endif // WEBVIEW_H