Changeset View
Changeset View
Standalone View
Standalone View
tests/kwayland/waylandconfigreader.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 81 | // qDebug() << "\tWhite: " << edid.white(); | |||
---|---|---|---|---|---|
108 | 108 | | |||
109 | int mode_id = 0; | 109 | int mode_id = 0; | ||
110 | Q_FOREACH (const QVariant &_mode, outputConfig[QStringLiteral("modes")].toList()) { | 110 | Q_FOREACH (const QVariant &_mode, outputConfig[QStringLiteral("modes")].toList()) { | ||
111 | mode_id++; | 111 | mode_id++; | ||
112 | const QVariantMap &mode = _mode.toMap(); | 112 | const QVariantMap &mode = _mode.toMap(); | ||
113 | OutputDeviceInterface::Mode m0; | 113 | OutputDeviceInterface::Mode m0; | ||
114 | const QSize _size = sizeFromJson(mode[QStringLiteral("size")]); | 114 | const QSize _size = sizeFromJson(mode[QStringLiteral("size")]); | ||
115 | 115 | | |||
116 | if (mode.keys().contains(QStringLiteral("refreshRate"))) { | 116 | auto refreshRateIt = mode.constFind(QStringLiteral("refreshRate")); | ||
117 | m0.refreshRate = qRound(mode[QStringLiteral("refreshRate")].toReal() * 1000); // config has it in Hz | 117 | if (refreshRateIt != mode.constEnd()) { | ||
118 | m0.refreshRate = qRound(refreshRateIt->toReal() * 1000); // config has it in Hz | ||||
broulik: We do a double lookup here, `contains()` and then `operator[]` afterwards, should be combined… | |||||
118 | } | 119 | } | ||
119 | bool isCurrent = currentModeId == mode[QStringLiteral("id")].toInt(); | 120 | bool isCurrent = currentModeId == mode[QStringLiteral("id")].toInt(); | ||
120 | bool isPreferred = preferredModes.contains(mode[QStringLiteral("id")]); | 121 | bool isPreferred = preferredModes.contains(mode[QStringLiteral("id")]); | ||
121 | 122 | | |||
122 | OutputDeviceInterface::ModeFlags flags; | 123 | OutputDeviceInterface::ModeFlags flags; | ||
123 | if (isCurrent && isPreferred) { | 124 | if (isCurrent && isPreferred) { | ||
124 | flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Current | OutputDeviceInterface::ModeFlag::Preferred); | 125 | flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Current | OutputDeviceInterface::ModeFlag::Preferred); | ||
125 | } else if (isCurrent) { | 126 | } else if (isCurrent) { | ||
126 | flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Current); | 127 | flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Current); | ||
127 | } else if (isPreferred) { | 128 | } else if (isPreferred) { | ||
128 | flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Preferred); | 129 | flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Preferred); | ||
129 | } | 130 | } | ||
130 | 131 | | |||
131 | if (mode.keys().contains(QLatin1String("id"))) { | 132 | auto idIt = mode.constFind(QStringLiteral("id")); | ||
132 | m0.id = mode[QStringLiteral("id")].toInt(); | 133 | if (idIt != mode.constEnd()) { | ||
134 | m0.id = idIt->toInt(); | ||||
133 | } else { | 135 | } else { | ||
134 | m0.id = mode_id; | 136 | m0.id = mode_id; | ||
135 | } | 137 | } | ||
136 | m0.size = _size; | 138 | m0.size = _size; | ||
137 | m0.flags = flags; | 139 | m0.flags = flags; | ||
138 | outputdevice->addMode(m0); | 140 | outputdevice->addMode(m0); | ||
139 | 141 | | |||
140 | if (isCurrent) { | 142 | if (isCurrent) { | ||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |
We do a double lookup here, contains() and then operator[] afterwards, should be combined to a single find()