[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasmate/terietor/kconfigxt] editors/kconfigxt: present the data correctly in the ui
From: Giorgos Tsiapaliwkas <terietor () gmail ! com>
Date: 2012-07-14 17:22:55
Message-ID: 20120714172255.F31B8A60C6 () git ! kde ! org
[Download RAW message or body]
Git commit 41182f7b0b40b02e9e11b4632c8cdc76c10d712d by Giorgos Tsiapaliwkas.
Committed on 13/07/2012 at 16:02.
Pushed by tsiapaliwkas into branch 'terietor/kconfigxt'.
present the data correctly in the ui
M +23 -20 editors/kconfigxt/kconfigxteditor.cpp
M +6 -2 editors/kconfigxt/kconfigxteditor.h
M +16 -2 editors/kconfigxt/kconfigxtparser.cpp
M +2 -0 editors/kconfigxt/kconfigxtparser.h
http://commits.kde.org/plasmate/41182f7b0b40b02e9e11b4632c8cdc76c10d712d
diff --git a/editors/kconfigxt/kconfigxteditor.cpp \
b/editors/kconfigxt/kconfigxteditor.cpp index e4ee6ce..a780912 100644
--- a/editors/kconfigxt/kconfigxteditor.cpp
+++ b/editors/kconfigxt/kconfigxteditor.cpp
@@ -70,8 +70,6 @@ void KConfigXtEditor::readFile()
return;
} else {
m_parser.setConfigXmlFile(m_filename.pathOrUrl());
- //parse the xml
- m_parser.parse();
takeDataFromParser();
setupWidgetsForOldFile();
}
@@ -131,19 +129,24 @@ void KConfigXtEditor::addGroupToUi(const QString& group)
void KConfigXtEditor::setupWidgetsForEntries(QTreeWidgetItem *item)
{
+ if (!item) {
+ return;
+ }
+
//the currectIndex of m_ui.twGroups has changed.
//this means that we need to load the data for the new
//group so remove the old items
m_ui.twEntries->clear();
- if (!item) {
- return;
- }
+ //also we will take new keys values and types so clear our list
+ m_keysValuesTypes.clear();
//take keys,values and types for the specified group
takeDataFromParser(item->text(0));
- addEntryToUi(m_keysValuesTypes.entryName(), m_keysValuesTypes.entryType(), \
m_keysValuesTypes.entryValue()); + foreach(const KConfigXtParserItem& item, \
m_keysValuesTypes) { + addEntryToUi(item.entryName(), item.entryType(), \
item.entryValue()); + }
}
@@ -158,25 +161,25 @@ void KConfigXtEditor::addEntryToUi(const QString& key, const \
QString& type, cons
void KConfigXtEditor::takeDataFromParser(const QString& group)
{
+
+ //we need to update the data of our parser first
+ m_parser.parse();
+
foreach(const KConfigXtParserItem& item, m_parser.dataList()) {
- //take the name of the groups
- if (!item.groupName().isEmpty()) {
+ //take the name of the groups also due to the fact
+ //that we take data from a parser we have to be careful so
+ //check if the group exists in the list
+ if (!item.groupName().isEmpty() && !m_groups.contains(item.groupName())) {
m_groups << item.groupName();
}
- if (!group.isEmpty()) {
- if (item.groupName() == group) {
- //we have specified a group
- //so probably we want to populate the
- //m_ui.twEntries.
- m_keysValuesTypes = item;
- } else {
- //we haven't specified a group.
- //So we don't want to populate the m_ui.twEntries.
- //clear the item.
- m_keysValuesTypes = KConfigXtParserItem();
- }
+ if (!group.isEmpty() && item.groupName() == group
+ && !m_keysValuesTypes.contains(item)) {
+ //we have specified a group
+ //so probably we want to populate the
+ //m_ui.twEntries.
+ m_keysValuesTypes.append(item);
}
}
}
diff --git a/editors/kconfigxt/kconfigxteditor.h \
b/editors/kconfigxt/kconfigxteditor.h index 0983481..fd7b37f 100644
--- a/editors/kconfigxt/kconfigxteditor.h
+++ b/editors/kconfigxt/kconfigxteditor.h
@@ -109,7 +109,11 @@ private:
* This method takes the groups from the parser
* If group is specified it will also take the
* keys,values and types from the parser for the specified group
- **/
+ *
+ * NOTE: after the call of this method use can use m_groups
+ * and m_keysValuesTypes
+ */
+
void takeDataFromParser(const QString& group = QString());
//with this method we avoid duplication
@@ -129,7 +133,7 @@ private:
KUrl m_filename;
QStringList m_groups;
- KConfigXtParserItem m_keysValuesTypes;
+ QList<KConfigXtParserItem> m_keysValuesTypes;
KConfigXtParser m_parser;
};
diff --git a/editors/kconfigxt/kconfigxtparser.cpp \
b/editors/kconfigxt/kconfigxtparser.cpp index 52b8d0a..994596c 100644
--- a/editors/kconfigxt/kconfigxtparser.cpp
+++ b/editors/kconfigxt/kconfigxtparser.cpp
@@ -61,6 +61,15 @@ void KConfigXtParserItem::setEntryName(const QString& entryName)
m_entryName = entryName;
}
+bool KConfigXtParserItem::operator==(const KConfigXtParserItem& item)
+{
+ if (this->entryName() == item.entryName()) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
void KConfigXtParserItem::setEntryType(const QString& entryType)
{
//those are the possible types
@@ -116,6 +125,11 @@ void KConfigXtParser::setConfigXmlFile(const QString& filename)
bool KConfigXtParser::parse()
{
+ //we will parse the xml again so clear the list
+ if (!m_dataList.isEmpty()) {
+ m_dataList.clear();
+ }
+
QFile xmlFile(m_filename);
if (!xmlFile.open(QIODevice::ReadWrite)) {
@@ -151,7 +165,6 @@ bool KConfigXtParser::parse()
m_parseResult = false;
}
- m_dataList.append(m_data);
//the parse was successfull
m_parseResult = true;
@@ -216,7 +229,6 @@ void KConfigXtParser::parseEntry(QXmlStreamReader& reader)
//for as long as we are inside the entry element
//we need to search for its value
- int counter = 0;
while(!(reader.tokenType() == QXmlStreamReader::EndElement &&
reader.name() == "entry")) {
@@ -238,6 +250,8 @@ void KConfigXtParser::parseEntry(QXmlStreamReader& reader)
}
reader.readNext();
}
+ //add the data in our datalist
+ m_dataList.append(m_data);
}
QList<KConfigXtParserItem> KConfigXtParser::dataList() const
diff --git a/editors/kconfigxt/kconfigxtparser.h \
b/editors/kconfigxt/kconfigxtparser.h index 73aaedd..cb964bd 100644
--- a/editors/kconfigxt/kconfigxtparser.h
+++ b/editors/kconfigxt/kconfigxtparser.h
@@ -44,6 +44,8 @@ public:
QString entryValue() const;
void setEntryValue(const QString& entryValue);
+ bool operator==(const KConfigXtParserItem& item);
+
private:
QString m_groupName;
QString m_entryName;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic