Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Jul 19, 2018
1 parent ab24091 commit 9ec380c
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 103 deletions.
10 changes: 6 additions & 4 deletions e2e/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ int main(int argc, char *argv[])
const QJsonArray rootSearch = root.value("search").toArray();
const QJsonObject sources = root.value("sources").toObject();

for (const QString &sourceName : sources.keys())
for (auto it = sources.begin(); it != sources.end(); ++it)
{
const QString &sourceName = it.key();
qDebug() << "#" << "Source" << sourceName;
QJsonObject sourceJson;

Source *source = allSources.value(sourceName);
QJsonObject sites = sources.value(sourceName).toObject();
QJsonObject sites = it.value().toObject();

const QJsonObject sourceApis = sites.value("apis").toObject();
QJsonArray sourceSearch = rootSearch;
Expand All @@ -107,11 +108,12 @@ int main(int argc, char *argv[])
{ siteSearch = override.value("search").toArray(); }
}

for (const QString &apiName : siteApis.keys())
for (auto ita = siteApis.begin(); ita != siteApis.end(); ++ita)
{
const QString &apiName = ita.key();
qDebug() << "###" << "API" << apiName;
QJsonObject apiJson;
QJsonArray checks = siteApis.value(apiName).toArray();
QJsonArray checks = ita.value(api).toArray();

QJsonArray apiSearch = siteSearch;
if (checks.count() > 4)
Expand Down
2 changes: 1 addition & 1 deletion gui/src/batch/adduniquewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


AddUniqueWindow::AddUniqueWindow(Site *selected, Profile *profile, QWidget *parent)
: QDialog(parent), ui(new Ui::AddUniqueWindow), m_page(nullptr), m_sites(profile->getSites()), m_close(nullptr), m_profile(profile)
: QDialog(parent), ui(new Ui::AddUniqueWindow), m_page(nullptr), m_sites(profile->getSites()), m_close(false), m_profile(profile)
{
ui->setupUi(this);

Expand Down
4 changes: 2 additions & 2 deletions gui/src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void clearLayout(QLayout *layout)
while (layout->count() > 0)
{
QLayoutItem *item = layout->takeAt(0);
if (item->layout())
if (item->layout() != nullptr)
{
clearLayout(item->layout());
item->layout()->deleteLater();
}
if (item->widget())
if (item->widget() != nullptr)
{ item->widget()->deleteLater(); }
delete item;
}
Expand Down
28 changes: 13 additions & 15 deletions gui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#endif
#if defined(Q_OS_WIN)
#include <cfloat>
#include "windows.h"
#include "Windows.h"
#endif
#include <qmath.h>
#include <ui_mainwindow.h>
Expand Down Expand Up @@ -171,14 +171,12 @@ void mainWindow::init(const QStringList &args, const QMap<QString, QString> &par
this->deleteLater();
return;
}
else
{
QString srsc;
QStringList keys = sites.keys();
for (const QString &key : keys)
{ srsc += (!srsc.isEmpty() ? ", " : "") + key + " (" + sites.value(key)->type() + ")"; }
log(QStringLiteral("%1 source%2 found: %3").arg(sites.size()).arg(sites.size() > 1 ? "s" : "", srsc), Logger::Info);
}

QString srsc;
QStringList keys = sites.keys();
for (const QString &key : keys)
{ srsc += (!srsc.isEmpty() ? ", " : "") + key + " (" + sites.value(key)->type() + ")"; }
log(QStringLiteral("%1 source%2 found: %3").arg(sites.size()).arg(sites.size() > 1 ? "s" : "", srsc), Logger::Info);

// System tray icon
if (m_settings->value("Monitoring/enableTray", false).toBool())
Expand Down Expand Up @@ -467,7 +465,7 @@ void mainWindow::addSearchTab(searchTab *w, bool background, bool save)
if (title.isEmpty())
{ title = "New tab"; }

int pos = m_loaded ? ui->tabWidget->currentIndex() + (!m_tabs.isEmpty()) : m_tabs.count();
int pos = m_loaded ? ui->tabWidget->currentIndex() + (!m_tabs.isEmpty() ? 1 : 0) : m_tabs.count();
int index = ui->tabWidget->insertTab(pos, w, title);
m_tabs.append(w);

Expand All @@ -486,7 +484,7 @@ void mainWindow::addSearchTab(searchTab *w, bool background, bool save)

bool mainWindow::saveTabs(const QString &filename)
{
return TabsLoader::save(filename, m_tabs, reinterpret_cast<searchTab*>(m_currentTab));
return TabsLoader::save(filename, m_tabs, qobject_cast<searchTab*>(m_currentTab));
}
bool mainWindow::loadTabs(const QString &filename)
{
Expand Down Expand Up @@ -1184,7 +1182,7 @@ void mainWindow::getAll(bool all)
error(this, tr("You did not specify a save folder!"));
return;
}
else if (m_settings->value("Save/filename").toString().isEmpty())
if (m_settings->value("Save/filename").toString().isEmpty())
{
error(this, tr("You did not specify a filename!"));
return;
Expand Down Expand Up @@ -1537,7 +1535,7 @@ void mainWindow::getAllImages()
// Check whether we need to get the tags first (for the filename) or if we can just download the images directly
// TODO(Bionus): having one batch needing it currently causes all batches to need it, should mae it batch (Downloader) dependent
m_mustGetTags = needExactTags(m_settings);
for (int f = 0; f < m_groupBatchs.size() && !m_mustGetTags; f++)
for (int f = 0; f < m_groupBatchs.size() && m_mustGetTags == 0; f++)
{
Filename fn(m_groupBatchs[f].filename);
Site *site = m_groupBatchs[f].site;
Expand All @@ -1547,7 +1545,7 @@ void mainWindow::getAllImages()
if (need != 0)
m_mustGetTags = need;
}
for (int f = 0; f < m_batchs.size() && !m_mustGetTags; f++)
for (int f = 0; f < m_batchs.size() && m_mustGetTags == 0; f++)
{
Filename fn(m_batchs[f].filename);
Site *site = m_batchs[f].site;
Expand All @@ -1558,7 +1556,7 @@ void mainWindow::getAllImages()
m_mustGetTags = need;
}

if (m_mustGetTags)
if (m_mustGetTags != 0)
log(QStringLiteral("Downloading images details."), Logger::Info);
else
log(QStringLiteral("Downloading images directly."), Logger::Info);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class mainWindow : public QMainWindow
Profile *m_profile;
QList<Favorite> &m_favorites;
int m_getAllDownloaded, m_getAllExists, m_getAllIgnored, m_getAllIgnoredPre, m_getAll404s, m_getAllErrors, m_getAllSkipped, m_getAllLimit, m_downloads, m_waitForLogin;
int m_allow, m_loaded, m_getAll;
bool m_allow, m_loaded, m_getAll;
int m_mustGetTags;
int m_forcedTab;
QSettings *m_settings;
Expand Down
8 changes: 5 additions & 3 deletions gui/src/settings/optionswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ optionsWindow::optionsWindow(Profile *profile, QWidget *parent)
QStringList types = QStringList() << "text" << "icon" << "both" << "hide";
ui->comboSources->setCurrentIndex(types.indexOf(settings->value("Sources/Types", "icon").toString()));
int i = settings->value("Sources/Letters", 3).toInt();
ui->comboSourcesLetters->setCurrentIndex((i < 0)+(i < -1));
ui->comboSourcesLetters->setCurrentIndex((i < 0 ? 1 : 0) + (i < -1 ? 1 : 0));
ui->spinSourcesLetters->setValue(i < 0 ? 3 : i);
ui->checkPreloadAllTabs->setChecked(settings->value("preloadAllTabs", false).toBool());

Expand Down Expand Up @@ -643,7 +643,7 @@ void optionsWindow::moveDownWebService(int id)
swapWebServices(i, i + 1);
}

int sortByOrder(const ReverseSearchEngine &a, const ReverseSearchEngine &b)
bool sortByOrder(const ReverseSearchEngine &a, const ReverseSearchEngine &b)
{ return a.order() < b.order(); }
void optionsWindow::swapWebServices(int a, int b)
{
Expand Down Expand Up @@ -787,8 +787,10 @@ void treeWidgetRec(int depth, bool& found, int& index, QTreeWidgetItem *current,
}
}

void optionsWindow::updateContainer(QTreeWidgetItem *current, QTreeWidgetItem *)
void optionsWindow::updateContainer(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
Q_UNUSED(previous);

bool found = false;
int index = 0;

Expand Down
2 changes: 1 addition & 1 deletion gui/src/settings/optionswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class optionsWindow : public QDialog
void setFont(QLineEdit *lineEdit);

public slots:
void updateContainer(QTreeWidgetItem *, QTreeWidgetItem *);
void updateContainer(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_comboSourcesLetters_currentIndexChanged(int);
void on_buttonFolder_clicked();
void on_buttonFolderFavorites_clicked();
Expand Down
4 changes: 3 additions & 1 deletion gui/src/sources/sourcessettingswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ void SourcesSettingsWindow::testLogin()
m_site->login(true);
}

void SourcesSettingsWindow::loginTested(Site*, Site::LoginResult result)
void SourcesSettingsWindow::loginTested(Site *site, Site::LoginResult result)
{
Q_UNUSED(site);

switch (result)
{
case Site::LoginResult::Success:
Expand Down
2 changes: 1 addition & 1 deletion gui/src/sources/sourcessettingswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SourcesSettingsWindow : public QDialog
void addHeader();
void save();
void testLogin();
void loginTested(Site*, Site::LoginResult);
void loginTested(Site *site, Site::LoginResult result);

signals:
void siteDeleted(const QString &);
Expand Down
16 changes: 2 additions & 14 deletions gui/src/sources/sourceswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,13 @@
#include "ui/QBouton.h"


sourcesWindow::sourcesWindow(Profile *profile, const QList<Site*> &selected, QWidget *parent)
: QDialog(parent), ui(new Ui::sourcesWindow), m_profile(profile), m_selected(selected), m_sites(profile->getSites()), m_sources(profile->getSources()), m_checkForSourceReply(nullptr)
sourcesWindow::sourcesWindow(Profile *profile, QList<Site*> selected, QWidget *parent)
: QDialog(parent), ui(new Ui::sourcesWindow), m_profile(profile), m_selected(std::move(selected)), m_sites(profile->getSites()), m_sources(profile->getSources()), m_checkForSourceReply(nullptr)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
restoreGeometry(m_profile->getSettings()->value("Sources/geometry").toByteArray());

bool checkall = true;
for (int i = 0; i < selected.count(); i++)
{
if (!selected.at(i))
{
checkall = false;
break;
}
}
if (checkall)
{ ui->checkBox->setChecked(true); }

addCheckboxes();

ui->gridLayout->setColumnStretch(0, 1);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/sources/sourceswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class sourcesWindow : public QDialog
Q_OBJECT

public:
explicit sourcesWindow(Profile *profile, const QList<Site*> &selected, QWidget *parent = nullptr);
explicit sourcesWindow(Profile *profile, QList<Site*> selected, QWidget *parent = nullptr);
~sourcesWindow() override;

public slots:
Expand Down
6 changes: 3 additions & 3 deletions gui/src/tabs/search-tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ QStringList searchTab::reasonsToFail(Page* page, const QStringList &completion,
if (c > 0)
{
QStringList res = results.values(), cl = clean.values();
*meant = "<a href=\"" + cl.join(" ").toHtmlEscaped() + "\" style=\"color:black;text-decoration:none;\">"+res.join(" ")+"</a>";
*meant = QString(R"(<a href="%1" style="color:black;text-decoration:none;">%2</a>)").arg(cl.join(" ").toHtmlEscaped(), res.join(" "));
}
}

Expand Down Expand Up @@ -869,7 +869,7 @@ QString getImageAlreadyExists(Image *img, Profile *profile)
const QString path = settings->value("Save/path").toString().replace("\\", "/");
const QString fn = settings->value("Save/filename").toString();

if (!Filename(fn).needExactTags(img->parentSite()))
if (Filename(fn).needExactTags(img->parentSite()) == 0)
{
QStringList files = img->path(fn, path, 0, true, false, true, true, true);
for (const QString &file : files)
Expand Down Expand Up @@ -1162,7 +1162,7 @@ void searchTab::webZoom(int id)

void searchTab::openImage(const QSharedPointer<Image> &image)
{
if (m_settings->value("Zoom/singleWindow", false).toBool() && m_lastZoomWindow)
if (m_settings->value("Zoom/singleWindow", false).toBool() && !m_lastZoomWindow.isNull())
{
m_lastZoomWindow->reuse(m_images, image, image->page()->site());
m_lastZoomWindow->activateWindow();
Expand Down
18 changes: 7 additions & 11 deletions gui/src/ui/fixed-size-grid-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,16 @@ QLayoutItem *FixedSizeGridLayout::takeAt(int index)

int FixedSizeGridLayout::horizontalSpacing() const
{
if (m_hSpace >= 0) {
return m_hSpace;
} else {
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
}
return m_hSpace >= 0
? m_hSpace
: smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
}

int FixedSizeGridLayout::verticalSpacing() const
{
if (m_vSpace >= 0) {
return m_vSpace;
} else {
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
}
return m_vSpace >= 0
? m_vSpace
: smartSpacing(QStyle::PM_LayoutVerticalSpacing);
}

Qt::Orientations FixedSizeGridLayout::expandingDirections() const
Expand Down Expand Up @@ -157,7 +153,7 @@ int FixedSizeGridLayout::doLayout(QRect rect, bool testOnly) const
int FixedSizeGridLayout::smartSpacing(QStyle::PixelMetric pm) const
{
QObject *parent = this->parent();
if (!parent)
if (parent == nullptr)
return -1;

if (parent->isWidgetType())
Expand Down
16 changes: 9 additions & 7 deletions gui/src/ui/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ void TextEdit::setText(const QString &text)

void TextEdit::setCompleter(QCompleter *completer)
{
if (!completer)
if (completer == nullptr)
return;

// Disconnect the previous completer
if (c)
if (c != nullptr)
QObject::disconnect(c, nullptr, this, nullptr);

// Set the new completer and connect it to the field
Expand Down Expand Up @@ -169,15 +169,15 @@ QString TextEdit::textUnderCursor() const

void TextEdit::focusInEvent(QFocusEvent *e)
{
if (c)
if (c != nullptr)
c->setWidget(this);

QTextEdit::focusInEvent(e);
}

void TextEdit::keyPressEvent(QKeyEvent *e)
{
if (c && c->popup()->isVisible())
if (c != nullptr && c->popup()->isVisible())
{
// The following keys are forwarded by the completer to the widget
QString curr = c->popup()->currentIndex().data().toString(), under = textUnderCursor();
Expand All @@ -204,7 +204,7 @@ void TextEdit::keyPressEvent(QKeyEvent *e)
}

const bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space); // CTRL+Space
if (!c || !isShortcut) // do not process the shortcut when we have a completer
if (c == nullptr || !isShortcut) // do not process the shortcut when we have a completer
{
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
{
Expand All @@ -216,7 +216,7 @@ void TextEdit::keyPressEvent(QKeyEvent *e)
doColor();

const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
if (!c || (ctrlOrShift && e->text().isEmpty()))
if (c == nullptr || (ctrlOrShift && e->text().isEmpty()))
return;

static QString eow(" ");
Expand All @@ -237,8 +237,10 @@ void TextEdit::keyPressEvent(QKeyEvent *e)
c->complete(cr);
}

void TextEdit::customContextMenuRequested(QPoint)
void TextEdit::customContextMenuRequested(const QPoint &pos)
{
Q_UNUSED(pos);

auto *menu = new QMenu(this);
auto *favs = new QMenu(tr("Favorites"), menu);
auto *favsGroup = new QActionGroup(favs);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/ui/textedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TextEdit : public QTextEdit
private slots:
void insertCompletion(const QString &completion);
void insertFav(QAction *act);
void customContextMenuRequested(QPoint);
void customContextMenuRequested(const QPoint &pos);
void setFavorite();
void unsetFavorite();
void setKfl();
Expand Down
7 changes: 4 additions & 3 deletions gui/src/ui/verticalscrollarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ void VerticalScrollArea::setScrollEnabled(bool enabled)

void VerticalScrollArea::updateWidgetSize()
{
if (widget())
QWidget *w = widget();
if (w != nullptr)
{
int maxWidth = width();
if (m_scrollEnabled && verticalScrollBar()->isVisible())
maxWidth -= verticalScrollBar()->width();
widget()->setMaximumWidth(maxWidth);
w->setMaximumWidth(maxWidth);

widget()->setMaximumHeight(m_scrollEnabled ? QWIDGETSIZE_MAX : height());
w->setMaximumHeight(m_scrollEnabled ? QWIDGETSIZE_MAX : height());
}
}

Expand Down
Loading

0 comments on commit 9ec380c

Please sign in to comment.