Skip to content

Commit

Permalink
chore: fix qAsConst deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed Nov 14, 2024
1 parent bbd7d6c commit 38052b9
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app/kloggapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class KloggApp : public QApplication {

if ( !changes.empty() ) {
message.append( "<p>Important changes:</p><ul>" );
for ( const auto& change : qAsConst( changes ) ) {
for ( const auto& change : changes ) {
message.append( QString( "<li>%1</li>" ).arg( change ) );
}
message.append( "</ul>" );
Expand Down
2 changes: 1 addition & 1 deletion src/settings/src/shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void ShortcutAction::registerShortcut( const ConfiguredShortcuts& configuredShor
? keysConfiguration->second
: ShortcutAction::defaultShortcuts( action );

for ( const auto& key : qAsConst( keys ) ) {
for ( const auto& key : keys ) {
if ( key.isEmpty() ) {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ui/include/fontutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class FontUtils {

#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
QFontDatabase database;
auto families = database.families();
for ( const auto& family : qAsConst( families ) ) {
const auto families = database.families();
for ( const auto& family : families ) {
if ( database.isFixedPitch( family ) )
fixedFamilies << family;
}
#else
auto families = QFontDatabase::families();
for ( const auto& family : qAsConst( families ) ) {
const auto families = QFontDatabase::families();
for ( const auto& family : families ) {
if ( QFontDatabase::isFixedPitch( family ) )
fixedFamilies << family;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/crawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ void CrawlerWidget::changeFilteredViewVisibility( int index )
void CrawlerWidget::setSearchPatternFromPredefinedFilters( const QList<PredefinedFilter>& filters )
{
QString searchPattern;
for ( const auto& filter : qAsConst( filters ) ) {
for ( const auto& filter : filters ) {
combinePatterns( searchPattern, escapeSearchPattern( filter.pattern, filter.useRegex ) );
}
setSearchPattern( searchPattern );
Expand Down
9 changes: 5 additions & 4 deletions src/ui/src/highlightersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <qpushbutton.h>
#include <utility>

#include "containers.h"
#include "dispatch_to.h"
#include "highlightersdialog.h"
#include "highlighterset.h"
Expand Down Expand Up @@ -206,15 +207,15 @@ void HighlightersDialog::exportHighlighters()

void HighlightersDialog::importHighlighters()
{
QStringList files = QFileDialog::getOpenFileNames(
const QStringList files = QFileDialog::getOpenFileNames(
this, tr( "Select one or more files to open" ), "", tr( "Highlighters (*.conf)" ) );

for ( const auto& file : qAsConst( files ) ) {
for ( const auto& file : files ) {
LOG_DEBUG << "Loading highlighters from " << file;
QSettings settings{ file, QSettings::IniFormat };
HighlighterSetCollection collection;
collection.retrieveFromStorage( settings );
for ( const auto& set : qAsConst( collection.highlighters_ ) ) {
for ( const auto& set : klogg::as_const( collection.highlighters_ ) ) {
if ( highlighterSetCollection_.hasSet( set.id() ) ) {
continue;
}
Expand Down Expand Up @@ -382,7 +383,7 @@ void HighlightersDialog::populateHighlighterList()
{
highlighterListWidget->clear();
for ( const HighlighterSet& highlighterSet :
qAsConst( highlighterSetCollection_.highlighters_ ) ) {
klogg::as_const( highlighterSetCollection_.highlighters_ ) ) {
auto* new_item = new QListWidgetItem( highlighterSet.name() );
// new_item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
highlighterListWidget->addItem( new_item );
Expand Down
3 changes: 2 additions & 1 deletion src/ui/src/highlightersetedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "highlighterset.h"
#include "highlightersetedit.h"

#include "containers.h"
#include "dispatch_to.h"
#include "iconloader.h"
#include "log.h"
Expand Down Expand Up @@ -281,7 +282,7 @@ void HighlighterSetEdit::updateHighlighterProperties()
void HighlighterSetEdit::populateHighlighterList()
{
highlighterListWidget->clear();
for ( const Highlighter& highlighter : qAsConst( highlighterSet_.highlighterList_ ) ) {
for ( const Highlighter& highlighter : klogg::as_const( highlighterSet_.highlighterList_ ) ) {
auto* new_item = new QListWidgetItem( highlighter.pattern() );
// new_item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
new_item->setForeground( QBrush( highlighter.foreColor() ) );
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/highlightersmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void HighlightersMenu::populateHighlightersMenu()

addSeparator();

for ( const auto& highlighter : qAsConst( highlighterSets ) ) {
for ( const auto& highlighter : highlighterSets ) {
auto setAction = addAction( highlighter.name() );
setAction->setActionGroup( highLighters_ );
setAction->setCheckable( true );
Expand Down
6 changes: 3 additions & 3 deletions src/ui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,9 +1610,9 @@ void MainWindow::dragEnterEvent( QDragEnterEvent* event )
// Tries and loads the file if the URL dropped is local
void MainWindow::dropEvent( QDropEvent* event )
{
QList<QUrl> urls = event->mimeData()->urls();
const QList<QUrl> urls = event->mimeData()->urls();

for ( const auto& url : qAsConst( urls ) ) {
for ( const auto& url : urls ) {
auto fileName = url.toLocalFile();
if ( fileName.isEmpty() )
continue;
Expand Down Expand Up @@ -1752,7 +1752,7 @@ bool MainWindow::loadFile( const QString& fileName, bool followFile )
const auto previousViewContext = [ &fileName ]() {
const auto& session = SessionInfo::getSynced();
const auto& windows = session.windows();
for ( const auto& windowId : qAsConst( windows ) ) {
for ( const auto& windowId : windows ) {
const auto openedFiles = session.openFiles( windowId );
const auto existingContext
= std::find_if( openedFiles.begin(), openedFiles.end(),
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void OptionsDialog::setupTabs()
void OptionsDialog::setupFontList()
{
const auto families = FontUtils::availableFonts();
for ( const QString& str : qAsConst( families ) ) {
for ( const QString& str : families ) {
fontFamilyBox->addItem( str );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/predefinedfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void PredefinedFiltersCollection::saveToStorage( QSettings& settings ) const

settings.beginWriteArray( "filters" );
int arrayIndex = 0;
for ( const auto& filter : qAsConst( filters_ ) ) {
for ( const auto& filter : filters_ ) {
settings.setArrayIndex( arrayIndex );
settings.setValue( "name", filter.name );
settings.setValue( "filter", filter.pattern );
Expand Down
8 changes: 8 additions & 0 deletions src/utils/include/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ constexpr int isize( const C& c )
{
return type_safe::narrow_cast<int>( ssize( c ) );
}


template<class C>
constexpr std::add_const_t<C>& as_const(C& c) noexcept
{
return c;
}

} // namespace klogg

#endif
2 changes: 1 addition & 1 deletion src/versioncheck/src/versionchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void VersionChecker::checkVersionData( QByteArray versionData )
const auto changeLog = latestVersionMap.value( "changelog" ).toList();

QStringList changes;
for ( const auto& entry : qAsConst( changeLog ) ) {
for ( const auto& entry : changeLog ) {
const auto entryData = entry.toMap();
const auto version = entryData.value( "version" ).toString();

Expand Down

0 comments on commit 38052b9

Please sign in to comment.