summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2023-10-29 00:10:58 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2023-10-29 00:10:58 -0500
commit9cfc93630d065e38a0ab09faf29489da64c44d2d (patch)
treec9af9912ee8331a5912b22b5a7816bd6557927ae
parent6899f2497dd2dc45a0d48e5d9621c19f4ca4fe7b (diff)
downloadhorizon-9cfc93630d065e38a0ab09faf29489da64c44d2d.tar.gz
horizon-9cfc93630d065e38a0ab09faf29489da64c44d2d.tar.bz2
horizon-9cfc93630d065e38a0ab09faf29489da64c44d2d.tar.xz
horizon-9cfc93630d065e38a0ab09faf29489da64c44d2d.zip
Qt UI: Perf improvements, hide date/time in RT Env
Dramatic speed up parsing time zone lists by using const refs. Closes: #357
-rw-r--r--ui/qt5/datetimepage.cc49
-rw-r--r--ui/qt5/datetimepage.hh2
2 files changed, 26 insertions, 25 deletions
diff --git a/ui/qt5/datetimepage.cc b/ui/qt5/datetimepage.cc
index 8b01d30..5f38493 100644
--- a/ui/qt5/datetimepage.cc
+++ b/ui/qt5/datetimepage.cc
@@ -27,15 +27,14 @@
TimeZone::TimeZone() : ianaName(), friendlyName(), offset(0) {}
-TimeZone::TimeZone(QByteArray iana) {
- QTimeZone zone(iana);
- QString offset, longName, comment;
- this->ianaName = iana;
+TimeZone::TimeZone(const QByteArray &iana) : ianaName(iana) {
+ const QTimeZone zone(iana);
+ QString offset_str, longName, comment;
- offset = zone.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName);
- this->friendlyName = "(" + offset + ") " + iana;
+ offset_str = zone.displayName(QTimeZone::GenericTime, QTimeZone::OffsetName);
+ this->friendlyName = "(" + offset_str + ") " + iana;
longName = zone.displayName(QTimeZone::GenericTime, QTimeZone::LongName);
- if(longName != offset) {
+ if(longName != offset_str) {
this->friendlyName += " - " + longName;
}
@@ -52,11 +51,11 @@ TimeZoneModel::TimeZoneModel(QWidget *parent) : QAbstractListModel(parent) {
for(auto &iana : QTimeZone::availableTimeZoneIds()) {
/* we don't support raw timezones because tzdata doesn't */
if(iana.startsWith("UTC") && iana.size() > 3) continue;
- TimeZone tzObj(iana);
+ const TimeZone tzObj(iana);
zones.push_back(tzObj);
}
- std::sort(zones.begin(), zones.end(), [](TimeZone tz1, TimeZone tz2) {
+ std::sort(zones.begin(), zones.end(), [](const TimeZone &tz1, const TimeZone &tz2) {
if(tz1.offset < tz2.offset) return true;
if(tz2.offset < tz1.offset) return false;
return tz1.friendlyName < tz2.friendlyName;
@@ -69,14 +68,14 @@ int TimeZoneModel::rowCount(const QModelIndex &) const {
QVariant TimeZoneModel::data(const QModelIndex &index, int role) const {
if(!index.isValid()) {
- return QVariant();
+ return {};
}
if(index.row() > zones.size()) {
- return QVariant();
+ return {};
}
- TimeZone zone = zones.at(index.row());
+ const TimeZone &zone = zones.at(index.row());
switch(role)
{
@@ -85,13 +84,13 @@ QVariant TimeZoneModel::data(const QModelIndex &index, int role) const {
case Qt::ToolTipRole:
return QString(zone.ianaName);
default:
- return QVariant();
+ return {};
}
}
QVariant TimeZoneModel::headerData(int, Qt::Orientation, int role) const {
if(role != Qt::DisplayRole) {
- return QVariant();
+ return {};
}
return QString("Time Zone");
@@ -173,18 +172,18 @@ DateTimePage::DateTimePage(QWidget *parent) : HorizonWizardPage(parent) {
updateTimer = new QTimer(this);
updateTimer->setInterval(1000);
- connect(updateTimer, &QTimer::timeout, [=]{
+ connect(updateTimer, &QTimer::timeout, [this]{
if(!dateEdit->hasFocus()) dateEdit->setDate(QDate::currentDate());
if(!timeEdit->hasFocus()) timeEdit->setTime(QTime::currentTime());
});
- QHBoxLayout *dateTimeLayout = new QHBoxLayout;
+ auto dateTimeLayout = new QHBoxLayout;
dateTimeLayout->addWidget(dateEdit);
dateTimeLayout->addWidget(timeEdit);
- QGroupBox *dateTimeGroup = new QGroupBox(tr("Date and Time"));
+ auto dateTimeGroup = new QGroupBox(tr("Date and Time"));
dateTimeGroup->setLayout(dateTimeLayout);
- QLineEdit *timeZoneSearch = new QLineEdit;
+ auto timeZoneSearch = new QLineEdit;
timeZoneSearch->addAction(QIcon::fromTheme("edit-find"),
QLineEdit::LeadingPosition);
timeZoneSearch->setPlaceholderText(tr("Search for a time zone"));
@@ -192,7 +191,7 @@ DateTimePage::DateTimePage(QWidget *parent) : HorizonWizardPage(parent) {
sortModel = new QSortFilterProxyModel(this);
sortModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
sortModel->setSourceModel(&zoneModel);
- connect(timeZoneSearch, &QLineEdit::textChanged, [=](const QString &text) {
+ connect(timeZoneSearch, &QLineEdit::textChanged, [this](const QString &text) {
sortModel->setFilterFixedString(text);
});
timeZoneList = new QListView;
@@ -200,22 +199,24 @@ DateTimePage::DateTimePage(QWidget *parent) : HorizonWizardPage(parent) {
timeZoneList->setSelectionMode(QAbstractItemView::SingleSelection);
timeZoneList->setWhatsThis(tr("This list contains all time zones known to the system. Select the one you wish to use for representing time on this computer."));
connect(timeZoneList->selectionModel(), &QItemSelectionModel::currentChanged,
- [=]() {
+ [this]() {
emit timezoneChanged();
});
registerField("timezone*", this, "selectedTimeZone", SIGNAL(timezoneChanged()));
- QVBoxLayout *timeZoneLayout = new QVBoxLayout;
+ auto timeZoneLayout = new QVBoxLayout;
timeZoneLayout->addWidget(timeZoneSearch);
timeZoneLayout->addWidget(timeZoneList);
- QGroupBox *timeZoneGroup = new QGroupBox(tr("Time Zone"));
+ auto timeZoneGroup = new QGroupBox(tr("Time Zone"));
timeZoneGroup->setLayout(timeZoneLayout);
- QVBoxLayout *mainLayout = new QVBoxLayout;
+ auto mainLayout = new QVBoxLayout;
mainLayout->addStretch();
+#ifdef HAS_INSTALL_ENV
mainLayout->addWidget(dateTimeGroup);
mainLayout->addStretch();
+#endif /* HAS_INSTALL_ENV */
mainLayout->addWidget(timeZoneGroup);
mainLayout->addStretch();
setLayout(mainLayout);
@@ -224,7 +225,7 @@ DateTimePage::DateTimePage(QWidget *parent) : HorizonWizardPage(parent) {
}
QString DateTimePage::selectedTimeZone() {
- QModelIndex curr = timeZoneList->selectionModel()->currentIndex();
+ const QModelIndex curr = timeZoneList->selectionModel()->currentIndex();
return sortModel->data(curr, Qt::ToolTipRole).toString();
}
diff --git a/ui/qt5/datetimepage.hh b/ui/qt5/datetimepage.hh
index a861d90..1a47b64 100644
--- a/ui/qt5/datetimepage.hh
+++ b/ui/qt5/datetimepage.hh
@@ -33,7 +33,7 @@ struct TimeZone {
int offset;
TimeZone();
- TimeZone(QByteArray iana);
+ TimeZone(const QByteArray &iana);
};
class TimeZoneModel : public QAbstractListModel {