Changeset View
Changeset View
Standalone View
Standalone View
src/KPropertyUtils_p.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2010-2016 Jarosław Staniek <staniek@kde.org> | 2 | Copyright (C) 2010-2017 Jarosław Staniek <staniek@kde.org> | ||
3 | 3 | | |||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. | ||
8 | 8 | | |||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | 12 | Library General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "KPropertyUtils_p.h" | 20 | #include "KPropertyUtils_p.h" | ||
21 | #include "KPropertyEditorView.h" | 21 | #include "KPropertyEditorView.h" | ||
22 | #include "KProperty.h" | ||||
22 | 23 | | |||
23 | #include <config-kproperty.h> | 24 | #include <config-kproperty.h> | ||
24 | #if defined KPropertyCore_EXPORTS || defined KPropertyWidgets_EXPORTS | 25 | #if defined KPropertyCore_EXPORTS || defined KPropertyWidgets_EXPORTS | ||
25 | #include "kproperty_debug.h" | 26 | #include "kproperty_debug.h" | ||
26 | #else | 27 | #else | ||
27 | # define kprDebug qDebug | 28 | # define kprDebug qDebug | ||
28 | # define kprWarning qWarning | 29 | # define kprWarning qWarning | ||
29 | # define kprCritical qCritical | 30 | # define kprCritical qCritical | ||
▲ Show 20 Lines • Show All 344 Lines • ▼ Show 20 Line(s) | 368 | if (!registerGlobalIconsResource()) { | |||
374 | return false; | 375 | return false; | ||
375 | } | 376 | } | ||
376 | } | 377 | } | ||
377 | return true; | 378 | return true; | ||
378 | } | 379 | } | ||
379 | 380 | | |||
380 | // ---- | 381 | // ---- | ||
381 | 382 | | |||
383 | ValueOptionsHandler::ValueOptionsHandler(const KProperty &property) | ||||
384 | { | ||||
385 | minValueText = property.option("minValueText").toString(); | ||||
386 | prefix = property.option("prefix").toString().trimmed(); | ||||
387 | suffix = property.option("suffix").toString().trimmed(); | ||||
388 | } | ||||
389 | | ||||
390 | QString ValueOptionsHandler::valueWithPrefixAndSuffix(const QString &valueString, const QLocale &locale) const | ||||
piggz: could this be simpler?
eg, something like
QString r = valueString;
if (!prefix.isEmpty())… | |||||
> QString r = valueString; > if (!prefix.isEmpty()) { > r = QString::fromLatin1("%1 %2).arg(r).arg(suffix); You meant !prefix.isEmpty() probably but I see what you mean > } > if (!suffix.isEmpty()) { > return = QString::fromLatin1("%1 %2).arg(prefix).arg(r); yes, good idea > } > > (+ the bits for locale) > > return r; staniek: ```
> QString r = valueString;
> if (!prefix.isEmpty()) {
> r = QString::fromLatin1("%1 %2). | |||||
391 | { | ||||
392 | if (prefix.isEmpty()) { | ||||
393 | if (suffix.isEmpty()) { // value only | ||||
394 | return valueString; | ||||
395 | } else { // value+suffix | ||||
396 | if (locale.language() == QLocale::C) { | ||||
397 | return QString::fromLatin1("%1 %2").arg(valueString).arg(suffix); | ||||
398 | } else { | ||||
399 | return QObject::tr("%1 %2", "<value> <suffix>") | ||||
400 | .arg(valueString).arg(suffix); | ||||
401 | } | ||||
402 | } | ||||
403 | } | ||||
404 | if (suffix.isEmpty()) { // prefix + value | ||||
405 | if (locale.language() == QLocale::C) { | ||||
406 | return QString::fromLatin1("%1 %2").arg(prefix).arg(valueString); | ||||
407 | } else { | ||||
408 | return QObject::tr("%1 %2", "<value> <suffix>") | ||||
409 | .arg(prefix).arg(valueString); | ||||
410 | } | ||||
411 | } | ||||
412 | // prefix+value+suffix | ||||
413 | if (locale.language() == QLocale::C) { | ||||
414 | return QString::fromLatin1("%1 %2 %3") | ||||
415 | .arg(prefix).arg(valueString).arg(suffix); | ||||
416 | } else { | ||||
417 | return QObject::tr("%1 %2 %3", "<prefix> <value> <suffix>") | ||||
418 | .arg(prefix).arg(valueString).arg(suffix); | ||||
419 | } | ||||
420 | } | ||||
421 | | ||||
422 | // ---- | ||||
423 | | ||||
382 | PainterSaver::PainterSaver(QPainter *p) | 424 | PainterSaver::PainterSaver(QPainter *p) | ||
383 | : m_painter(p) | 425 | : m_painter(p) | ||
384 | { | 426 | { | ||
385 | if (m_painter) { | 427 | if (m_painter) { | ||
386 | m_painter->save(); | 428 | m_painter->save(); | ||
387 | } | 429 | } | ||
388 | } | 430 | } | ||
389 | 431 | | |||
390 | PainterSaver::~PainterSaver() | 432 | PainterSaver::~PainterSaver() | ||
391 | { | 433 | { | ||
392 | if (m_painter) { | 434 | if (m_painter) { | ||
393 | m_painter->restore(); | 435 | m_painter->restore(); | ||
394 | } | 436 | } | ||
395 | } | 437 | } | ||
396 | 438 | | |||
397 | } // namespace KPropertyUtilsPrivate | 439 | } // namespace KPropertyUtilsPrivate |
could this be simpler?
eg, something like