Skip to content

Commit 9ae5202

Browse files
committed
Optionally use the text edit panel for attribute values.
1 parent 3cae02d commit 9ae5202

File tree

7 files changed

+169
-24
lines changed

7 files changed

+169
-24
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
0.9.15
2+
Optionally use the text edit panel for attribute values.
23
Issue #69, compilation error.
34
Configuration option to disable TODO functions.
45
Text panel full screen if text length greater than a threshold.

src/EditElement.ui

+27-6
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,23 @@
357357
</property>
358358
</widget>
359359
</item>
360+
<item>
361+
<widget class="QPushButton" name="cmdEditAttributeAdvanced">
362+
<property name="enabled">
363+
<bool>false</bool>
364+
</property>
365+
<property name="text">
366+
<string>&amp;Edit Panel</string>
367+
</property>
368+
</widget>
369+
</item>
360370
<item>
361371
<widget class="QPushButton" name="cmdToBase64">
362372
<property name="enabled">
363373
<bool>false</bool>
364374
</property>
365375
<property name="text">
366-
<string>To base64</string>
376+
<string>To Base64</string>
367377
</property>
368378
</widget>
369379
</item>
@@ -373,7 +383,7 @@
373383
<bool>false</bool>
374384
</property>
375385
<property name="text">
376-
<string>From base64</string>
386+
<string>From Base64</string>
377387
</property>
378388
</widget>
379389
</item>
@@ -386,7 +396,7 @@
386396
<string>s</string>
387397
</property>
388398
<property name="text">
389-
<string>Save base64</string>
399+
<string>Save Base64</string>
390400
</property>
391401
</widget>
392402
</item>
@@ -399,7 +409,7 @@
399409
<string>Load a binary file and insert it into the current attribute as base64 coded text.</string>
400410
</property>
401411
<property name="text">
402-
<string>Load base64</string>
412+
<string>Load Base64</string>
403413
</property>
404414
</widget>
405415
</item>
@@ -466,14 +476,25 @@
466476
</action>
467477
</widget>
468478
<tabstops>
479+
<tabstop>editTag</tabstop>
480+
<tabstop>cmdNamespaces</tabstop>
481+
<tabstop>elementTable</tabstop>
482+
<tabstop>textAdd</tabstop>
469483
<tabstop>textDel</tabstop>
484+
<tabstop>textEdit</tabstop>
485+
<tabstop>textUp</tabstop>
486+
<tabstop>textDown</tabstop>
487+
<tabstop>attrTable</tabstop>
470488
<tabstop>newAttribute</tabstop>
471489
<tabstop>delAttribute</tabstop>
472-
<tabstop>buttonBox</tabstop>
490+
<tabstop>cmdEditAttributeAdvanced</tabstop>
491+
<tabstop>cmdToBase64</tabstop>
492+
<tabstop>cmdFromBase64</tabstop>
493+
<tabstop>cmdSaveFileBase64</tabstop>
494+
<tabstop>cmdLoadFileBase64</tabstop>
473495
</tabstops>
474496
<resources>
475497
<include location="risorse.qrc"/>
476-
<include location="risorse.qrc"/>
477498
</resources>
478499
<connections>
479500
<connection>

src/editelement.cpp

+47-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************
22
* This file is part of QXmlEdit *
3-
* Copyright (C) 2011-2018 by Luca Bellonda and individual contributors *
3+
* Copyright (C) 2011-2020 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -44,6 +44,7 @@ EditElement::EditElement(QWidget * parent) : QDialog(parent)
4444
modColor = QColor::fromRgb(255, 128, 128);
4545
isMixedContent = false ;
4646
ui.setupUi(this);
47+
attributesSelectionChanged(false);
4748
ui.elementTable->setColumnWidth(T_COLUMN_MOD, MOD_WIDTH);
4849
ui.attrTable->setColumnWidth(A_COLUMN_MOD, MOD_WIDTH);
4950
_attributeTextDelegate = new AttributeColumnItemDelegate(ui.attrTable, A_COLUMN_TEXT, ui.attrTable);
@@ -248,7 +249,7 @@ bool EditElement::updateTarget(Element *targetElement)
248249
}
249250

250251
Utils::TODO_NEXT_RELEASE("this part must be tested very well");
251-
//if(_textModified) {
252+
252253
targetElement->clearTextNodes();
253254

254255
isMixedContent = false ;
@@ -462,11 +463,17 @@ void EditElement::on_attrTable_itemSelectionChanged()
462463
if(currentRow >= 0) {
463464
isSel = true ;
464465
}
466+
attributesSelectionChanged(isSel);
467+
}
468+
469+
void EditElement::attributesSelectionChanged(const bool isSel)
470+
{
465471
ui.delAttribute->setEnabled(isSel);
466472
ui.cmdToBase64->setEnabled(isSel);
467473
ui.cmdFromBase64->setEnabled(isSel);
468474
ui.cmdLoadFileBase64->setEnabled(isSel);
469475
ui.cmdSaveFileBase64->setEnabled(isSel);
476+
ui.cmdEditAttributeAdvanced->setEnabled(isSel);
470477
}
471478

472479
void EditElement::on_textDel_clicked()
@@ -724,20 +731,18 @@ void EditElement::doBase64Operation(const bool isFromBase64)
724731
int currentColumn = ui.attrTable->currentColumn();
725732
QTableWidgetItem *currentItem = ui.attrTable->currentItem() ;
726733
if((NULL != currentItem) && (currentRow >= 0) && ((A_COLUMN_NAME == currentColumn) || (A_COLUMN_TEXT == currentColumn))) {
727-
//ui.attrTable->closePersistentEditor(currentItem);
728-
QString text = currentItem->text();
729-
QString newText ;
730-
if(isFromBase64) {
731-
newText = Utils::fromBase64(text);
732-
} else {
733-
newText = Utils::toBase64(text);
734+
QTableWidgetItem *textItem = ui.attrTable->item(currentRow, A_COLUMN_TEXT) ;
735+
if(NULL != textItem) {
736+
QString text = textItem->text();
737+
QString newText ;
738+
if(isFromBase64) {
739+
newText = Utils::fromBase64(text);
740+
} else {
741+
newText = Utils::toBase64(text);
742+
}
743+
setNewAttributeText(currentRow, newText);
734744
}
735-
currentItem->setText(newText);
736-
setUpdatedAttr(currentRow);
737-
ui.attrTable->setCurrentItem(currentItem);
738-
ui.attrTable->setFocus();
739745
}
740-
741746
}
742747

743748
void EditElement::on_cmdToBase64_clicked()
@@ -918,3 +923,31 @@ void EditElement::on_cmdSaveFileBase64_clicked()
918923
base64Utils.saveBase64ToBinaryFile(Base64Utils::RFC4648Standard, this, text, QXmlEditData::sysFilePathForOperation(""));
919924
}
920925

926+
void EditElement::on_cmdEditAttributeAdvanced_clicked()
927+
{
928+
int currentRow = ui.attrTable->currentRow();
929+
if(currentRow >= 0) {
930+
QTableWidgetItem *attributeNameItem = ui.attrTable->item(currentRow, A_COLUMN_NAME);
931+
QTableWidgetItem *currentItem = ui.attrTable->item(currentRow, A_COLUMN_TEXT);
932+
if((NULL != currentItem) && (NULL != attributeNameItem)) {
933+
EditTextNode editDialog(false, tr("Attribute: %1").arg(attributeNameItem->text()), this);
934+
editDialog.setWindowModality(Qt::WindowModal);
935+
editDialog.setText(currentItem->text());
936+
if(editDialog.exec() == QDialog::Accepted) {
937+
const QString & newText = editDialog.getText();
938+
setNewAttributeText(currentRow, newText);
939+
}
940+
}
941+
}
942+
}
943+
944+
void EditElement::setNewAttributeText(const int row, const QString &newText)
945+
{
946+
QTableWidgetItem *currentItem = ui.attrTable->item(row, A_COLUMN_TEXT);
947+
currentItem->setText(newText);
948+
setUpdatedAttr(row);
949+
ui.attrTable->setCurrentItem(currentItem);
950+
ui.attrTable->setFocus();
951+
ui.attrTable->resizeRowToContents(row);
952+
}
953+

src/editelement.h

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class EditElement : public QDialog
9696
void setTextToItem(QTableWidgetItem *item, const QString &text);
9797
QString textFromItem(QTableWidgetItem *item);
9898
QHash<QString, QString> getNsFromAttributes();
99+
void attributesSelectionChanged(const bool isSel);
100+
void setNewAttributeText(const int row, const QString &newText);
99101

100102
public slots:
101103
void accept();
@@ -117,6 +119,7 @@ private slots:
117119
void on_cmdNamespaces_clicked();
118120
void on_cmdLoadFileBase64_clicked();
119121
void on_cmdSaveFileBase64_clicked();
122+
void on_cmdEditAttributeAdvanced_clicked();
120123

121124
private:
122125
Ui::Dialog ui;
@@ -142,6 +145,10 @@ private slots:
142145
void doBase64Operation(const bool isFromBase64);
143146
void applyNamespaceOper(NamespaceCommands *commands);
144147
bool updateTarget(Element *element);
148+
149+
#ifdef QXMLEDIT_TEST
150+
friend class TestEditElements;
151+
#endif
145152
};
146153

147154
#endif

src/languages_lib/QXmlEditWidget_cs.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1979,12 +1979,12 @@ row=%1, column=%2</source>
19791979
</message>
19801980
<message>
19811981
<location filename="../EditElement.ui" line="366"/>
1982-
<source>To base64</source>
1982+
<source>To Base64</source>
19831983
<translation>Do Base 64</translation>
19841984
</message>
19851985
<message>
19861986
<location filename="../EditElement.ui" line="376"/>
1987-
<source>From base64</source>
1987+
<source>From Base64</source>
19881988
<translation>Od Base 64</translation>
19891989
</message>
19901990
<message>
@@ -1994,7 +1994,7 @@ row=%1, column=%2</source>
19941994
</message>
19951995
<message>
19961996
<location filename="../EditElement.ui" line="389"/>
1997-
<source>Save base64</source>
1997+
<source>Save Base64</source>
19981998
<translation>Uložit base64</translation>
19991999
</message>
20002000
<message>
@@ -2004,7 +2004,7 @@ row=%1, column=%2</source>
20042004
</message>
20052005
<message>
20062006
<location filename="../EditElement.ui" line="402"/>
2007-
<source>Load base64</source>
2007+
<source>Load Base64</source>
20082008
<translation>Nahrát base64</translation>
20092009
</message>
20102010
<message>

test/testeditelements.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,10 @@ bool TestEditElements::testInsertElement()
10831083

10841084
bool TestEditElements::testFast()
10851085
{
1086+
Utils::TODO_THIS_RELEASE("elimina ridondante");
1087+
if(!testEditAttributes()) {
1088+
return false;
1089+
}
10861090
if(!testEditSearchTwo()) {
10871091
return false;
10881092
}
@@ -1491,6 +1495,9 @@ bool TestEditElements::testUnit()
14911495
if(!testActivationEdit()) {
14921496
return false;
14931497
}
1498+
if(!testEditAttributes()) {
1499+
return false;
1500+
}
14941501
return true;
14951502
}
14961503

@@ -1529,3 +1536,76 @@ bool TestEditElements::testActivationEdit()
15291536
}
15301537
return true;
15311538
}
1539+
1540+
bool TestEditElements::testEditAttributes()
1541+
{
1542+
_testName = "testEditAttributes";
1543+
if(!testEditAttributeText()) {
1544+
return false;
1545+
}
1546+
if(!testEditAttributeBase64()) {
1547+
return false;
1548+
}
1549+
return true ;
1550+
}
1551+
1552+
bool TestEditElements::testEditAttributeText()
1553+
{
1554+
_testName = "testEditAttributeText";
1555+
const QString NewText = "XXX YY ZZ";
1556+
Element startElement( "x", "", NULL, NULL) ;
1557+
Element referenceElement( "x", "", NULL, NULL) ;
1558+
startElement.addAttribute("a", "aa");
1559+
startElement.addAttribute("b", "bb");
1560+
startElement.addAttribute("c", "cc");
1561+
referenceElement.addAttribute("a", "aa");
1562+
referenceElement.addAttribute("b", NewText);
1563+
referenceElement.addAttribute("c", "cc");
1564+
1565+
//----
1566+
EditElement editElement;
1567+
editElement.setTarget(&startElement);
1568+
editElement.show();
1569+
editElement.setAttrFocus(1);
1570+
editElement.setNewAttributeText(1, NewText);
1571+
editElement.accept();
1572+
//----
1573+
1574+
QString message;
1575+
if(!referenceElement.compareToElement(&startElement, message)) {
1576+
return error(QString("Element differ :%1").arg(message));
1577+
}
1578+
return true;
1579+
}
1580+
1581+
bool TestEditElements::testEditAttributeBase64()
1582+
{
1583+
_testName = "testEditAttributeBase64";
1584+
Element startElement( "x", "", NULL, NULL) ;
1585+
Element referenceElement( "x", "", NULL, NULL) ;
1586+
startElement.addAttribute("a", "aa"); //YWE=
1587+
startElement.addAttribute("b", "YmI="); //bb
1588+
startElement.addAttribute("c", "cc");
1589+
referenceElement.addAttribute("a", "YWE=");
1590+
referenceElement.addAttribute("b", "bb");
1591+
referenceElement.addAttribute("c", "cc");
1592+
1593+
//----
1594+
EditElement editElement;
1595+
editElement.setTarget(&startElement);
1596+
editElement.show();
1597+
editElement.setAttrFocus(0);
1598+
QTest::mouseClick ( editElement.ui.cmdToBase64, Qt::LeftButton, Qt::NoModifier);
1599+
QApplication::processEvents();
1600+
editElement.setAttrFocus(1);
1601+
QTest::mouseClick ( editElement.ui.cmdFromBase64, Qt::LeftButton, Qt::NoModifier);
1602+
QApplication::processEvents();
1603+
editElement.accept();
1604+
//----
1605+
1606+
QString message;
1607+
if(!referenceElement.compareToElement(&startElement, message)) {
1608+
return error(QString("Element differ :%1").arg(message));
1609+
}
1610+
return true;
1611+
}

test/testeditelements.h

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class TestEditElements : public TestBase
123123
const QString& expectedTag, const QString& expectedAttributes );
124124
bool verifyTestActivationEdit(XmlEditWidgetPrivate *target, App &app, const bool baseEditModeForm, const bool isNormalMode, const XmlEditWidgetPrivate::EEditMode expected );
125125
bool testActivationEdit();
126+
bool testEditAttributes();
127+
bool testEditAttributeText();
128+
bool testEditAttributeBase64();
126129
public:
127130
TestEditElements();
128131
virtual ~TestEditElements();

0 commit comments

Comments
 (0)