Skip to content

Commit 551fe71

Browse files
committed
Propose the current folder saving inner xml.
1 parent cdc0d0d commit 551fe71

18 files changed

+573
-28
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
0.9.18
2+
Propose the same folder of parent when saving an inner XML.
23
New algorithm to anonymize data.
34
Issue #84, added options for metadata installation folders.
45
Issue #86, show license dialog at first startup.

src/mainwindow.cpp

+75-9
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
* *
@@ -1169,7 +1169,13 @@ void MainWindow::on_actionSaveAs_triggered()
11691169
error(tr("Cannot write an empty file."));
11701170
return ;
11711171
}
1172-
QString newFilePath = askFileName(regola->fileName());
1172+
1173+
if(isSlave) {
1174+
on_actionSaveACopyAs_triggered();
1175+
return ;
1176+
}
1177+
1178+
QString newFilePath = askFileNameForSaving(regola->fileName());
11731179
if(newFilePath.isEmpty()) {
11741180
return ;
11751181
}
@@ -1190,10 +1196,17 @@ void MainWindow::actionSaveAs_internal(const QString &newFilePath)
11901196
updateRecentFilesMenu(newFilePath);
11911197
regola->setModified(false);
11921198
data->sessionManager()->enrollFile(newFilePath);
1193-
statusBar()->showMessage(tr("File saved"), SHORT_TIMEOUT);
1199+
statusBar()->showMessage(fileSavedMessage(newFilePath), SHORT_TIMEOUT);
11941200
updateWindowFilePath();
11951201
ui.loadWarningWidget->setVisible(false);
11961202
}
1203+
1204+
QString MainWindow::fileSavedMessage(const QString &newFilePath)
1205+
{
1206+
QString filePathReduced = newFilePath.length() > 20 ? QString("...%1").arg(newFilePath.right(15)) : newFilePath;
1207+
return tr("File saved %1").arg(filePathReduced);
1208+
}
1209+
11971210
void MainWindow::on_actionSaveACopyAs_triggered()
11981211
{
11991212
Regola * regola = getRegola();
@@ -1205,7 +1218,7 @@ void MainWindow::on_actionSaveACopyAs_triggered()
12051218
error(tr("Cannot write an empty file."));
12061219
return ;
12071220
}
1208-
QString newFilePath = askFileName(regola->fileName());
1221+
QString newFilePath = askFileNameForSaving(regola->fileName());
12091222
if(newFilePath.isEmpty()) {
12101223
return ;
12111224
}
@@ -1224,7 +1237,7 @@ void MainWindow::actionSaveACopyAs_internal(const QString &newFilePath)
12241237
}
12251238
updateRecentFilesMenu(newFilePath);
12261239
regola->setModified(modifiedStatus);
1227-
statusBar()->showMessage(tr("File saved"), SHORT_TIMEOUT);
1240+
statusBar()->showMessage(fileSavedMessage(newFilePath), SHORT_TIMEOUT);
12281241
}
12291242

12301243
void MainWindow::on_actionSave_triggered()
@@ -1248,6 +1261,12 @@ void MainWindow::on_actionSave_triggered()
12481261
error(tr("Cannot write empty file."));
12491262
return ;
12501263
}
1264+
execActionSave();
1265+
}
1266+
1267+
void MainWindow::execActionSave()
1268+
{
1269+
Regola * regola = getRegola();
12511270

12521271
// scrivi il nuovo con il nome vecchio+estensione
12531272
QString newFilePath = regola->fileName() + ".new_new~" ;
@@ -1273,7 +1292,7 @@ void MainWindow::on_actionSave_triggered()
12731292
return ;
12741293
}
12751294
regola->setModified(false);
1276-
appData()->notifier()->notify(this, tr("File saved"));
1295+
appData()->notifier()->notify(this, fileSavedMessage(regola->fileName()));
12771296
}
12781297

12791298
bool MainWindow::actionSave_internal(const QString &newFilePath)
@@ -1282,10 +1301,57 @@ bool MainWindow::actionSave_internal(const QString &newFilePath)
12821301
return getEditor()->writeData(newFilePath);
12831302
}
12841303

1285-
QString MainWindow::askFileName(const QString &actualName)
1304+
1305+
MainWindow *MainWindow::getParentMainWindow()
1306+
{
1307+
MainWindow *theParent = dynamic_cast<MainWindow*>(parent());
1308+
return theParent;
1309+
}
1310+
1311+
QString MainWindow::fileNameOrFolder(const QString &filePath)
1312+
{
1313+
if(filePath.isEmpty()) {
1314+
return "";
1315+
}
1316+
QFileInfo info(filePath);
1317+
return info.path();
1318+
}
1319+
1320+
QString MainWindow::thisOrParentFileName()
1321+
{
1322+
QString filePath;
1323+
if(NULL != getRegola()) {
1324+
filePath = getRegola()->fileName();
1325+
}
1326+
if(!filePath.isEmpty()) {
1327+
return fileNameOrFolder(filePath);
1328+
}
1329+
if(isSlave) {
1330+
MainWindow *parentWindow = getParentMainWindow();
1331+
if(NULL != parentWindow) {
1332+
return parentWindow->thisOrParentFileName();
1333+
}
1334+
}
1335+
return "";
1336+
}
1337+
1338+
QString MainWindow::hierarchyFileName(const QString &filePath)
1339+
{
1340+
if(!filePath.isEmpty()) {
1341+
return filePath;
1342+
}
1343+
return thisOrParentFileName();
1344+
}
1345+
1346+
QString MainWindow::fileNameForSaving(const QString &actualName)
1347+
{
1348+
return QXmlEditData::sysFilePathForOperation(hierarchyFileName(actualName));
1349+
}
1350+
1351+
QString MainWindow::askFileNameForSaving(const QString &actualName)
12861352
{
12871353
QString filePath = QFileDialog::getSaveFileName(this, tr("Save Data"),
1288-
QXmlEditData::sysFilePathForOperation(actualName), Utils::getFileFilterForOpenFile());
1354+
fileNameForSaving(actualName), Utils::getFileFilterForOpenFile());
12891355

12901356
if(!filePath.isEmpty()) {
12911357
return filePath;
@@ -3490,7 +3556,7 @@ void MainWindow::on_actionExportElementToFile_triggered()
34903556
error(tr("No data to save."));
34913557
return ;
34923558
}
3493-
QString newFilePath = askFileName(getExportPath());
3559+
QString newFilePath = askFileNameForSaving(getExportPath());
34943560
if(newFilePath.isEmpty()) {
34953561
return ;
34963562
}

src/mainwindow.h

+13-4
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
* *
@@ -203,6 +203,13 @@ class MainWindow : public QMainWindow, UIDelegate, XMLLoadErrorHandler
203203
void beforeLoadingNewData();
204204
void requestOpenGuidedPanel();
205205
void fireAction(QAction *action);
206+
QString parentFileName();
207+
QString hierarchyFileName(const QString &filePath);
208+
MainWindow *getParentMainWindow();
209+
QString fileNameOrFolder(const QString &filePath);
210+
QString thisOrParentFileName();
211+
QString fileSavedMessage(const QString &newFilePath);
212+
virtual void execActionSave();
206213

207214
private slots:
208215
void onRaiseWindow();
@@ -477,7 +484,7 @@ private slots:
477484
bool setupEncoding();
478485
bool buildPluginsMenu(const char *method, QMenu *parent);
479486

480-
QString askFileName(const QString &actualName);
487+
virtual QString askFileNameForSaving(const QString &actualName);
481488
void errorNoRule();
482489

483490
void setFileTitle();
@@ -553,8 +560,8 @@ private slots:
553560
bool createDocumentFromResources(const QString &path);
554561
void createDocumentFromSnippet(Regola* newRegola);
555562
//-------region(internal)
556-
void actionSaveAs_internal(const QString &newFilePath);
557-
void actionSaveACopyAs_internal(const QString &newFilePath);
563+
virtual void actionSaveAs_internal(const QString &newFilePath);
564+
virtual void actionSaveACopyAs_internal(const QString &newFilePath);
558565
bool actionSave_internal(const QString &newFilePath);
559566
//-------endregion(internal)
560567
void updateWindowFilePath();
@@ -572,6 +579,7 @@ private slots:
572579
bool baseEvaluateIfShowEditingTypeDialog(const bool configurationModified, const bool configurationDialogShown, const uint editElementAsFormUsageCount, const uint editElementAsTextUsageCount);
573580

574581
protected:
582+
QString fileNameForSaving(const QString &actualName);
575583
bool openDroppedFile(const QString &filePath);
576584
bool recentFile(const QString &filePath);
577585
bool preferredDir(const QString &filePath);
@@ -594,6 +602,7 @@ private slots:
594602
friend class TestFormattingInfo;
595603
friend class TestConfig;
596604
friend class App;
605+
friend class TestTestMainWindow;
597606
void setLoadErrorHandler(XMLLoadErrorHandler *newHandler);
598607
#endif
599608
};

src/modules/anonymize/algstat/anoncharutils.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ AnonCharSet::~AnonCharSet()
123123

124124
bool AnonCharSet::buildCharSet(const int lowerRange1, const int upperRange1, const int lowerRange2, const int upperRange2)
125125
{
126-
Utils::TEST_ME("");
127126
_lowerRange = lowerRange1;
128127
_upperRange = upperRange1;
129128
_lowerCaseCount = 0;

src/modules/anonymize/anonoperationbatch.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ const AnonOperationResult * AnonOperationBatch::scanAndExecute(QIODevice *input,
164164
{
165165
scan(input, startContext);
166166
if(!input->reset()) {
167-
Utils::TODO_THIS_RELEASE("aaaaaaaaaaaaaaaaaaaaaaaaa");
168167
_result.setError(AnonOperationResult::RES_ERR_READING_INPUTFILE, tr("Unable to reset input file:'%1'").arg(fileInputPath));
169168
} else {
170169
execute(input, output, startContext);

test/TestQXmlEdit.h

+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) 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
* *
@@ -24,6 +24,7 @@
2424
#ifndef TESTQXMLEDIT_H
2525
#define TESTQXMLEDIT_H
2626

27+
#include <xmlEdit.h>
2728
#include <QtCore/QString>
2829
#include <QtTest/QtTest>
2930
#include <QtCore/QCoreApplication>
@@ -108,6 +109,7 @@
108109
#include "testloadsample.h"
109110
#include "testxmlbeans.h"
110111
#include "testabout.h"
112+
#include "testtestmainwindow.h"
111113

112114
class TestQXmlEdit : public QObject
113115
{
@@ -225,6 +227,7 @@ private Q_SLOTS:
225227
void testLoadSample();
226228
void testXMLBeans();
227229
void testAbout();
230+
void testMainWindow();
228231
};
229232

230233

test/app.cpp

+24-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-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
* *
@@ -23,11 +23,13 @@
2323

2424
#include "app.h"
2525
#include "testhelpers/testmainwindow.h"
26+
#include "testhelpers/testmainwindowfile.h"
2627

2728
App::App() : QObject(NULL)
2829
{
2930
_mainWindow = NULL ;
3031
_useTestWindow = false;
32+
_useTestWindowFile = false;
3133
_currentDelegate = NULL ;
3234
}
3335

@@ -48,11 +50,23 @@ bool App::useTestWindow() const
4850
return _useTestWindow;
4951
}
5052

51-
void App::setUseTestWindow(bool value)
53+
bool App::useTestWindowFile() const
5254
{
53-
_useTestWindow = value;
55+
return _useTestWindowFile;
5456
}
5557

58+
59+
void App::setUseTestWindow()
60+
{
61+
_useTestWindow = true;
62+
}
63+
64+
void App::setUseTestWindowFile()
65+
{
66+
_useTestWindowFile = true;
67+
}
68+
69+
5670
bool App::internalInit()
5771
{
5872
Q_INIT_RESOURCE(risorse);
@@ -76,9 +90,13 @@ bool App::init(const bool delegateYes)
7690
{
7791
internalInit();
7892
TestMainWindow *testWindow = NULL ;
93+
TestMainWindowFile *testWindowFile = NULL ;
7994
if(_useTestWindow) {
8095
testWindow = new TestMainWindow(false, false, &appData);
8196
_mainWindow = testWindow ;
97+
} else if(_useTestWindowFile) {
98+
testWindowFile = new TestMainWindowFile(false, false, &appData);
99+
_mainWindow = testWindowFile ;
82100
} else {
83101
_mainWindow = new MainWindow(false, false, &appData);
84102
}
@@ -95,6 +113,9 @@ bool App::init(const bool delegateYes)
95113
if( NULL != testWindow ) {
96114
testWindow->setFakeUIDelegate(_currentDelegate);
97115
}
116+
if( NULL != testWindowFile ) {
117+
testWindowFile->setFakeUIDelegate(_currentDelegate);
118+
}
98119
return true ;
99120
}
100121

test/app.h

+5-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
* *
@@ -41,6 +41,7 @@ class App : public QObject
4141
FakeUIDelegate uiDelegate;
4242
FakeUIDelegateYes uiDelegateYes;
4343
bool _useTestWindow;
44+
bool _useTestWindowFile;
4445
FakeUIDelegate *_currentDelegate;
4546

4647
bool internalInit();
@@ -63,7 +64,9 @@ class App : public QObject
6364
FakeUIDelegate *getUiDelegate();
6465
FakeUIDelegate *getUiDelegateYes();
6566
bool useTestWindow() const;
66-
void setUseTestWindow(bool useTestWindow);
67+
bool useTestWindowFile() const;
68+
void setUseTestWindow();
69+
void setUseTestWindowFile();
6770
};
6871

6972
#endif // APP_H

test/data/mainwindow/file1.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a/>

test/test.pro

+6-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ SOURCES += \
191191
testhelpers/xml2xsdtest.cpp \
192192
testhelpers/xsd2xmltest.cpp \
193193
testabout.cpp \
194-
testhelpers/testanonymize_stat.cpp
194+
testhelpers/testanonymize_stat.cpp \
195+
testtestmainwindow.cpp \
196+
testhelpers/testmainwindowfile.cpp
195197

196198
DEFINES += SRCDIR=\\\"$$PWD/\\\"
197199

@@ -319,7 +321,9 @@ HEADERS += \
319321
testxmlbeans.h \
320322
testhelpers/xml2xsdtest.h \
321323
testhelpers/xsd2xmltest.h \
322-
testabout.h
324+
testabout.h \
325+
testtestmainwindow.h \
326+
testhelpers/testmainwindowfile.h
323327

324328
#OTHER_FILES += \
325329

0 commit comments

Comments
 (0)