From 14463a722064177b1699d3ab562e3a89e0a39da9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Tue, 6 Sep 2011 11:02:49 +0000 Subject: [PATCH] Fix locale problem (inserted a thousand separator into numbers when converting to strings) svn path=/trunk/kdenlive/; revision=5856 --- src/documentvalidator.cpp | 3 ++- src/effectstackedit.cpp | 3 +-- src/initeffects.cpp | 4 +++- src/kdenlivedoc.cpp | 4 +++- src/mainwindow.cpp | 10 ++++++++-- src/trackview.cpp | 18 +++++++++--------- src/trackview.h | 2 +- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/documentvalidator.cpp b/src/documentvalidator.cpp index 64c595c7..d13fd99e 100644 --- a/src/documentvalidator.cpp +++ b/src/documentvalidator.cpp @@ -62,7 +62,8 @@ bool DocumentValidator::validate(const double currentVersion) setlocale(LC_NUMERIC, mlt.attribute("LC_NUMERIC").toUtf8().constData()); documentLocale = QLocale(mlt.attribute("LC_NUMERIC")); } - + + documentLocale.setNumberOptions(QLocale::OmitGroupSeparator); if (documentLocale != QLocale()) { QLocale::setDefault(documentLocale); // locale conversion might need to be redone diff --git a/src/effectstackedit.cpp b/src/effectstackedit.cpp index 2ed0bc63..7ade3c50 100644 --- a/src/effectstackedit.cpp +++ b/src/effectstackedit.cpp @@ -646,11 +646,10 @@ QString EffectStackEdit::getWipeString(wipeInfo info) void EffectStackEdit::collectAllParameters() { if (m_valueItems.isEmpty() || m_params.isNull()) return; - QLocale locale; - locale.setNumberOptions(QLocale::OmitGroupSeparator); const QDomElement oldparam = m_params.cloneNode().toElement(); QDomElement newparam = oldparam.cloneNode().toElement(); QDomNodeList namenode = newparam.elementsByTagName("parameter"); + QLocale locale; for (int i = 0; i < namenode.count() ; i++) { QDomNode pa = namenode.item(i); diff --git a/src/initeffects.cpp b/src/initeffects.cpp index 1cf161b3..a388b113 100644 --- a/src/initeffects.cpp +++ b/src/initeffects.cpp @@ -344,9 +344,10 @@ void initEffects::parseEffectFile(EffectsList *customEffectList, EffectsList *au kDebug() << "Effect broken: " << name; return; } - QLocale locale; + bool needsLocaleConversion = false; for (int i = 0; !effects.item(i).isNull(); ++i) { + QLocale locale; documentElement = effects.item(i).toElement(); QString tag = documentElement.attribute("tag", QString()); if (documentElement.hasAttribute("LC_NUMERIC")) { @@ -356,6 +357,7 @@ void initEffects::parseEffectFile(EffectsList *customEffectList, EffectsList *au needsLocaleConversion = true; } } + locale.setNumberOptions(QLocale::OmitGroupSeparator); if (needsLocaleConversion) { // we need to convert all numbers to the system's locale (for example 0.5 -> 0,5) diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 23484f67..fced3334 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -101,7 +101,9 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup if (QLocale() != QLocale::system()) { setlocale(LC_NUMERIC, ""); - QLocale::setDefault(QLocale::system()); + QLocale systemLocale = QLocale::system(); + systemLocale.setNumberOptions(QLocale::OmitGroupSeparator); + QLocale::setDefault(systemLocale); // locale conversion might need to be redone initEffects::parseEffectFiles(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c3efd3da..d8a46d37 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -87,7 +87,6 @@ #include #include #include -#include #include #include #include @@ -148,12 +147,19 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & #endif /* NO_JOGSHUTTLE */ m_findActivated(false), m_stopmotion(NULL) -{ +{ qRegisterMetaType > (); + + // Init locale + QLocale systemLocale = QLocale(); + systemLocale.setNumberOptions(QLocale::OmitGroupSeparator); + QLocale::setDefault(systemLocale); + // Create DBus interface new MainWindowAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject("/MainWindow", this); + if (!KdenliveSettings::colortheme().isEmpty()) slotChangePalette(NULL, KdenliveSettings::colortheme()); setFont(KGlobalSettings::toolBarFont()); parseProfiles(MltPath); diff --git a/src/trackview.cpp b/src/trackview.cpp index 1d2af8ae..471706eb 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -406,8 +406,6 @@ void TrackView::parseDocument(QDomDocument doc) } } } - - QDomElement infoXml = mlt.firstChildElement("kdenlivedoc"); // Add guides @@ -600,8 +598,9 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNod double speed = 1.0; int strobe = 1; if (idString.startsWith("slowmotion")) { + QLocale locale; id = idString.section(':', 1, 1); - speed = m_locale.toDouble(idString.section(':', 2, 2)); + speed = locale.toDouble(idString.section(':', 2, 2)); strobe = idString.section(':', 3, 3).toInt(); if (strobe == 0) strobe = 1; } @@ -742,6 +741,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNod void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNode, ClipItem *clip, int trackIndex) { int effectNb = 0; + QLocale locale; for (int ix = 0; ix < effects.count(); ix++) { bool disableeffect = false; QDomElement effect = effects.at(ix).toElement(); @@ -823,8 +823,8 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo // add first keyframe if (effectout <= effectin) { // there is only one keyframe - keyframes.append(QString::number(effectin) + ':' + m_locale.toString(startvalue) + ';'); - } else keyframes.append(QString::number(effectin) + ':' + m_locale.toString(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';'); + keyframes.append(QString::number(effectin) + ':' + locale.toString(startvalue) + ';'); + } else keyframes.append(QString::number(effectin) + ':' + locale.toString(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';'); QDomNode lastParsedEffect; ix++; QDomNode n2 = effects.at(ix); @@ -849,7 +849,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo } } if (continueParsing) { - keyframes.append(QString::number(effectout) + ':' + m_locale.toString(endvalue) + ';'); + keyframes.append(QString::number(effectout) + ':' + locale.toString(endvalue) + ';'); ix++; } } @@ -896,14 +896,14 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo QStringList kfrs = paramvalue.split(";"); for (int l = 0; l < kfrs.count(); l++) { QString fr = kfrs.at(l).section('=', 0, 0); - double val = m_locale.toDouble(kfrs.at(l).section('=', 1, 1)); - //kfrs[l] = fr + ":" + m_locale.toString((int)(val * fact)); + double val = locale.toDouble(kfrs.at(l).section('=', 1, 1)); + //kfrs[l] = fr + ":" + locale.toString((int)(val * fact)); kfrs[l] = fr + ":" + QString::number((int) (val * fact)); } e.setAttribute("keyframes", kfrs.join(";")); } else if (type == "double" || type == "constant") { bool ok; - e.setAttribute("value", m_locale.toDouble(paramvalue, &ok) * fact); + e.setAttribute("value", locale.toDouble(paramvalue, &ok) * fact); if (!ok) e.setAttribute("value", paramvalue); } else { diff --git a/src/trackview.h b/src/trackview.h index b7ea50db..5208fbce 100644 --- a/src/trackview.h +++ b/src/trackview.h @@ -100,11 +100,11 @@ private: KdenliveDoc *m_doc; int m_verticalZoom; QString m_documentErrors; - QLocale m_locale; void parseDocument(QDomDocument doc); int slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNodeList producers); DocClipBase *getMissingProducer(const QString id) const; void adjustTrackHeaders(); + /** @brief Add effects from the xml. Returns true if some effect was upgraded, false if everything went fine.*/ void slotAddProjectEffects(QDomNodeList effects, QDomElement parentNode, ClipItem *clip, int trackIndex); private slots: -- 2.39.2