Skip to content

Commit 38052b9

Browse files
committed
chore: fix qAsConst deprecation warning
1 parent bbd7d6c commit 38052b9

12 files changed

+29
-19
lines changed

src/app/kloggapp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class KloggApp : public QApplication {
302302

303303
if ( !changes.empty() ) {
304304
message.append( "<p>Important changes:</p><ul>" );
305-
for ( const auto& change : qAsConst( changes ) ) {
305+
for ( const auto& change : changes ) {
306306
message.append( QString( "<li>%1</li>" ).arg( change ) );
307307
}
308308
message.append( "</ul>" );

src/settings/src/shortcuts.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void ShortcutAction::registerShortcut( const ConfiguredShortcuts& configuredShor
312312
? keysConfiguration->second
313313
: ShortcutAction::defaultShortcuts( action );
314314

315-
for ( const auto& key : qAsConst( keys ) ) {
315+
for ( const auto& key : keys ) {
316316
if ( key.isEmpty() ) {
317317
continue;
318318
}

src/ui/include/fontutils.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class FontUtils {
3737

3838
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
3939
QFontDatabase database;
40-
auto families = database.families();
41-
for ( const auto& family : qAsConst( families ) ) {
40+
const auto families = database.families();
41+
for ( const auto& family : families ) {
4242
if ( database.isFixedPitch( family ) )
4343
fixedFamilies << family;
4444
}
4545
#else
46-
auto families = QFontDatabase::families();
47-
for ( const auto& family : qAsConst( families ) ) {
46+
const auto families = QFontDatabase::families();
47+
for ( const auto& family : families ) {
4848
if ( QFontDatabase::isFixedPitch( family ) )
4949
fixedFamilies << family;
5050
}

src/ui/src/crawlerwidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ void CrawlerWidget::changeFilteredViewVisibility( int index )
840840
void CrawlerWidget::setSearchPatternFromPredefinedFilters( const QList<PredefinedFilter>& filters )
841841
{
842842
QString searchPattern;
843-
for ( const auto& filter : qAsConst( filters ) ) {
843+
for ( const auto& filter : filters ) {
844844
combinePatterns( searchPattern, escapeSearchPattern( filter.pattern, filter.useRegex ) );
845845
}
846846
setSearchPattern( searchPattern );

src/ui/src/highlightersdialog.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <qpushbutton.h>
4747
#include <utility>
4848

49+
#include "containers.h"
4950
#include "dispatch_to.h"
5051
#include "highlightersdialog.h"
5152
#include "highlighterset.h"
@@ -206,15 +207,15 @@ void HighlightersDialog::exportHighlighters()
206207

207208
void HighlightersDialog::importHighlighters()
208209
{
209-
QStringList files = QFileDialog::getOpenFileNames(
210+
const QStringList files = QFileDialog::getOpenFileNames(
210211
this, tr( "Select one or more files to open" ), "", tr( "Highlighters (*.conf)" ) );
211212

212-
for ( const auto& file : qAsConst( files ) ) {
213+
for ( const auto& file : files ) {
213214
LOG_DEBUG << "Loading highlighters from " << file;
214215
QSettings settings{ file, QSettings::IniFormat };
215216
HighlighterSetCollection collection;
216217
collection.retrieveFromStorage( settings );
217-
for ( const auto& set : qAsConst( collection.highlighters_ ) ) {
218+
for ( const auto& set : klogg::as_const( collection.highlighters_ ) ) {
218219
if ( highlighterSetCollection_.hasSet( set.id() ) ) {
219220
continue;
220221
}
@@ -382,7 +383,7 @@ void HighlightersDialog::populateHighlighterList()
382383
{
383384
highlighterListWidget->clear();
384385
for ( const HighlighterSet& highlighterSet :
385-
qAsConst( highlighterSetCollection_.highlighters_ ) ) {
386+
klogg::as_const( highlighterSetCollection_.highlighters_ ) ) {
386387
auto* new_item = new QListWidgetItem( highlighterSet.name() );
387388
// new_item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
388389
highlighterListWidget->addItem( new_item );

src/ui/src/highlightersetedit.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "highlighterset.h"
4545
#include "highlightersetedit.h"
4646

47+
#include "containers.h"
4748
#include "dispatch_to.h"
4849
#include "iconloader.h"
4950
#include "log.h"
@@ -281,7 +282,7 @@ void HighlighterSetEdit::updateHighlighterProperties()
281282
void HighlighterSetEdit::populateHighlighterList()
282283
{
283284
highlighterListWidget->clear();
284-
for ( const Highlighter& highlighter : qAsConst( highlighterSet_.highlighterList_ ) ) {
285+
for ( const Highlighter& highlighter : klogg::as_const( highlighterSet_.highlighterList_ ) ) {
285286
auto* new_item = new QListWidgetItem( highlighter.pattern() );
286287
// new_item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
287288
new_item->setForeground( QBrush( highlighter.foreColor() ) );

src/ui/src/highlightersmenu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void HighlightersMenu::populateHighlightersMenu()
5252

5353
addSeparator();
5454

55-
for ( const auto& highlighter : qAsConst( highlighterSets ) ) {
55+
for ( const auto& highlighter : highlighterSets ) {
5656
auto setAction = addAction( highlighter.name() );
5757
setAction->setActionGroup( highLighters_ );
5858
setAction->setCheckable( true );

src/ui/src/mainwindow.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1610,9 +1610,9 @@ void MainWindow::dragEnterEvent( QDragEnterEvent* event )
16101610
// Tries and loads the file if the URL dropped is local
16111611
void MainWindow::dropEvent( QDropEvent* event )
16121612
{
1613-
QList<QUrl> urls = event->mimeData()->urls();
1613+
const QList<QUrl> urls = event->mimeData()->urls();
16141614

1615-
for ( const auto& url : qAsConst( urls ) ) {
1615+
for ( const auto& url : urls ) {
16161616
auto fileName = url.toLocalFile();
16171617
if ( fileName.isEmpty() )
16181618
continue;
@@ -1752,7 +1752,7 @@ bool MainWindow::loadFile( const QString& fileName, bool followFile )
17521752
const auto previousViewContext = [ &fileName ]() {
17531753
const auto& session = SessionInfo::getSynced();
17541754
const auto& windows = session.windows();
1755-
for ( const auto& windowId : qAsConst( windows ) ) {
1755+
for ( const auto& windowId : windows ) {
17561756
const auto openedFiles = session.openFiles( windowId );
17571757
const auto existingContext
17581758
= std::find_if( openedFiles.begin(), openedFiles.end(),

src/ui/src/optionsdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void OptionsDialog::setupTabs()
128128
void OptionsDialog::setupFontList()
129129
{
130130
const auto families = FontUtils::availableFonts();
131-
for ( const QString& str : qAsConst( families ) ) {
131+
for ( const QString& str : families ) {
132132
fontFamilyBox->addItem( str );
133133
}
134134
}

src/ui/src/predefinedfilters.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void PredefinedFiltersCollection::saveToStorage( QSettings& settings ) const
7979

8080
settings.beginWriteArray( "filters" );
8181
int arrayIndex = 0;
82-
for ( const auto& filter : qAsConst( filters_ ) ) {
82+
for ( const auto& filter : filters_ ) {
8383
settings.setArrayIndex( arrayIndex );
8484
settings.setValue( "name", filter.name );
8585
settings.setValue( "filter", filter.pattern );

src/utils/include/containers.h

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ constexpr int isize( const C& c )
4343
{
4444
return type_safe::narrow_cast<int>( ssize( c ) );
4545
}
46+
47+
48+
template<class C>
49+
constexpr std::add_const_t<C>& as_const(C& c) noexcept
50+
{
51+
return c;
52+
}
53+
4654
} // namespace klogg
4755

4856
#endif

src/versioncheck/src/versionchecker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void VersionChecker::checkVersionData( QByteArray versionData )
177177
const auto changeLog = latestVersionMap.value( "changelog" ).toList();
178178

179179
QStringList changes;
180-
for ( const auto& entry : qAsConst( changeLog ) ) {
180+
for ( const auto& entry : changeLog ) {
181181
const auto entryData = entry.toMap();
182182
const auto version = entryData.value( "version" ).toString();
183183

0 commit comments

Comments
 (0)