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.
wilder-portage
Tomaz Canabrava 8 years ago
parent 1462bb095d
commit e782691e70
  1. 13
      src/settings/ProfileSettings.cpp
  2. 2
      src/settings/ProfileSettings.h

@ -130,7 +130,7 @@ void ProfileSettings::updateItems(const Profile::Ptr profile)
};
updateItemsForProfile(profile, items);
}
void ProfileSettings::updateItemsForProfile(const Profile::Ptr profile, QList<QStandardItem*>& items) const
void ProfileSettings::updateItemsForProfile(const Profile::Ptr profile, const QList<QStandardItem*>& items) const
{
// Profile Name
items[ProfileNameColumn]->setText(profile->name());
@ -173,11 +173,12 @@ void ProfileSettings::addItems(const Profile::Ptr profile)
return;
}
QList<QStandardItem*> 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<QStandardItem*> {
new QStandardItem(),
new QStandardItem(),
new QStandardItem()
};
updateItemsForProfile(profile, items);
_sessionModel->appendRow(items);

@ -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<QStandardItem *> &items) const;
void updateItemsForProfile(const Profile::Ptr profile,const QList<QStandardItem *> &items) const;
// updates the profile table to be in sync with the
// session manager
void populateTable();

Loading…
Cancel
Save