Replace deprecated qSort function

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4917 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-02-16 14:10:30 +00:00
parent 070c601f7b
commit 5d52605b38
2 changed files with 26 additions and 23 deletions

View File

@@ -23,13 +23,16 @@
/** /**
@return a list containing all the keys in the context object. @return a list containing all the keys in the context object.
*/ */
QList<QString> DiagramContext::keys(DiagramContext::KeyOrder order) const { QList<QString> DiagramContext::keys(DiagramContext::KeyOrder order) const
{
if (order == None) { if (order == None) {
return content_.keys(); return m_content.keys();
} else { }
QList<QString> keys_list = content_.keys(); else
{
QList<QString> keys_list = m_content.keys();
if (order == Alphabetical) { if (order == Alphabetical) {
qSort(keys_list); std::sort(keys_list.begin(), keys_list.end());
} else { } else {
std::sort(keys_list.begin(), keys_list.end(), DiagramContext::stringLongerThan); std::sort(keys_list.begin(), keys_list.end(), DiagramContext::stringLongerThan);
} }
@@ -42,14 +45,14 @@ QList<QString> DiagramContext::keys(DiagramContext::KeyOrder order) const {
@return true if that key is known to the diagram context, false otherwise @return true if that key is known to the diagram context, false otherwise
*/ */
bool DiagramContext::contains(const QString &key) const { bool DiagramContext::contains(const QString &key) const {
return(content_.contains(key)); return(m_content.contains(key));
} }
/** /**
@param key @param key
*/ */
const QVariant DiagramContext::operator[](const QString &key) const { const QVariant DiagramContext::operator[](const QString &key) const {
return(content_[key]); return(m_content[key]);
} }
/** /**
@@ -64,8 +67,8 @@ const QVariant DiagramContext::operator[](const QString &key) const {
*/ */
bool DiagramContext::addValue(const QString &key, const QVariant &value, bool show) { bool DiagramContext::addValue(const QString &key, const QVariant &value, bool show) {
if (keyIsAcceptable(key)) { if (keyIsAcceptable(key)) {
content_.insert(key, value); m_content.insert(key, value);
content_show.insert(key, show); m_content_show.insert(key, show);
return(true); return(true);
} }
return(false); return(false);
@@ -75,15 +78,15 @@ bool DiagramContext::addValue(const QString &key, const QVariant &value, bool sh
Clear the content of this diagram context. Clear the content of this diagram context.
*/ */
void DiagramContext::clear() { void DiagramContext::clear() {
content_.clear(); m_content.clear();
content_show.clear(); m_content_show.clear();
} }
/** /**
@return the number of key/value pairs stored in this object. @return the number of key/value pairs stored in this object.
*/ */
int DiagramContext::count() { int DiagramContext::count() {
return(content_.count()); return(m_content.count());
} }
/** /**
@@ -91,14 +94,14 @@ int DiagramContext::count() {
* @return the value pairs with key, if key no found, return false * @return the value pairs with key, if key no found, return false
*/ */
bool DiagramContext::keyMustShow(const QString &key) const { bool DiagramContext::keyMustShow(const QString &key) const {
if (content_show.contains(key)) if (m_content_show.contains(key))
return content_show[key]; return m_content_show[key];
return false; return false;
} }
bool DiagramContext::operator==(const DiagramContext &dc) const { bool DiagramContext::operator==(const DiagramContext &dc) const {
return(content_ == dc.content_ && return(m_content == dc.m_content &&
content_show == dc.content_show); m_content_show == dc.m_content_show);
} }
bool DiagramContext::operator!=(const DiagramContext &dc) const { bool DiagramContext::operator!=(const DiagramContext &dc) const {
@@ -113,8 +116,8 @@ void DiagramContext::toXml(QDomElement &e, const QString &tag_name) const {
foreach (QString key, keys()) { foreach (QString key, keys()) {
QDomElement property = e.ownerDocument().createElement(tag_name); QDomElement property = e.ownerDocument().createElement(tag_name);
property.setAttribute("name", key); property.setAttribute("name", key);
property.setAttribute("show",content_show[key]); property.setAttribute("show",m_content_show[key]);
QDomText value = e.ownerDocument().createTextNode(content_[key].toString()); QDomText value = e.ownerDocument().createTextNode(m_content[key].toString());
property.appendChild(value); property.appendChild(value);
e.appendChild(property); e.appendChild(property);
} }
@@ -128,7 +131,7 @@ void DiagramContext::fromXml(const QDomElement &e, const QString &tag_name) {
foreach (QDomElement property, QET::findInDomElement(e, tag_name)) { foreach (QDomElement property, QET::findInDomElement(e, tag_name)) {
if (!property.hasAttribute("name")) continue; if (!property.hasAttribute("name")) continue;
addValue(property.attribute("name"), QVariant(property.text())); addValue(property.attribute("name"), QVariant(property.text()));
content_show.insert(property.attribute("name"), property.attribute("show", "1").toInt()); m_content_show.insert(property.attribute("name"), property.attribute("show", "1").toInt());
} }
} }
@@ -139,10 +142,10 @@ void DiagramContext::fromXml(const QDomElement &e, const QString &tag_name) {
void DiagramContext::toSettings(QSettings &settings, const QString &array_name) const { void DiagramContext::toSettings(QSettings &settings, const QString &array_name) const {
settings.beginWriteArray(array_name); settings.beginWriteArray(array_name);
int i = 0; int i = 0;
foreach (QString key, content_.keys()) { foreach (QString key, m_content.keys()) {
settings.setArrayIndex(i); settings.setArrayIndex(i);
settings.setValue("name", key); settings.setValue("name", key);
settings.setValue("value", content_[key].toString()); settings.setValue("value", m_content[key].toString());
++ i; ++ i;
} }
settings.endArray(); settings.endArray();

View File

@@ -75,7 +75,7 @@ class DiagramContext {
static bool stringLongerThan(const QString &, const QString &); static bool stringLongerThan(const QString &, const QString &);
bool keyIsAcceptable(const QString &) const; bool keyIsAcceptable(const QString &) const;
/// Diagram context data (key/value pairs) /// Diagram context data (key/value pairs)
QHash<QString, QVariant> content_; QHash<QString, QVariant> m_content;
QHash<QString, bool> content_show; QHash<QString, bool> m_content_show;
}; };
#endif #endif