Skip to content

Commit 7920c64

Browse files
committed
Stochastic anonymization (test)
1 parent e4e7be7 commit 7920c64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4268
-184
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
0.9.18
2+
New algorithm to anonymize data.
23
Issue #84, added options for metadata installation folders.
34
Issue #86, show license dialog at first startup.
45

src/QXmlEditWidget.pro

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#/**************************************************************************
22
# * This file is part of QXmlEdit *
3-
# * Copyright (C) 2011-2021 by Luca Bellonda and individual contributors *
3+
# * Copyright (C) 2011-2022 by Luca Bellonda and individual contributors *
44
# * as indicated in the AUTHORS file *
55
# * lbellonda _at_ gmail.com *
66
# * *
@@ -297,7 +297,7 @@ SOURCES += xmleditwidget.cpp \
297297
modules/anonymize/anonexception.cpp \
298298
modules/anonymize/anonprofile.cpp \
299299
modules/anonymize/anonymizeparameters.cpp \
300-
modules/anonymize/anonfixedalg.cpp \
300+
modules/anonymize/anonfixedproducer.cpp \
301301
modules/anonymize/anoncodealg.cpp \
302302
modules/anonymize/anonallalg.cpp \
303303
modules/anonymize/anonseqproducer.cpp \
@@ -438,6 +438,8 @@ SOURCES += xmleditwidget.cpp \
438438
extraction/extractionscriptingprovider.cpp \
439439
extraction/scripting/events/extractionoperationscriptcontext.cpp
440440

441+
SOURCES += $$files(../src/modules/anonymize/algstat/*.cpp)
442+
441443
HEADERS += precompiled_lib.h \
442444
globals/includes/bookmark.h \
443445
framework/include/log.h \
@@ -609,7 +611,7 @@ HEADERS += precompiled_lib.h \
609611
modules/anonymize/anonexception.h \
610612
modules/anonymize/anonprofile.h \
611613
modules/anonymize/anonymizeparameters.h \
612-
modules/anonymize/anonfixedalg.h \
614+
modules/anonymize/anonfixedproducer.h \
613615
modules/anonymize/anoncodealg.h \
614616
modules/anonymize/anonallalg.h \
615617
modules/anonymize/anonseqproducer.h \
@@ -726,6 +728,7 @@ HEADERS += precompiled_lib.h \
726728
extraction/extractionscriptingprovider.h \
727729
extraction/scripting/events/extractionoperationscriptcontext.h
728730

731+
HEADERS += $$files(../src/modules/anonymize/algstat/*.h)
729732

730733
FORMS += xmleditwidget.ui \
731734
alloweditemsinsert.ui \

src/allsources.pri

+4-1
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-2022 by Luca Bellonda and individual contributors *
44
# * as indicated in the AUTHORS file *
55
# * lbellonda _at_ gmail.com *
66
# * *
@@ -44,6 +44,7 @@ SOURCES += $$files(../src/undo/*.cpp)
4444
SOURCES += $$files(../src/sessions/data_access/*.cpp)
4545
SOURCES += $$files(../src/sessions/data_access/model/*.cpp)
4646
SOURCES += $$files(../src/modules/anonymize/*.cpp)
47+
SOURCES += $$files(../src/modules/anonymize/algstat/*.cpp)
4748
SOURCES += $$files(../src/modules/binaryviewer/*.cpp)
4849
SOURCES += $$files(../src/modules/compare/*.cpp)
4950
SOURCES += $$files(../src/modules/graph/*.cpp)
@@ -96,6 +97,7 @@ HEADERS += $$files(../src/sessions/data_access/model*.h)
9697
HEADERS += $$files(../src/framework/include/*.h)
9798
HEADERS += $$files(../src/globals/includes/*.h)
9899
HEADERS += $$files(../src/modules/anonymize/*.h)
100+
HEADERS += $$files(../src/modules/anonymize/algstat/*.h)
99101
HEADERS += $$files(../src/modules/binaryviewer/*.h)
100102
HEADERS += $$files(../src/modules/compare/*.h)
101103
HEADERS += $$files(../src/modules/graph/*.h)
@@ -196,3 +198,4 @@ FORMS += $$files(../src/modules/messages/*.ui)
196198
FORMS += $$files(../src/modules/help/*.ui)
197199

198200
RESOURCES += ../src/risorse.qrc
201+

src/config.cpp

+4-1
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-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -253,6 +253,9 @@ const QString Config::KEY_TEST("test");
253253
const QString Config::KEY_TOOLS_XMLBEANS_INST2XSD("tools/xmlbeans/inst2xsd");
254254
const QString Config::KEY_TOOLS_XMLBEANS_XSD2INST("tools/xmlbeans/xsd2inst");
255255

256+
// anon
257+
const QString Config::KEY_ANON_TEXT_LEGACY("anon/textLegacy");
258+
256259
//------------------------------------------------------
257260
static QSettings *config = NULL ;
258261

src/config/configurexmlmanagementdialog.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************
22
* This file is part of QXmlEdit *
3-
* Copyright (C) 2013-2018 by Luca Bellonda and individual contributors *
3+
* Copyright (C) 2013-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -65,6 +65,7 @@ void ConfigureXMLManagementDialog::init(ApplicationData* data)
6565
_attributeHelper.setUp(data->xmlIndentAttributesType(), data->xmlIndentAttributes());
6666
ui->cbProcessFormattingMetadata->setChecked(data->isFormattingInfoEnabled());
6767
ui->cbInsertFormattingMetadata->setChecked(data->isFormattingInfoInsertOnNew());
68+
ui->cbAnonLegacyAlg->setChecked(Config::getBool(Config::KEY_ANON_TEXT_LEGACY, false));
6869
_started = true ;
6970
}
7071

@@ -181,3 +182,10 @@ void ConfigureXMLManagementDialog::on_cbInsertFormattingMetadata_stateChanged(in
181182
_data->setFormattingInfoInsertOnNew(ui->cbInsertFormattingMetadata->isChecked());
182183
}
183184
}
185+
186+
void ConfigureXMLManagementDialog::on_cbAnonLegacyAlg_stateChanged(int /*state*/)
187+
{
188+
if(_started) {
189+
Config::saveBool(Config::KEY_ANON_TEXT_LEGACY, ui->cbAnonLegacyAlg->isChecked());
190+
}
191+
}

src/config/configurexmlmanagementdialog.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************
22
* This file is part of QXmlEdit *
3-
* Copyright (C) 2013-2018 by Luca Bellonda and individual contributors *
3+
* Copyright (C) 2013-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -68,6 +68,7 @@ private slots:
6868
void on_cmdPredefinedAttributes_clicked();
6969
void on_cbProcessFormattingMetadata_stateChanged(int /*state*/);
7070
void on_cbInsertFormattingMetadata_stateChanged(int /*state*/);
71+
void on_cbAnonLegacyAlg_stateChanged(int /*state*/);
7172
};
7273

7374
#endif // CONFIGUREXMLMANAGEMENTDIALOG_H

src/config/configurexmlmanagementdialog.ui

+40-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>638</width>
10-
<height>484</height>
10+
<height>495</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -39,7 +39,7 @@
3939
<string>Creation</string>
4040
</property>
4141
<property name="margin">
42-
<number>20</number>
42+
<number>16</number>
4343
</property>
4444
</widget>
4545
</item>
@@ -106,7 +106,7 @@
106106
<string>Metadata</string>
107107
</property>
108108
<property name="margin">
109-
<number>20</number>
109+
<number>16</number>
110110
</property>
111111
</widget>
112112
</item>
@@ -136,7 +136,7 @@
136136
<string>Save</string>
137137
</property>
138138
<property name="margin">
139-
<number>20</number>
139+
<number>16</number>
140140
</property>
141141
</widget>
142142
</item>
@@ -305,6 +305,42 @@
305305
</property>
306306
</widget>
307307
</item>
308+
<item>
309+
<widget class="QLabel" name="label_9">
310+
<property name="sizePolicy">
311+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
312+
<horstretch>0</horstretch>
313+
<verstretch>0</verstretch>
314+
</sizepolicy>
315+
</property>
316+
<property name="font">
317+
<font>
318+
<pointsize>12</pointsize>
319+
<weight>75</weight>
320+
<bold>true</bold>
321+
</font>
322+
</property>
323+
<property name="frameShape">
324+
<enum>QFrame::NoFrame</enum>
325+
</property>
326+
<property name="lineWidth">
327+
<number>0</number>
328+
</property>
329+
<property name="text">
330+
<string>Anonymization</string>
331+
</property>
332+
<property name="margin">
333+
<number>16</number>
334+
</property>
335+
</widget>
336+
</item>
337+
<item>
338+
<widget class="QCheckBox" name="cbAnonLegacyAlg">
339+
<property name="text">
340+
<string>Use legacy algorithm</string>
341+
</property>
342+
</widget>
343+
</item>
308344
</layout>
309345
</widget>
310346
<tabstops>

src/coptions.pri

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#/**************************************************************************
22
# * This file is part of QXmlEdit *
3-
# * Copyright (C) 2019 by Luca Bellonda and individual contributors *
3+
# * Copyright (C) 2019-2022 by Luca Bellonda and individual contributors *
44
# * as indicated in the AUTHORS file *
55
# * lbellonda _at_ gmail.com *
66
# * *

src/element.cpp

+1-40
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-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -2885,45 +2885,6 @@ bool Element::removeChild(Element *toDelete)
28852885
return false;
28862886
}
28872887

2888-
2889-
void Element::anonymize(AnonAlg *alg)
2890-
{
2891-
switch(type) {
2892-
case ET_ELEMENT:
2893-
anonymizeElement(alg);
2894-
break;
2895-
case ET_PROCESSING_INSTRUCTION:
2896-
break;
2897-
case ET_COMMENT:
2898-
break;
2899-
case ET_TEXT:
2900-
anonymizeText(alg);
2901-
default:
2902-
break;
2903-
}
2904-
foreach(Element * child, childItems) {
2905-
child->anonymize(alg);
2906-
}
2907-
}
2908-
2909-
void Element::anonymizeElement(AnonAlg *alg)
2910-
{
2911-
QVectorIterator<TextChunk*> tt(textNodes);
2912-
while(tt.hasNext()) {
2913-
TextChunk *tx = tt.next();
2914-
tx->text = alg->processText(tx->text);
2915-
}
2916-
foreach(Attribute * attribute, getAttributesList()) {
2917-
attribute->value = alg->processText(attribute->value);
2918-
}
2919-
}
2920-
2921-
void Element::anonymizeText(AnonAlg *alg)
2922-
{
2923-
text = alg->processText(text);
2924-
}
2925-
2926-
29272888
Element *Element::firstChildRecursiveOrThis()
29282889
{
29292890
if(childItems.isEmpty()) {

src/globals/includes/element.h

+7-6
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-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -139,6 +139,7 @@ class LIBQXMLEDITSHARED_EXPORT Attribute
139139
static void emptyList(QList<Attribute*> &sourceList);
140140

141141
void anonymize(AnonContext *context);
142+
void scanAnonymize(AnonContext *context);
142143

143144
};
144145

@@ -597,12 +598,15 @@ class LIBQXMLEDITSHARED_EXPORT Element
597598
const QString getIdUsingStyle(PaintInfo *paintInfo);
598599
void handleMapEncodingPreInsert(QDomNode &parent, ElementLoadInfoMap *dataMap);
599600
void handleMapEncodingPreInsert(ElementLoadInfoMap *dataMap);
600-
void anonymizeElement(AnonAlg *alg);
601-
void anonymizeText(AnonAlg *alg);
602601
QString anonymizeTextOfElement(AnonContext * context, const QString &inputText, void * key);
603602
void handleNamespace(AnonContext *context);
604603

605604
bool checkSaveAndSetIndent(XMLSaveContext *context, QXmlStreamWriter &writer) const;
605+
void scanAnonymize(AnonContext *context);
606+
void scanAnonymizeElement(AnonContext *context);
607+
void anonymizeElement(AnonContext *context);
608+
void anonymizeText(AnonContext *context);
609+
void anonymizeInternal(AnonContext *context);
606610

607611
public:
608612
bool areChildrenLeavesHidden(QTreeWidgetItem *twi);
@@ -636,10 +640,7 @@ class LIBQXMLEDITSHARED_EXPORT Element
636640
bool canRemoveParent();
637641
bool canInsertParent();
638642

639-
void anonymize(AnonAlg *alg);
640643
void anonymize(AnonContext *context);
641-
void anonymizeElement(AnonContext *context);
642-
void anonymizeText(AnonContext *context);
643644

644645
//---
645646
Element *firstChildRecursiveOrThis();

src/globals/includes/regola.h

+1-2
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-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -544,7 +544,6 @@ class LIBQXMLEDITSHARED_EXPORT Regola : public QAbstractItemModel, TextEditorInt
544544
//------------endregion(containers)
545545

546546
void addUndo(QUndoCommand *undoGroup);
547-
void anonymize(AnonAlg *alg);
548547
void anonymize(AnonContext *context, QTreeWidget *treeWidget, const bool doDirect = false);
549548

550549
QHash<QString, QString> mapOfSchemaReferences();

src/globals/includes/xmlEdit.h

+2-2
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-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -85,7 +85,7 @@ extern const char VERSION[] ;
8585
void msgBoxDebug(const QString message);
8686

8787
#ifdef QXML_DEBUG
88-
#define D(x) x
88+
#define D(x) do{x;}while(0)
8989
#else
9090
#define D(x)
9191
#endif

src/mainwndcontroller.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************
22
* This file is part of QXmlEdit *
3-
* Copyright (C) 2014-2018 by Luca Bellonda and individual contributors *
3+
* Copyright (C) 2014-2022 by Luca Bellonda and individual contributors *
44
* as indicated in the AUTHORS file *
55
* lbellonda _at_ gmail.com *
66
* *
@@ -30,7 +30,7 @@
3030
#include "modules/anonymize/anonallalg.h"
3131
#include "modules/anonymize/anoncodealg.h"
3232
#include "modules/anonymize/anonseqproducer.h"
33-
#include "modules/anonymize/anonfixedalg.h"
33+
#include "modules/anonymize/anonfixedproducer.h"
3434
#include "modules/anonymize/anoncontext.h"
3535
#include "modules/anonymize/anonadvdialog.h"
3636
#include "modules/xsd/namespacemanager.h"
@@ -139,6 +139,7 @@ void MainWndController::innerAnonymize(AnonContext *context)
139139
}
140140
Regola *regola = _w->getRegola();
141141
regola->anonymize(context, _w->getEditor()->getMainTreeWidget());
142+
context->exposeErrorToUser(_w);
142143
}
143144

144145
void MainWndController::innerAnonymize(AnonAlg *alg)

0 commit comments

Comments
 (0)