From 5703a6b362f76a416e04622a2e4c0ed6743d3abc Mon Sep 17 00:00:00 2001 From: Armin Felder <armin.felder@osalliance.com> Date: Sat, 24 Nov 2018 18:36:20 +0100 Subject: [PATCH] worng for each loops --- CustomModels/messagemodel.cpp | 6 +++--- CustomModels/usermodel.cpp | 2 +- api/meteorddp.cpp | 11 ++++++----- rocketchatserver.cpp | 3 ++- services/rocketchatchannelservice.cpp | 6 +++--- utils.cpp | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CustomModels/messagemodel.cpp b/CustomModels/messagemodel.cpp index 36aa052..dc15ebb 100644 --- a/CustomModels/messagemodel.cpp +++ b/CustomModels/messagemodel.cpp @@ -157,7 +157,7 @@ QString MessagesModel::getCurrent() const void MessagesModel::setCurrent( const QString &value ) { - QMutexLocker( &this->mutex ); + //QMutexLocker( &this->mutex ); current = value; beginResetModel(); @@ -165,7 +165,7 @@ void MessagesModel::setCurrent( const QString &value ) messagesOfCurrentChannel = mChannelMap[value]->getMessageRepo()->timestampIndex().values().toVector(); duplicateCheck.clear(); - for ( auto currentMessage : messagesOfCurrentChannel ) { + for ( const auto ¤tMessage : messagesOfCurrentChannel ) { duplicateCheck.insert( currentMessage->getId() ); } } else { @@ -262,7 +262,7 @@ QHash<int, QByteArray> MessagesModel::roleNames() const void MessagesModel::onNewMessage( const QSharedPointer<RocketChatChannel> &channel, qint64 timestamp ) { - QMutexLocker( &this->mutex ); + //QMutexLocker( &this->mutex ); if ( timestamp == 0 ) { setCurrent( current ); diff --git a/CustomModels/usermodel.cpp b/CustomModels/usermodel.cpp index 56c3e56..ebd8fa4 100644 --- a/CustomModels/usermodel.cpp +++ b/CustomModels/usermodel.cpp @@ -151,7 +151,7 @@ void UserModel::setCurrent( const QString &value ) QList<QSharedPointer<RocketChatUser>> userList = userMap.values( value ); mMutex.unlock(); - for ( auto current : userList ) { + for ( const auto ¤t : userList ) { userOfCurrentChannel.insert( current->getUserId(), current ); } diff --git a/api/meteorddp.cpp b/api/meteorddp.cpp index 35f0ff5..57e0c62 100755 --- a/api/meteorddp.cpp +++ b/api/meteorddp.cpp @@ -42,6 +42,7 @@ void MeteorDDP::init( const QString &pUri, bool pUnsecure ) QString protocol = QStringLiteral( "wss://" ); unsecure = pUnsecure; + if ( pUnsecure ) { protocol = QStringLiteral( "ws://" ); } @@ -65,14 +66,14 @@ void MeteorDDP::init( const QString &pUri, bool pUnsecure ) mLastPing = currentTime; } -void MeteorDDP::registerMessageHandler(MessageListener &listener) +void MeteorDDP::registerMessageHandler( MessageListener &listener ) { - connect(this, &MeteorDDP::messageReceived , &listener, &MessageListener::handlesMessage); + connect( this, &MeteorDDP::messageReceived, &listener, &MessageListener::handlesMessage ); } -void MeteorDDP::registerMessageHandler(MessageListener *listener) +void MeteorDDP::registerMessageHandler( MessageListener *listener ) { - connect(this, &MeteorDDP::messageReceived , listener, &MessageListener::handlesMessage); + connect( this, &MeteorDDP::messageReceived, listener, &MessageListener::handlesMessage ); } void MeteorDDP::connectWithServer() @@ -249,7 +250,7 @@ void MeteorDDP::resume() mWsClient->open( wsUri ); } else if ( !mWsClient->isConnecting() ) { QMetaObject::Connection *const connection = new QMetaObject::Connection; - *connection = connect( mWsClient, &Websocket::closed, [&]() { + *connection = connect( mWsClient, &Websocket::closed, [ = ]() { qDebug() << "websocket closed"; mWsClient->open( wsUri ); QDateTime now = QDateTime::currentDateTime(); diff --git a/rocketchatserver.cpp b/rocketchatserver.cpp index ac6e4ee..5436479 100755 --- a/rocketchatserver.cpp +++ b/rocketchatserver.cpp @@ -201,6 +201,7 @@ void RocketChatServerData::loadEmojis() if ( !emojisByCategory.contains( category ) ) { emojisByCategory.insert( category, QList<QSharedPointer<Emoji>>() ); + emojisByCategory[category].reserve( 500 ); } emojisByCategory[category].append( emoji ); @@ -208,7 +209,7 @@ void RocketChatServerData::loadEmojis() auto keys = emojisByCategory.keys(); - for ( auto key : keys ) { + for ( const auto &key : keys ) { QMetaObject::invokeMethod( emojiModel, "addEmojisByCategory", Q_ARG( QString, key ), Q_ARG( QList<QSharedPointer<Emoji>>, emojisByCategory[key] ) ); } } diff --git a/services/rocketchatchannelservice.cpp b/services/rocketchatchannelservice.cpp index e57afc4..97aa806 100755 --- a/services/rocketchatchannelservice.cpp +++ b/services/rocketchatchannelservice.cpp @@ -226,10 +226,10 @@ void RocketChatChannelService::loadJoinedChannelsFromServer( void ) auto channelsLocal = mChannels->getElements(); - for ( auto channelKey : channelsLocal.keys() ) { + for ( const auto &channelKey : channelsLocal.keys() ) { bool deleteFlag = true; - for ( auto channelServer : channelsParsed ) { + for ( const auto &channelServer : channelsParsed ) { if ( channelServer->getRoomId() == channelKey ) { deleteFlag = false; } @@ -603,7 +603,7 @@ channelVector RocketChatChannelService::searchRoomLocal( const QString &pTerm, c channelVector list; QString term = pTerm.toLower(); - for ( auto channel : mChannels->getElements() ) { + for ( const auto &channel : mChannels->getElements() ) { QString id = channel->getRoomId(); QString type = channel->getType(); QString name = channel->getName().toLower(); diff --git a/utils.cpp b/utils.cpp index 95ee297..3b3c4c3 100755 --- a/utils.cpp +++ b/utils.cpp @@ -154,7 +154,7 @@ QString Utils::linkiFy( const QString &pText ) parts.append( pText.right( pText.length() - idx_last ) ); - for ( const auto part : parts ) { + for ( const auto &part : parts ) { html += part; } -- GitLab