From e782691e7021fb05e1dd82b9fb488aae45bb301c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 14 Jun 2018 14:09:54 +0200 Subject: [PATCH] Favor manual list creator over for loop for small list Three items, create them manually, cleaner and less computationally expensive. Btw - this is ugly, both ways. I blame QStandardItemModel. --- src/settings/ProfileSettings.cpp | 13 +++++++------ src/settings/ProfileSettings.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/settings/ProfileSettings.cpp b/src/settings/ProfileSettings.cpp index 1bd2861f..3fbfe0b2 100644 --- a/src/settings/ProfileSettings.cpp +++ b/src/settings/ProfileSettings.cpp @@ -130,7 +130,7 @@ void ProfileSettings::updateItems(const Profile::Ptr profile) }; updateItemsForProfile(profile, items); } -void ProfileSettings::updateItemsForProfile(const Profile::Ptr profile, QList& items) const +void ProfileSettings::updateItemsForProfile(const Profile::Ptr profile, const QList& items) const { // Profile Name items[ProfileNameColumn]->setText(profile->name()); @@ -173,11 +173,12 @@ void ProfileSettings::addItems(const Profile::Ptr profile) return; } - QList items; - items.reserve(3); - for (int i = 0; i < 3; i++) { - items.append(new QStandardItem); - } + // each _sessionModel row has three items. + const auto items = QList { + new QStandardItem(), + new QStandardItem(), + new QStandardItem() + }; updateItemsForProfile(profile, items); _sessionModel->appendRow(items); diff --git a/src/settings/ProfileSettings.h b/src/settings/ProfileSettings.h index 456bb58e..29ce1f06 100644 --- a/src/settings/ProfileSettings.h +++ b/src/settings/ProfileSettings.h @@ -98,7 +98,7 @@ private: // updates the font of the items to match // their default / non-default profile status void updateDefaultItem(); - void updateItemsForProfile(const Profile::Ptr profile, QList &items) const; + void updateItemsForProfile(const Profile::Ptr profile,const QList &items) const; // updates the profile table to be in sync with the // session manager void populateTable();