From 34a83c6b491ba6f9426928d3d23deb839d0acdc5 Mon Sep 17 00:00:00 2001 From: Lukas Holecek <hluk@email.cz> Date: Sun, 22 Nov 2020 07:33:50 +0100 Subject: [PATCH] Refactor strict compiler warnings Fixes compiler warnings. Sets strict compiler flags only for non-generated non-external sources. Removes "-Werror" compiler flag so that compilation doesn't stop after a warning. The flag makes development very difficult. Occasionally, it's a good idea to check CI build output -- GitHub Actions list the warnings very well. --- CMakeLists.txt | 105 +++++++++--------- plugins/CMakeLists.txt | 6 +- plugins/itemencrypted/itemencrypted.cpp | 2 +- plugins/itemfakevim/CMakeLists.txt | 30 +---- plugins/itemfakevim/itemfakevim.cpp | 2 +- plugins/itempinned/itempinned.cpp | 2 +- plugins/itemsync/itemsync.cpp | 2 +- plugins/itemtags/itemtags.cpp | 2 +- qxt/qxtglobalshortcut_mac.cpp | 10 +- qxt/qxtglobalshortcut_win.cpp | 4 +- qxt/qxtglobalshortcut_x11.cpp | 4 +- src/CMakeLists.txt | 14 ++- src/app/clipboardserver.cpp | 6 +- src/common/actionhandlerenums.h | 4 +- src/common/actiontablemodel.cpp | 1 - src/common/config.cpp | 2 +- src/gui/actiondialog.cpp | 4 +- src/gui/actionhandlerdialog.cpp | 6 +- src/gui/clipboardbrowser.cpp | 8 +- src/gui/icon_list.h | 2 +- src/gui/iconfactory.cpp | 9 +- src/gui/mainwindow.cpp | 6 +- src/gui/menuitems.cpp | 2 +- src/gui/notification.cpp | 2 +- src/gui/theme.cpp | 17 ++- src/platform/win/winplatform.cpp | 2 +- .../x11/systemclipboard/waylandclipboard.cpp | 2 +- src/platform/x11/x11platform.cpp | 2 +- src/scriptable/scriptable.cpp | 14 +-- src/scriptable/scriptableproxy.cpp | 21 ++-- src/tests/test_utils.h | 10 +- src/tests/tests.cpp | 48 ++++---- utils/update_icon_font.py | 2 +- 33 files changed, 173 insertions(+), 180 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc6315d65..417c13ff0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,64 +64,63 @@ endif() if (PEDANTIC) if (CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wall \ - -Wsuggest-override \ - -Wlogical-op \ - -Wnoexcept \ - -Wstrict-null-sentinel \ - ") + list(APPEND copyq_pedantic_flags + -Wextra -Wall + -Wsuggest-override + -Wlogical-op + -Wnoexcept + -Wstrict-null-sentinel + ) else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything \ - -Winconsistent-missing-override \ - ") - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -Wno-c++98-compat \ - -Wno-c++98-compat-pedantic \ - -Wno-shadow-field-in-constructor \ - -Wno-weak-vtables \ - -Wno-disabled-macro-expansion \ - -fcomment-block-commands=retval \ - ") - - # Disable errors from moc-generated files. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -Wno-undefined-reinterpret-cast \ - -Wno-missing-prototypes \ - ") - - # Disable errors from qrc-generated files. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -Wno-exit-time-destructors \ - -Wno-global-constructors \ - ") + list(APPEND copyq_pedantic_flags + -Weverything + -Winconsistent-missing-override + ) + + list(APPEND copyq_pedantic_flags + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-disabled-macro-expansion + -Wno-exit-time-destructors + -Wno-extra-semi-stmt + -Wno-redundant-parens + -Wno-shadow-field + -Wno-shadow-field-in-constructor + -Wno-shorten-64-to-32 + -Wno-sign-conversion + -Wno-suggest-destructor-override + -Wno-unknown-warning-option + -Wno-used-but-marked-unused + -Wno-weak-vtables + -fcomment-block-commands=retval + ) endif() - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -pedantic -Werror \ - -Wcast-align \ - -Wctor-dtor-privacy \ - -Wdisabled-optimization \ - -Wformat=2 \ - -Winit-self \ - -Wmissing-declarations \ - -Wmissing-include-dirs \ - -Wold-style-cast \ - -Woverloaded-virtual \ - -Wredundant-decls \ - -Wstrict-overflow=4 \ - -Wundef \ - ") - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -Wno-padded \ - -Wno-switch-enum \ - ") + list(APPEND copyq_pedantic_flags + -pedantic + -Wcast-align + -Wctor-dtor-privacy + -Wdisabled-optimization + -Wformat=2 + -Winit-self + -Wmissing-declarations + -Wmissing-include-dirs + -Wold-style-cast + -Woverloaded-virtual + -Wredundant-decls + -Wstrict-overflow=4 + -Wundef + ) + + list(APPEND copyq_pedantic_flags + -Wno-padded + -Wno-switch-enum + ) # Disable Q_OBJECT macro warnings. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -Wno-unused-member-function \ - ") + list(APPEND copyq_pedantic_flags + -Wno-unused-member-function + ) endif() if(WITH_TESTS) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 9a20f4595..d6209844e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,7 +1,7 @@ macro (copyq_add_plugin copyq_pkg) - file(GLOB copyq_plugin_SOURCES ${copyq_plugin_${copyq_pkg}_SOURCES} + ${copyq_plugin_${copyq_pkg}_external_SOURCES} *.cpp ../../src/item/itemwidget.cpp ) @@ -10,6 +10,10 @@ macro (copyq_add_plugin copyq_pkg) *.ui ) + set_source_files_properties( + ${copyq_plugin_${copyq_pkg}_SOURCES} PROPERTIES + COMPILE_OPTIONS "${copyq_pedantic_flags}") + if (WITH_TESTS) file(GLOB copyq_plugin_SOURCES ${copyq_plugin_SOURCES} tests/*.cpp) endif (WITH_TESTS) diff --git a/plugins/itemencrypted/itemencrypted.cpp b/plugins/itemencrypted/itemencrypted.cpp index edefaca6e..6be260dce 100644 --- a/plugins/itemencrypted/itemencrypted.cpp +++ b/plugins/itemencrypted/itemencrypted.cpp @@ -756,7 +756,7 @@ QObject *ItemEncryptedLoader::tests(const TestInterfacePtr &test) const QObject *tests = new ItemEncryptedTests(test); return tests; #else - Q_UNUSED(test); + Q_UNUSED(test) return nullptr; #endif } diff --git a/plugins/itemfakevim/CMakeLists.txt b/plugins/itemfakevim/CMakeLists.txt index 5480d20c1..bf80f6e9f 100644 --- a/plugins/itemfakevim/CMakeLists.txt +++ b/plugins/itemfakevim/CMakeLists.txt @@ -1,6 +1,7 @@ file(GLOB copyq_plugin_itemfakevim_SOURCES - ${copyq_plugin_itemfakevim_SOURCES} ../../src/item/itemwidgetwrapper.cpp + ) +file(GLOB copyq_plugin_itemfakevim_external_SOURCES fakevim/*.cpp fakevim/utils/*.cpp ) @@ -15,30 +16,3 @@ set(copyq_plugin_itemfakevim_DEFINITIONS set(copyq_plugin_itemfakevim_RESOURCES itemfakevim.qrc) copyq_add_plugin(itemfakevim) - -# Disable warnings for 3rd-party source code. -if (PEDANTIC) - if (CMAKE_COMPILER_IS_GNUCXX) - set(IGNORE_PEDANTIC_FLAGS "-Wno-suggest-override") - else() - set(IGNORE_PEDANTIC_FLAGS "-Wno-unused-macros") - endif() - - set_source_files_properties( - fakevim/fakevimhandler.cpp - fakevim/fakevimactions.cpp - PROPERTIES COMPILE_FLAGS - "\ - -Wno-shorten-64-to-32 \ - -Wno-sign-conversion \ - -Wno-conversion \ - -Wno-unreachable-code \ - -Wno-documentation-unknown-command \ - -Wno-shadow \ - -Wno-missing-declarations \ - -Wno-strict-overflow \ - -Wno-zero-as-null-pointer-constant \ - ${IGNORE_PEDANTIC_FLAGS} \ - ") -endif() - diff --git a/plugins/itemfakevim/itemfakevim.cpp b/plugins/itemfakevim/itemfakevim.cpp index 3e53aa24f..9d9a69ced 100644 --- a/plugins/itemfakevim/itemfakevim.cpp +++ b/plugins/itemfakevim/itemfakevim.cpp @@ -808,7 +808,7 @@ QObject *ItemFakeVimLoader::tests(const TestInterfacePtr &test) const tests->setProperty("CopyQ_test_settings", settings); return tests; #else - Q_UNUSED(test); + Q_UNUSED(test) return nullptr; #endif } diff --git a/plugins/itempinned/itempinned.cpp b/plugins/itempinned/itempinned.cpp index 831ab369e..738d37c78 100644 --- a/plugins/itempinned/itempinned.cpp +++ b/plugins/itempinned/itempinned.cpp @@ -369,7 +369,7 @@ QObject *ItemPinnedLoader::tests(const TestInterfacePtr &test) const QObject *tests = new ItemPinnedTests(test); return tests; #else - Q_UNUSED(test); + Q_UNUSED(test) return nullptr; #endif } diff --git a/plugins/itemsync/itemsync.cpp b/plugins/itemsync/itemsync.cpp index 27a309cca..a617a1466 100644 --- a/plugins/itemsync/itemsync.cpp +++ b/plugins/itemsync/itemsync.cpp @@ -783,7 +783,7 @@ QObject *ItemSyncLoader::tests(const TestInterfacePtr &test) const tests->setProperty("CopyQ_test_settings", settings); return tests; #else - Q_UNUSED(test); + Q_UNUSED(test) return nullptr; #endif } diff --git a/plugins/itemtags/itemtags.cpp b/plugins/itemtags/itemtags.cpp index 4e6f41e56..e9860191d 100644 --- a/plugins/itemtags/itemtags.cpp +++ b/plugins/itemtags/itemtags.cpp @@ -679,7 +679,7 @@ QObject *ItemTagsLoader::tests(const TestInterfacePtr &test) const tests->setProperty("CopyQ_test_settings", settings); return tests; #else - Q_UNUSED(test); + Q_UNUSED(test) return nullptr; #endif } diff --git a/qxt/qxtglobalshortcut_mac.cpp b/qxt/qxtglobalshortcut_mac.cpp index 16be4d6f8..bac7fd8c8 100644 --- a/qxt/qxtglobalshortcut_mac.cpp +++ b/qxt/qxtglobalshortcut_mac.cpp @@ -43,8 +43,8 @@ static bool qxt_mac_handler_installed = false; OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data) { - Q_UNUSED(nextHandler); - Q_UNUSED(data); + Q_UNUSED(nextHandler) + Q_UNUSED(data) if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed) { EventHotKeyID keyID; @@ -76,9 +76,9 @@ quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifier bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType, void * message, long * result) { - Q_UNUSED(result); - Q_UNUSED(message); - Q_UNUSED(eventType); + Q_UNUSED(result) + Q_UNUSED(message) + Q_UNUSED(eventType) return false; } diff --git a/qxt/qxtglobalshortcut_win.cpp b/qxt/qxtglobalshortcut_win.cpp index 4876b72e5..0acf55c99 100644 --- a/qxt/qxtglobalshortcut_win.cpp +++ b/qxt/qxtglobalshortcut_win.cpp @@ -39,8 +39,8 @@ bool QxtGlobalShortcutPrivate::eventFilter(void* message) bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType, void * message, long * result) { - Q_UNUSED(eventType); - Q_UNUSED(result); + Q_UNUSED(eventType) + Q_UNUSED(result) #endif MSG* msg = static_cast<MSG*>(message); if (msg->message == WM_HOTKEY) diff --git a/qxt/qxtglobalshortcut_x11.cpp b/qxt/qxtglobalshortcut_x11.cpp index b654fd85d..0f22c9f21 100644 --- a/qxt/qxtglobalshortcut_x11.cpp +++ b/qxt/qxtglobalshortcut_x11.cpp @@ -79,7 +79,7 @@ public: static int qxtX11ErrorHandler(Display* display, XErrorEvent *event) { - Q_UNUSED(display); + Q_UNUSED(display) switch (event->error_code) { case BadAccess: @@ -227,7 +227,7 @@ bool QxtGlobalShortcutPrivate::eventFilter(void* message) bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType, void * message, long * result) { - Q_UNUSED(result); + Q_UNUSED(result) xcb_key_press_event_t *kev = nullptr; if (eventType == "xcb_generic_event_t") { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e8a832ea..916367941 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,15 @@ add_definitions(${Qt5Widgets_DEFINITIONS}) include(platform/platform.cmake) +# Compile with tests? +if (WITH_TESTS) + file(GLOB copyq_SOURCES ${copyq_SOURCES} tests/*.cpp) +endif() + +set_source_files_properties( + ${copyq_SOURCES} PROPERTIES + COMPILE_OPTIONS "${copyq_pedantic_flags}") + # Qxt - global shortcuts if (USE_QXT) set(copyq_SOURCES ${copyq_SOURCES} @@ -30,11 +39,6 @@ if (USE_QXT) add_definitions( -DQXT_STATIC ) endif() -# Compile with tests? -if (WITH_TESTS) - file(GLOB copyq_SOURCES ${copyq_SOURCES} tests/*.cpp) -endif() - # translations file(GLOB copyq_TRANSLATIONS ../translations/*.ts) diff --git a/src/app/clipboardserver.cpp b/src/app/clipboardserver.cpp index 3f76cde1e..c3a3b95b8 100644 --- a/src/app/clipboardserver.cpp +++ b/src/app/clipboardserver.cpp @@ -591,8 +591,8 @@ void ClipboardServer::onNotificationButtonClicked(const NotificationButton &butt void ClipboardServer::createGlobalShortcut(const QKeySequence &shortcut, const Command &command) { #ifdef NO_GLOBAL_SHORTCUTS - Q_UNUSED(shortcut); - Q_UNUSED(command); + Q_UNUSED(shortcut) + Q_UNUSED(command) #else auto s = new QxtGlobalShortcut(shortcut, this); if (!s->isValid()) { @@ -721,7 +721,7 @@ void ClipboardServer::loadSettings() void ClipboardServer::shortcutActivated(QxtGlobalShortcut *shortcut) { #ifdef NO_GLOBAL_SHORTCUTS - Q_UNUSED(shortcut); + Q_UNUSED(shortcut) #else m_ignoreKeysTimer.start(); diff --git a/src/common/actionhandlerenums.h b/src/common/actionhandlerenums.h index b8d0e0ae8..ca09ccd1d 100644 --- a/src/common/actionhandlerenums.h +++ b/src/common/actionhandlerenums.h @@ -1,6 +1,8 @@ #ifndef ACTIONHANDLERENUMS_H #define ACTIONHANDLERENUMS_H +#include <QtGlobal> + enum class ActionState { Starting, Running, @@ -22,7 +24,7 @@ enum { namespace ActionHandlerRole { enum { - sort, + sort = Qt::UserRole, status, id }; diff --git a/src/common/actiontablemodel.cpp b/src/common/actiontablemodel.cpp index f27e4f47a..5d462c2f1 100644 --- a/src/common/actiontablemodel.cpp +++ b/src/common/actiontablemodel.cpp @@ -206,7 +206,6 @@ QVariant ActionTableModel::data(const QModelIndex &index, int role) const } } } else if (role >= Qt::UserRole) { - role -= Qt::UserRole; if (role == ActionHandlerRole::sort) { const int row = index.row(); const int column = index.column(); diff --git a/src/common/config.cpp b/src/common/config.cpp index a841332b8..0f7a287e8 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -272,7 +272,7 @@ void moveToCurrentWorkspace(QWidget *w) w->show(); } #else - Q_UNUSED(w); + Q_UNUSED(w) #endif } diff --git a/src/gui/actiondialog.cpp b/src/gui/actiondialog.cpp index 02a77362b..65ca834d4 100644 --- a/src/gui/actiondialog.cpp +++ b/src/gui/actiondialog.cpp @@ -73,9 +73,9 @@ ActionDialog::ActionDialog(QWidget *parent) ui->setupUi(this); ui->comboBoxCommands->setFont( ui->commandEdit->commandFont() ); - auto shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_P), this); + auto shortcut = new QShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_P), this); connect(shortcut, &QShortcut::activated, this, &ActionDialog::previousCommand); - shortcut = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_N), this); + shortcut = new QShortcut(QKeySequence(Qt::ControlModifier | Qt::Key_N), this); connect(shortcut, &QShortcut::activated, this, &ActionDialog::nextCommand); connect(ui->buttonBox, &QDialogButtonBox::clicked, diff --git a/src/gui/actionhandlerdialog.cpp b/src/gui/actionhandlerdialog.cpp index 98051e115..8bac9c04a 100644 --- a/src/gui/actionhandlerdialog.cpp +++ b/src/gui/actionhandlerdialog.cpp @@ -32,7 +32,7 @@ void terminateSelectedActions(QItemSelectionModel *selectionModel, ActionHandler { QSet<int> ids; for ( const auto &index : selectionModel->selectedIndexes() ) { - const int actionId = index.data(Qt::UserRole + ActionHandlerRole::id).toInt(); + const int actionId = index.data(ActionHandlerRole::id).toInt(); ids.insert(actionId); } for (const int id : ids) @@ -44,7 +44,7 @@ void updateTerminateButton(QItemSelectionModel *selectionModel, QAbstractItemMod for ( const auto &index : selectionModel->selectedIndexes() ) { const int row = index.row(); const auto statusIndex = model->index(row, 0); - const auto state = static_cast<ActionState>(statusIndex.data(Qt::UserRole + ActionHandlerRole::status).toInt()); + const auto state = static_cast<ActionState>(statusIndex.data(ActionHandlerRole::status).toInt()); if (state == ActionState::Running || state == ActionState::Starting) { button->setEnabled(true); return; @@ -65,7 +65,7 @@ ActionHandlerDialog::ActionHandlerDialog(ActionHandler *actionHandler, QAbstract auto proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(model); proxyModel->setDynamicSortFilter(true); - proxyModel->setSortRole(Qt::UserRole + ActionHandlerRole::sort); + proxyModel->setSortRole(ActionHandlerRole::sort); proxyModel->setFilterKeyColumn(ActionHandlerColumn::name); ui->tableView->setModel(proxyModel); diff --git a/src/gui/clipboardbrowser.cpp b/src/gui/clipboardbrowser.cpp index cb924011e..94947580d 100644 --- a/src/gui/clipboardbrowser.cpp +++ b/src/gui/clipboardbrowser.cpp @@ -715,10 +715,10 @@ void ClipboardBrowser::dragDropScroll() const auto y = mapFromGlobal(QCursor::pos()).y(); const auto h = viewport()->contentsRect().height(); - const auto d = h / 4; + const auto diff = h / 4; const auto scrollAmount = - (h < y + d) ? (y + d - h) / 4 - : (y < d) ? -(d - y) / 4 + (h < y + diff) ? (y + diff - h) / 4 + : (y < diff) ? -(diff - y) / 4 : 0; if (scrollAmount != 0) { @@ -824,7 +824,7 @@ QPixmap ClipboardBrowser::renderItemPreview(const QModelIndexList &indexes, int return QPixmap(); const auto ratio = pixelRatio(this); - const int frameLineWidth = std::ceil(2 * ratio); + const int frameLineWidth = static_cast<int>( std::ceil(2 * ratio) ); const auto height = qMin(maxHeight, h + s + 2 * frameLineWidth); const auto width = qMin(maxWidth, viewport()->contentsRect().width() + 2 * frameLineWidth); diff --git a/src/gui/icon_list.h b/src/gui/icon_list.h index 3c0035327..c709c2d54 100644 --- a/src/gui/icon_list.h +++ b/src/gui/icon_list.h @@ -1,7 +1,7 @@ // This file is generated with "update_icon_font.py" from FontAwesome's metadata. struct Icon { - unsigned int unicode; + unsigned short unicode; bool isBrand; const char *searchTerms; }; diff --git a/src/gui/iconfactory.cpp b/src/gui/iconfactory.cpp index ed2158548..836a78937 100644 --- a/src/gui/iconfactory.cpp +++ b/src/gui/iconfactory.cpp @@ -56,7 +56,10 @@ const int lightThreshold = 100; bool sessionIconTagEnabledFlag = true; -QPointer<QObject> activePaintDevice; +QPointer<QObject> &activePaintDevice() { + static QPointer<QObject> activePaintDevice; + return activePaintDevice; +} QIcon fromTheme(const QString &name) { @@ -355,7 +358,7 @@ QColor colorForMode(QPainter *painter, QIcon::Mode mode) { auto parent = painter ? dynamic_cast<QWidget*>(painter->device()) - : qobject_cast<QWidget*>(activePaintDevice.data()); + : qobject_cast<QWidget*>(activePaintDevice().data()); const bool selected = (mode == QIcon::Active || mode == QIcon::Selected); QColor color = parent ? getDefaultIconColor(*parent, selected) : Qt::darkGray; @@ -661,7 +664,7 @@ QIcon appIcon() void setActivePaintDevice(QObject *device) { - activePaintDevice = device; + activePaintDevice() = device; } QColor getDefaultIconColor(const QWidget &widget, bool selected) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 914e2f8f6..7d7de288f 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -760,10 +760,10 @@ void MainWindow::createMenu() // Open Item Menu createAction( Actions::ItemMenu, &MainWindow::showContextMenu, nullptr ); - for (auto menu : menuBar()->findChildren<QMenu*>()) { - connect( menu, &QMenu::aboutToShow, + for (auto subMenu : menuBar()->findChildren<QMenu*>()) { + connect( subMenu, &QMenu::aboutToShow, this, &MainWindow::disableHideWindowOnUnfocus ); - connect( menu, &QMenu::aboutToHide, + connect( subMenu, &QMenu::aboutToHide, this, &MainWindow::enableHideWindowOnUnfocus ); } } diff --git a/src/gui/menuitems.cpp b/src/gui/menuitems.cpp index 16dfdfd2b..c90437f10 100644 --- a/src/gui/menuitems.cpp +++ b/src/gui/menuitems.cpp @@ -32,7 +32,7 @@ void addMenuItem( const QKeySequence &shortcut, const QString &iconName, ushort iconId = 0) { Q_ASSERT(items.size() == id && "Menu item index must be same as its ID."); - Q_UNUSED(id); + Q_UNUSED(id) MenuItem item; item.text = text; diff --git a/src/gui/notification.cpp b/src/gui/notification.cpp index 0eb2d5a62..7aaf2d74b 100644 --- a/src/gui/notification.cpp +++ b/src/gui/notification.cpp @@ -189,7 +189,7 @@ void Notification::updateIcon() auto pixmap = iconId == 0 ? QPixmap(m_icon) - : createPixmap(iconId, color, height * ratio); + : createPixmap(iconId, color, static_cast<int>(height * ratio)); pixmap.setDevicePixelRatio(ratio); diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 4fc3e715f..dd72ebfd4 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -42,17 +42,19 @@ double normalizeFactor(double value) return qBound( 0.0, value, 1.0 ); } -int normalizeColorValue(float value) +int normalizeColorValue(int value) { - return qBound( 0, static_cast<int>(value), 255 ); + return qBound(0, value, 255); } /// Add RGB components properly. int addColor(int c1, float multiply, int c2) { + const float f1 = static_cast<float>(c1); + const float f2 = static_cast<float>(c2); return multiply > 0.0f - ? static_cast<int>( std::sqrt(c1*c1 + multiply * c2*c2) ) - : c1 + static_cast<int>(multiply * c2); + ? static_cast<int>( std::sqrt(f1*f1 + multiply * f2*f2) ) + : c1 + static_cast<int>(multiply * f2); } void addColor( @@ -84,8 +86,11 @@ void addColor( *r = normalizeColorValue( addColor(*r, x, toAdd.red()) ); *g = normalizeColorValue( addColor(*g, x, toAdd.green()) ); *b = normalizeColorValue( addColor(*b, x, toAdd.blue()) ); - if (multiply > 0.0f) - *a = normalizeColorValue(*a + x * toAdd.alpha()); + if (multiply > 0.0f) { + const float fa = static_cast<float>(*a); + const float fad = static_cast<float>(toAdd.alpha()); + *a = normalizeColorValue( static_cast<int>(fa + x * fad) ); + } } int fitFontWeight(int weight, int low, int high, int highCss) diff --git a/src/platform/win/winplatform.cpp b/src/platform/win/winplatform.cpp index c29e173f1..f2cddcf13 100644 --- a/src/platform/win/winplatform.cpp +++ b/src/platform/win/winplatform.cpp @@ -191,7 +191,7 @@ QApplication *createGuiApplication(int &argc, char **argv) // WM_QUERYENDSESSION (from installer) and similar events. auto w = new QWidget(); auto winId = w->winId(); - Q_UNUSED(winId); + Q_UNUSED(winId) return app; } diff --git a/src/platform/x11/systemclipboard/waylandclipboard.cpp b/src/platform/x11/systemclipboard/waylandclipboard.cpp index 123fc2e38..3d942db9a 100644 --- a/src/platform/x11/systemclipboard/waylandclipboard.cpp +++ b/src/platform/x11/systemclipboard/waylandclipboard.cpp @@ -90,7 +90,7 @@ QVariant DataControlOffer::retrieveData(const QString &mimeType, QVariant::Type if (!hasFormat(mimeType)) { return QVariant(); } - Q_UNUSED(type); + Q_UNUSED(type) int pipeFds[2]; if (pipe(pipeFds) != 0){ diff --git a/src/platform/x11/x11platform.cpp b/src/platform/x11/x11platform.cpp index dbe7e406c..5f80889b5 100644 --- a/src/platform/x11/x11platform.cpp +++ b/src/platform/x11/x11platform.cpp @@ -232,7 +232,7 @@ void X11Platform::setAutostartEnabled(bool enable) maybePrintFileError(desktopFile2, "Failed to write desktop file"); #else - Q_UNUSED(enable); + Q_UNUSED(enable) #endif } diff --git a/src/scriptable/scriptable.cpp b/src/scriptable/scriptable.cpp index c2aeae62d..7c7d55173 100644 --- a/src/scriptable/scriptable.cpp +++ b/src/scriptable/scriptable.cpp @@ -2107,8 +2107,8 @@ QJSValue Scriptable::dialog() QJSValue Scriptable::menuItems() { - const auto arg = argument(0); - if ( arg.isString() ) { + const auto text = argument(0); + if ( text.isString() ) { m_skipArguments = -1; QVector<QVariantMap> items; for (const auto &arg : arguments()) @@ -2120,7 +2120,7 @@ QJSValue Scriptable::menuItems() } m_skipArguments = 1; - const auto items = fromScriptValue<QVector<QVariantMap>>( arg, this ); + const auto items = fromScriptValue<QVector<QVariantMap>>(text, this); if ( items.isEmpty() ) return -1; return m_proxy->menuItems(items); @@ -2752,8 +2752,8 @@ void Scriptable::onSynchronizeSelection(ClipboardMode sourceMode, const QString : "copyq --clipboard-access synchronizeFromSelection"; m_proxy->runInternalAction(data, command); #else - Q_UNUSED(text); - Q_UNUSED(sourceMode); + Q_UNUSED(text) + Q_UNUSED(sourceMode) #endif } @@ -3410,7 +3410,7 @@ void Scriptable::synchronizeSelection(ClipboardMode targetMode) #ifdef HAS_MOUSE_SELECTIONS # define COPYQ_SYNC_LOG(MESSAGE) \ COPYQ_LOG( QString("Synchronizing to %1: " MESSAGE) \ - .arg(targetMode == ClipboardMode::Clipboard ? "clipboard" : "selection") ); + .arg(targetMode == ClipboardMode::Clipboard ? "clipboard" : "selection") ) if (!verifyClipboardAccess()) return; @@ -3470,7 +3470,7 @@ void Scriptable::synchronizeSelection(ClipboardMode targetMode) provideSelection(); # undef COPYQ_SYNC_LOG #else - Q_UNUSED(targetMode); + Q_UNUSED(targetMode) #endif } diff --git a/src/scriptable/scriptableproxy.cpp b/src/scriptable/scriptableproxy.cpp index ddcccf815..4ceec3976 100644 --- a/src/scriptable/scriptableproxy.cpp +++ b/src/scriptable/scriptableproxy.cpp @@ -121,27 +121,30 @@ void registerMetaTypes() { #define STR(str) str -#define INVOKE_(function, arguments, functionCallId) \ +#define INVOKE_(function, arguments, functionCallId) do { \ static const auto f = FunctionCallSerializer(STR(#function)).withSlotArguments arguments; \ const auto args = f.argumentList arguments; \ - emit sendMessage(f.serialize(functionCallId, args), CommandFunctionCall) + emit sendMessage(f.serialize(functionCallId, args), CommandFunctionCall); \ +} while(false) -#define INVOKE(FUNCTION, ARGUMENTS) \ +#define INVOKE(FUNCTION, ARGUMENTS) do { \ if (!m_wnd) { \ using Result = decltype(FUNCTION ARGUMENTS); \ const auto functionCallId = ++m_lastFunctionCallId; \ INVOKE_(FUNCTION, ARGUMENTS, functionCallId); \ const auto result = waitForFunctionCallFinished(functionCallId); \ return result.value<Result>(); \ - } + } \ +} while(false) -#define INVOKE2(FUNCTION, ARGUMENTS) \ +#define INVOKE2(FUNCTION, ARGUMENTS) do { \ if (!m_wnd) { \ const auto functionCallId = ++m_lastFunctionCallId; \ INVOKE_(FUNCTION, ARGUMENTS, functionCallId); \ waitForFunctionCallFinished(functionCallId); \ return; \ - } + } \ +} while(false) Q_DECLARE_METATYPE(QFile*) @@ -1340,7 +1343,7 @@ void ScriptableProxy::browserMoveSelected(int targetRow) return; QModelIndexList indexes; - for (const auto index : selected) + for (const auto &index : selected) indexes.append(index); c->move(indexes, targetRow); } @@ -1794,8 +1797,8 @@ int ScriptableProxy::inputDialog(const NamedValueList &values) QObject::connect( buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject ); layout.addWidget(buttons); - installShortcutToCloseDialog(&dialog, &dialog, Qt::CTRL | Qt::Key_Enter); - installShortcutToCloseDialog(&dialog, &dialog, Qt::CTRL | Qt::Key_Return); + installShortcutToCloseDialog(&dialog, &dialog, Qt::ControlModifier | Qt::Key_Enter); + installShortcutToCloseDialog(&dialog, &dialog, Qt::ControlModifier | Qt::Key_Return); if (icon.isNull()) icon = appIcon(); diff --git a/src/tests/test_utils.h b/src/tests/test_utils.h index 728fdef60..b4c51efc3 100644 --- a/src/tests/test_utils.h +++ b/src/tests/test_utils.h @@ -35,19 +35,19 @@ * didn't fail or print error. */ #define TEST(ERRORS_OR_EMPTY) \ - QVERIFY2( NO_ERRORS(ERRORS_OR_EMPTY), "Failed with errors above." ); + QVERIFY2( NO_ERRORS(ERRORS_OR_EMPTY), "Failed with errors above." ) #define RUN(ARGUMENTS, STDOUT_EXPECTED) \ - TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED)) ); + TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED)) ) #define RUN_WITH_INPUT(ARGUMENTS, INPUT, STDOUT_EXPECTED) \ - TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED), toByteArray(INPUT)) ); + TEST( m_test->runClient((Args() << ARGUMENTS), toByteArray(STDOUT_EXPECTED), toByteArray(INPUT)) ) #define RUN_EXPECT_ERROR(ARGUMENTS, EXIT_CODE) \ - TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE)) ); + TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE)) ) #define RUN_EXPECT_ERROR_WITH_STDERR(ARGUMENTS, EXIT_CODE, STDERR_CONTAINS) \ - TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE), toByteArray(STDERR_CONTAINS)) ); + TEST( m_test->runClientWithError((Args() << ARGUMENTS), (EXIT_CODE), toByteArray(STDERR_CONTAINS)) ) #define WAIT_FOR_CLIPBOARD(DATA) \ TEST( m_test->verifyClipboard(DATA, "text/plain") ) diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 3b03c80e4..035764fd8 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -877,7 +877,7 @@ void Tests::badSessionName() void Tests::commandExit() { - RUN("exit", "Terminating server.\n") + RUN("exit", "Terminating server.\n"); TEST( m_test->waitForServerToStop() ); @@ -983,8 +983,8 @@ void Tests::commandSource() scriptFile.close(); const auto scriptFileName = scriptFile.fileName(); - RUN("source" << scriptFileName, "SOURCED") - RUN("source" << scriptFileName << "test()", "SOURCED TEST\n") + RUN("source" << scriptFileName, "SOURCED"); + RUN("source" << scriptFileName << "test()", "SOURCED TEST\n"); } void Tests::commandVisible() @@ -1608,7 +1608,7 @@ void Tests::commandsImportExportCommandsFixIndentation() void Tests::commandScreenshot() { - RUN("screenshot().size() > 0", "true\n") + RUN("screenshot().size() > 0", "true\n"); } void Tests::commandNotification() @@ -2272,7 +2272,7 @@ void Tests::copyPasteCommands() WAIT_FOR_CLIPBOARD(commands); RUN("keys" << commandDialogListId << "Enter" << clipboardBrowserId, ""); - RUN("commands().length", "2\n") + RUN("commands().length", "2\n"); } void Tests::editItems() @@ -2715,14 +2715,14 @@ void Tests::itemPreview() RUN("keys" << clipboardBrowserId << "F7", ""); RUN("preview", "true\n"); - RUN("keys" << clipboardBrowserId << "TAB" << itemPreviewId, "") - RUN("keys" << itemPreviewId << "HOME", "") - RUN("keys" << itemPreviewId << "RIGHT", "") - RUN("keys" << itemPreviewId << "SHIFT+RIGHT", "") - RUN("keys" << itemPreviewId << keyNameFor(QKeySequence::Copy), "") + RUN("keys" << clipboardBrowserId << "TAB" << itemPreviewId, ""); + RUN("keys" << itemPreviewId << "HOME", ""); + RUN("keys" << itemPreviewId << "RIGHT", ""); + RUN("keys" << itemPreviewId << "SHIFT+RIGHT", ""); + RUN("keys" << itemPreviewId << keyNameFor(QKeySequence::Copy), ""); WAIT_FOR_CLIPBOARD("b"); - RUN("keys" << itemPreviewId << "F7" << clipboardBrowserId, "") + RUN("keys" << itemPreviewId << "F7" << clipboardBrowserId, ""); RUN("preview" << "true", "false\n"); RUN("preview" << "false", "true\n"); @@ -3527,7 +3527,7 @@ void Tests::showHideClipboardDialog() void Tests::showHideItemDialog() { - RUN("write" << "test-format" << "TEST", "") + RUN("write" << "test-format" << "TEST", ""); RUN("selectItems" << "0", "true\n"); RUN("keys" << clipboardBrowserId << "F4" << clipboardDialogId, ""); @@ -3573,7 +3573,7 @@ void Tests::shortcutDialogAddShortcut() #endif RUN("setCommands([{name: 'test', inMenu: true, cmd: 'copyq add OK'}])", ""); - RUN("commands()[0].shortcuts", "") + RUN("commands()[0].shortcuts", ""); RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, ""); RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, ""); @@ -3582,7 +3582,7 @@ void Tests::shortcutDialogAddShortcut() RUN("keys" << commandDialogId << "ESCAPE" << commandDialogSaveButtonId, ""); RUN("keys" << commandDialogSaveButtonId << "Enter" << clipboardBrowserId, ""); - RUN("commands()[0].shortcuts", "ctrl+f1\n") + RUN("commands()[0].shortcuts", "ctrl+f1\n"); } void Tests::shortcutDialogAddTwoShortcuts() @@ -3592,7 +3592,7 @@ void Tests::shortcutDialogAddTwoShortcuts() #endif RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", ""); - RUN("commands()[0].shortcuts", "ctrl+f1\n") + RUN("commands()[0].shortcuts", "ctrl+f1\n"); RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, ""); RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, ""); @@ -3606,7 +3606,7 @@ void Tests::shortcutDialogAddTwoShortcuts() RUN("keys" << commandDialogId << "ESCAPE" << commandDialogSaveButtonId, ""); RUN("keys" << commandDialogSaveButtonId << "Enter" << clipboardBrowserId, ""); - RUN("commands()[0].shortcuts", "ctrl+f1\nf1\nf2\n") + RUN("commands()[0].shortcuts", "ctrl+f1\nf1\nf2\n"); } void Tests::shortcutDialogChangeShortcut() @@ -3616,7 +3616,7 @@ void Tests::shortcutDialogChangeShortcut() #endif RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['f1','f2','f3'], cmd: 'copyq add OK'}])", ""); - RUN("commands()[0].shortcuts", "f1\nf2\nf3\n") + RUN("commands()[0].shortcuts", "f1\nf2\nf3\n"); RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, ""); RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, ""); @@ -3626,7 +3626,7 @@ void Tests::shortcutDialogChangeShortcut() RUN("keys" << commandDialogId << "ESCAPE" << commandDialogSaveButtonId, ""); RUN("keys" << commandDialogSaveButtonId << "Enter" << clipboardBrowserId, ""); - RUN("commands()[0].shortcuts", "f1\nf4\nf3\n") + RUN("commands()[0].shortcuts", "f1\nf4\nf3\n"); } void Tests::shortcutDialogSameShortcut() @@ -3636,7 +3636,7 @@ void Tests::shortcutDialogSameShortcut() #endif RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", ""); - RUN("commands()[0].shortcuts", "ctrl+f1\n") + RUN("commands()[0].shortcuts", "ctrl+f1\n"); RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, ""); RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, ""); @@ -3645,7 +3645,7 @@ void Tests::shortcutDialogSameShortcut() RUN("keys" << shortcutDialogId << "CTRL+F1" << shortcutButtonId, ""); RUN("keys" << commandDialogId << "ESCAPE" << clipboardBrowserId, ""); - RUN("commands()[0].shortcuts", "ctrl+f1\n") + RUN("commands()[0].shortcuts", "ctrl+f1\n"); } void Tests::shortcutDialogCancel() @@ -3655,7 +3655,7 @@ void Tests::shortcutDialogCancel() #endif RUN("setCommands([{name: 'test', inMenu: true, shortcuts: ['ctrl+f1'], cmd: 'copyq add OK'}])", ""); - RUN("commands()[0].shortcuts", "ctrl+f1\n") + RUN("commands()[0].shortcuts", "ctrl+f1\n"); RUN("keys" << clipboardBrowserId << "F6" << commandDialogId, ""); RUN("keys" << commandDialogId << "ALT+S" << shortcutButtonId, ""); @@ -3664,7 +3664,7 @@ void Tests::shortcutDialogCancel() RUN("keys" << shortcutDialogId << "ESCAPE" << shortcutButtonId, ""); RUN("keys" << commandDialogId << "ESCAPE" << clipboardBrowserId, ""); - RUN("commands()[0].shortcuts", "ctrl+f1\n") + RUN("commands()[0].shortcuts", "ctrl+f1\n"); } void Tests::actionDialogCancel() @@ -3777,7 +3777,7 @@ void Tests::exitConfirm() void Tests::exitNoConfirm() { - RUN("config" << "confirm_exit" << "false", "false\n") + RUN("config" << "confirm_exit" << "false", "false\n"); RUN("keys" << clipboardBrowserId << "CTRL+Q", ""); TEST( m_test->waitForServerToStop() ); } @@ -3871,7 +3871,7 @@ int runTests(int argc, char *argv[]) const auto platform = platformNativeInterface(); std::unique_ptr<QGuiApplication> app( platform->createTestApplication(argc, argv) ); - Q_UNUSED(app); + Q_UNUSED(app) const QString session = "copyq.test"; QCoreApplication::setOrganizationName(session); diff --git a/utils/update_icon_font.py b/utils/update_icon_font.py index 98be9096f..a6ac57936 100755 --- a/utils/update_icon_font.py +++ b/utils/update_icon_font.py @@ -54,7 +54,7 @@ def write_icon_list_header_file(header_icon_list, icons): item_list_content = ',\n'.join(items) content = dedent('''\ struct Icon { - unsigned int unicode; + unsigned short unicode; bool isBrand; const char *searchTerms; }; -- GitLab