From kde-commits Fri Jul 27 23:44:14 2012 From: Giorgos Tsiapaliwkas Date: Fri, 27 Jul 2012 23:44:14 +0000 To: kde-commits Subject: [plasmate/terietor/kconfigxt] editors/kconfigxt: Modify the description type Message-Id: <20120727234414.E92AFA6094 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=134343292609070 Git commit 848b7fcdd255e84197ccf67e0b46c9ff1344605b by Giorgos Tsiapaliwkas. Committed on 28/07/2012 at 01:23. Pushed by tsiapaliwkas into branch 'terietor/kconfigxt'. Modify the description type M +52 -6 editors/kconfigxt/kconfigxteditor.cpp M +5 -0 editors/kconfigxt/kconfigxteditor.h http://commits.kde.org/plasmate/848b7fcdd255e84197ccf67e0b46c9ff1344605b diff --git a/editors/kconfigxt/kconfigxteditor.cpp b/editors/kconfigxt/kcon= figxteditor.cpp index e6446ed..6b4272a 100644 --- a/editors/kconfigxt/kconfigxteditor.cpp +++ b/editors/kconfigxt/kconfigxteditor.cpp @@ -52,6 +52,9 @@ KConfigXtEditor::KConfigXtEditor(QWidget *parent) connect(m_ui.twGroups, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(setupWidgetsForEntries(QTreeWidgetItem*))); = + connect(m_ui.twEntries, SIGNAL(currentItemChanged(QTreeWidgetItem*, QT= reeWidgetItem*)), + this, SLOT(entryItemWidgetState(QTreeWidgetItem*, QTreeWidgetI= tem*))); + connect(m_ui.twGroups, SIGNAL(itemPressed(QTreeWidgetItem*, int)), thi= s, SLOT(setLastGroupItem(QTreeWidgetItem*, int))); connect(m_ui.twEntries, SIGNAL(itemPressed(QTreeWidgetItem*, int)), th= is, SLOT(setLastEntryItem(QTreeWidgetItem*))); = @@ -219,6 +222,10 @@ void KConfigXtEditor::addEntryToUi(const QString& key,= const QString& type, descriptionButton->addItem("ToolTip"); descriptionButton->addItem("WhatsThis"); = + //we need a valid QTreeWidgetItem in order to enable the button, + //so disable it for now, and leave the signal to do the work! + descriptionButton->setEnabled(false); + connect(descriptionButton, SIGNAL(currentIndexChanged(int)), this, SLO= T(modifyTypeDescription())); = //find the correct index @@ -241,6 +248,7 @@ void KConfigXtEditor::addEntryToUi(const QString& key, = const QString& type, item->setFlags(item->flags() | Qt::ItemIsEditable); = m_ui.twEntries->setItemWidget(item, 3, descriptionButton); + } = void KConfigXtEditor::takeDataFromParser() @@ -259,12 +267,10 @@ void KConfigXtEditor::takeDataFromParser() } = if (!m_keysValuesTypes.contains(item) && - !item.entryName().isEmpty()) - { + !item.entryName().isEmpty()) { //take the entries m_keysValuesTypes.append(item); } - } } } @@ -314,7 +320,6 @@ void KConfigXtEditor::modifyEntry(QTreeWidgetItem* item= , int column) //create the entry const QString oldEntry =3D stringToEntryAndValue(m_lastEntryItem["name= "], m_lastEntryItem["type"]= ); - if (column =3D=3D 0 || column =3D=3D 1) { //the user has modified either the //key or its type. @@ -340,9 +345,9 @@ void KConfigXtEditor::modifyEntry(QTreeWidgetItem* item= , int column) return; } = - QByteArray text; + QByteArray text; = - while (!xmlFile.atEnd()) { + while (!xmlFile.atEnd()) { QString line =3D xmlFile.readLine(); if (line.contains(oldEntry)) { while (!line.contains("")) { @@ -384,16 +389,24 @@ void KConfigXtEditor::modifyEntry(QTreeWidgetItem* it= em, int column) if (bt->currentIndex() =3D=3D 0) { //it's a label newDescription =3D stringToDescription("label", item->text(4)); + //our descriptionType is about to change, so update its value + m_lastEntryItem["descriptionType"] =3D "label"; } else if (bt->currentIndex() =3D=3D 1) { //it's a tooltip newDescription =3D stringToDescription("tooltip", item->text(4= )); + //our descriptionType is about to change, so update its value + m_lastEntryItem["descriptionType"] =3D "tooltip"; } else if (bt->currentIndex() =3D=3D2) { //it's a whatsthis newDescription =3D stringToDescription("whatsthis", item->text= (4)); + //our descriptionType is about to change, so update its value + m_lastEntryItem["descriptionType"] =3D "whatsthis"; } + //replace the items replaceItemsInXml(oldDescription, newDescription); } else if (column =3D=3D 4) { + const QString oldDescription =3D stringToDescription(m_lastEntryIt= em["descriptionType"], m_lastEntryItem[= "descriptionValue"]); = @@ -404,6 +417,39 @@ void KConfigXtEditor::modifyEntry(QTreeWidgetItem* ite= m, int column) } } = +void KConfigXtEditor::entryItemWidgetState(QTreeWidgetItem *currentItem, Q= TreeWidgetItem *previousItem) +{ + + //we need to check every button/item individually because, + //the first time that the signal will be emited the previousItem + //will be 0, because there is no previousItem at that time, only + //the currentItem is valid + + KComboBox *previousBt =3D 0; + KComboBox *currentBt =3D 0; + + if (previousItem) { + previousBt =3D qobject_cast(m_ui.twEntries->itemWidget= (previousItem, 3)); + + if (previousBt) { + if (previousBt->isEnabled()) { + previousBt->setEnabled(false); + } + } + } + + if (currentItem) { + currentBt =3D qobject_cast(m_ui.twEntries->itemWidget(= currentItem, 3)); + + if (currentBt) { + if (!currentBt->isEnabled()) { + currentBt->setEnabled(true); + } + } + } + +} + void KConfigXtEditor::setLastEntryItem(QTreeWidgetItem* item) { //check if ptr is evil diff --git a/editors/kconfigxt/kconfigxteditor.h b/editors/kconfigxt/kconfi= gxteditor.h index dc79108..7300326 100644 --- a/editors/kconfigxt/kconfigxteditor.h +++ b/editors/kconfigxt/kconfigxteditor.h @@ -123,6 +123,11 @@ private slots: **/ void setLastEntryItem(QTreeWidgetItem* item); = + /** + * It will enable and disable the itemWidget of the entry + **/ + void entryItemWidgetState(QTreeWidgetItem* currentItem, QTreeWidgetIte= m* previousItem); + protected: Ui::KConfigXtEditor m_ui; =