Skip to content

Commit 7c99d97

Browse files
committed
b-173 Branches, fixed possible leaks, demoted class, added desctructors,
fixed test condiction in prefixes operations.
1 parent d2492f8 commit 7c99d97

17 files changed

+66
-35
lines changed

BRANCHES

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ devel
44

55
Branches:
66
---------
7+
172 - Fixes after code review.
78
171 - Function key help.
89

910
Merged branches:

src/aboutdialog.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ AboutDialog::AboutDialog(QWidget *parent,
7979
item->setText(0, QString("%1 %2").arg(author->name).arg(contactInfo(author->contactInfo)));
8080
contributors->addChild(item);
8181
} else {
82+
delete item ;
8283
//TODO printf( "%s", QString("ROLE NOT FOUND %1").arg(author->name).toAscii().data() );
8384
}
8485
}

src/applicationdata.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,14 @@ ApplicationData::~ApplicationData()
9090
}
9191
if(NULL != _uiServices) {
9292
delete _uiServices;
93+
_uiServices = NULL;
9394
}
9495
if(NULL != _sessionDataInterface) {
9596
_sessionDataInterface->closeAndDispose();
97+
_sessionDataInterface = NULL ;
9698
}
99+
disconnect(&_sessionManager, SIGNAL(sessionActivated(const int)), this, SLOT(onSessionActivated(const int)));
100+
disconnect(&_sessionManager, SIGNAL(clearSession()), this, SLOT(onClearSession()));
97101
}
98102

99103

src/config/configuresessionswidget.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void ConfigureSessionsWidget::on_deleteAllData_clicked()
7474
SessionDataInterface * dataAccess = _data->sessionManager()->dataAccess();
7575
if(NULL == dataAccess) {
7676
Utils::error(this, tr("Error connecting with storage."));
77+
return ;
7778
}
7879
SessionOperationStatus context;
7980
setEnabled(false);
@@ -95,6 +96,7 @@ void ConfigureSessionsWidget::on_deleteData_clicked()
9596
SessionDataInterface *dataAccess = _data->sessionManager()->dataAccess();
9697
if(NULL == dataAccess) {
9798
Utils::error(this, tr("Error connecting with storage."));
99+
return;
98100
}
99101
bool isValidChoice = true ;
100102
SessionDataInterface::EDateInterval dateInterval;

src/filter/attributefilterdataaccess.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
//----------------------------------------------------------------
2727

2828

29-
AttributeFilterDataAccess::AttributeFilterDataAccess(SessionDataInterface *newDataAccess, QObject *parent) :
30-
QObject(parent)
29+
AttributeFilterDataAccess::AttributeFilterDataAccess(SessionDataInterface *newDataAccess)
3130
{
3231
_dataAccess = newDataAccess ;
3332
}

src/filter/attributefilterdataaccess.h

+2-11
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,16 @@
2424
#ifndef ATTRIBUTEFILTERDATAACCESS_H
2525
#define ATTRIBUTEFILTERDATAACCESS_H
2626

27-
#include <QObject>
28-
29-
3027
#include "sessions/data_access/model/attrfilterprofile.h"
3128
#include "sessions/data_access/model/attrfilterdetail.h"
3229
#include "sessions/data_access/dataresult.h"
3330
#include <sessiondata>
3431

35-
class AttributeFilterDataAccess : public QObject
32+
class AttributeFilterDataAccess
3633
{
37-
Q_OBJECT
38-
3934
SessionDataInterface *_dataAccess;
4035
public:
41-
explicit AttributeFilterDataAccess(SessionDataInterface *newDataAccess = NULL, QObject *parent = 0);
36+
explicit AttributeFilterDataAccess(SessionDataInterface *newDataAccess = NULL);
4237
virtual ~AttributeFilterDataAccess();
4338

4439
void setDataAccess(SessionDataInterface *newDataAccess);
@@ -48,10 +43,6 @@ class AttributeFilterDataAccess : public QObject
4843
virtual void storageDeleteProfile(DataResult &result, const int idProfile);
4944
virtual AttrFilterDetail *storageReadProfileDetails(DataResult &result, const int idProfile);
5045

51-
signals:
52-
53-
public slots:
54-
5546
};
5647

5748
#endif // ATTRIBUTEFILTERDATAACCESS_H

src/filter/attributefiltermanagement.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "utils.h"
2626
#include "fakeattributefilterdataaccess.h"
2727

28-
FakeAttributeFilterDataAccess fakeAccess;
29-
3028
AttributeFilterManagement::AttributeFilterManagement(QObject *parent) :
3129
QObject(parent)
3230
{

src/mainwindow.cpp

+30-8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const QString MainWindow::ActionTagLastFolders("LastFolders");
9595
MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWindow *parent)
9696
: QMainWindow(parent),
9797
_uiServices(this),
98+
data(newData),
9899
uiDelegate(this),
99100
_windowIcon(":/icon/images/icon.png"),
100101
_closing(false)
@@ -123,7 +124,6 @@ MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWin
123124
isSlave = setIsSlave ;
124125
eventLoop = NULL ;
125126
_extractResult = NULL ;
126-
data = newData ;
127127
ui.setupUi(this);
128128
ui.loadWarningWidget->setVisible(false);
129129
ui.actionAbout->setMenuRole(QAction::AboutRole);
@@ -152,6 +152,7 @@ MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWin
152152
if(Config::getBool(Config::KEY_TEST_SHOW_XSD_EDITOR, false)) {
153153
//void xsdTest(); TODO
154154
//xsdTest();
155+
Utils::TODO_THIS_RELEASE("rimuovi se non serve");
155156
}
156157
setWindowIcon(_windowIcon);
157158
started = true ;
@@ -165,22 +166,30 @@ MainWindow::MainWindow(const bool setIsSlave, ApplicationData *newData, QMainWin
165166

166167
MainWindow::~MainWindow()
167168
{
168-
if(NULL != data) {
169-
disconnect(data, SIGNAL(clipboardDataChanged(bool)), this, SLOT(onClipboardDataChanged(bool)));
170-
disconnect(data, SIGNAL(stateKeyboardShortcutChanged(bool)), this, SLOT(onStateKeyboardShortcutChanged(bool)));
171-
}
169+
ui.sessionTree->setSessionManager(NULL);
172170
dismissInfoOnKeyboard();
173171
dismissInfoEditTypes();
174-
if(!isSlave) {
175-
data->removeWindow(this);
176-
}
177172
cleanExtractResults(); //TODO
178173
removeAttributesFilter();
179174
if(NULL != _snippetManager) {
180175
delete _snippetManager;
181176
}
177+
forgetData();
182178
}
183179

180+
void MainWindow::forgetData()
181+
{
182+
if(NULL != data) {
183+
disconnect(data, SIGNAL(clipboardDataChanged(bool)), this, SLOT(onClipboardDataChanged(bool)));
184+
disconnect(data, SIGNAL(stateKeyboardShortcutChanged(bool)), this, SLOT(onStateKeyboardShortcutChanged(bool)));
185+
if(!isSlave) {
186+
data->removeWindow(this);
187+
}
188+
data = NULL ;
189+
}
190+
}
191+
192+
184193
ApplicationData *MainWindow::appData()
185194
{
186195
return data;
@@ -248,11 +257,21 @@ bool MainWindow::event(QEvent *e)
248257
const bool result = QMainWindow::event(e);
249258
switch(e->type()) {
250259
case QEvent::WindowActivate:
260+
#ifdef QXMLEDIT_TEST
261+
if(NULL == data) {
262+
Utils::TODO_THIS_RELEASE("fault");
263+
}
264+
#endif
251265
if(NULL != data) {
252266
data->newWindowActivationStatus(this, true);
253267
}
254268
break;
255269
case QEvent::WindowDeactivate:
270+
#ifdef QXMLEDIT_TEST
271+
if(NULL == data) {
272+
Utils::TODO_THIS_RELEASE("fault");
273+
}
274+
#endif
256275
if(NULL != data) {
257276
data->newWindowActivationStatus(this, false);
258277
}
@@ -1381,8 +1400,11 @@ void MainWindow::closeEvent(QCloseEvent * event)
13811400
event->accept();
13821401
_closing = true;
13831402
if(!isSlave) {
1403+
// disable events until destroyed
1404+
forgetData();
13841405
deleteLater();
13851406
} else {
1407+
Utils::TODO_THIS_RELEASE("ma perche'? non forget data se closed? o deleted?");
13861408
_slaveIsClosed = true ;
13871409
if(NULL != eventLoop) {
13881410
eventLoop->exit(_returnCodeAsSlave);

src/mainwindow.h

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class MainWindow : public QMainWindow, UIDelegate, XMLLoadErrorHandler
170170
void fireActionByName(const QString &name);
171171

172172
protected:
173+
void forgetData();
173174
virtual void changeEvent(QEvent *event);
174175
virtual bool event(QEvent *e);
175176
void dismissInfoOnKeyboard();
@@ -581,6 +582,7 @@ private slots:
581582
friend class TestLoadFile;
582583
friend class TestFormattingInfo;
583584
friend class TestConfig;
585+
friend class App;
584586
void setLoadErrorHandler(XMLLoadErrorHandler *newHandler);
585587
#endif
586588
};

src/modules/namespace/regolaprefixes.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ bool Regola::removePrefix(const QString &removedPrefix, QList<Element*> elements
235235
{
236236
bool ok = true;
237237
foreach(Element * element, elements) {
238-
if((NULL != element) || element->isElement()) {
238+
if((NULL != element) && element->isElement()) {
239239
if(!element->removePrefix(removedPrefix, targetSelection,
240240
isAllPrefixes, observer)) {
241241
ok = false;
@@ -252,7 +252,7 @@ bool Regola::setPrefix(const QString &newPrefix, QList<Element*> elements, Targe
252252
{
253253
bool ok = true;
254254
foreach(Element * element, elements) {
255-
if((NULL != element) || element->isElement()) {
255+
if((NULL != element) && element->isElement()) {
256256
if(!element->setPrefix(newPrefix, targetSelection, observer)) {
257257
ok = false;
258258
}
@@ -287,7 +287,7 @@ bool Regola::removeNamespace(const QString &removedNS, QList<Element *>elements,
287287
{
288288
bool ok = true;
289289
foreach(Element * element, elements) {
290-
if((NULL != element) || element->isElement()) {
290+
if((NULL != element) && element->isElement()) {
291291
QList<NSContext*> contexts;
292292
NSContext *lastContext = buildContextInfo(contexts, element);
293293
if(!element->removeNamespace(removedNS, targetSelection,
@@ -304,7 +304,7 @@ bool Regola::setNamespace(const QString &ns, const QString &prefix, QList<Elemen
304304
{
305305
bool ok = true;
306306
foreach(Element * element, elements) {
307-
if((NULL != element) || element->isElement()) {
307+
if((NULL != element) && element->isElement()) {
308308

309309
QList<NSContext*> contexts;
310310
NSContext *lastContext = buildContextInfo(contexts, element);
@@ -322,7 +322,7 @@ bool Regola::replaceNamespace(const QString &replacedNS, const QString &newNS, c
322322
{
323323
bool ok = true;
324324
foreach(Element * element, elements) {
325-
if((NULL != element) || element->isElement()) {
325+
if((NULL != element) && element->isElement()) {
326326

327327
QList<NSContext*> contexts;
328328
NSContext *lastContext = buildContextInfo(contexts, element);
@@ -360,7 +360,7 @@ bool Regola::replacePrefix(const QString &oldPrefix, const QString &newPrefix, Q
360360
{
361361
bool ok = true;
362362
foreach(Element * element, elements) {
363-
if((NULL != element) || element->isElement()) {
363+
if((NULL != element) && element->isElement()) {
364364
if(!element->replacePrefix(oldPrefix, newPrefix, targetSelection, isAllPrefixes, observer)) {
365365
ok = false;
366366
}
@@ -392,7 +392,7 @@ bool Regola::namespaceNormalize(const QString &thePrefix, const QString &theNS,
392392
{
393393
bool ok = true;
394394
foreach(Element * element, elements) {
395-
if((NULL != element) || element->isElement()) {
395+
if((NULL != element) && element->isElement()) {
396396
QList<NSContext*> contexts;
397397
NSContext *context = buildContextInfo(contexts, element);
398398
bool isDeclared = false ;

src/sessions/SessionDataInterface.h

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class SessionDataFactory
8181
{
8282
public:
8383
virtual SessionDataInterface *sessionDataInterface(const QString &configuration) = 0;
84+
virtual ~SessionDataFactory();
8485
};
8586

8687
#endif // SESSIONDATAINTERFACE_H

src/sessions/data_access/sqllitedataaccess.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@
140140
#define FILE_FIELDS "f.id, f.path, f.description, f.creationdate, f.starred"
141141
#define OFFSET_ACCESS_FILEACCESS (5)
142142

143+
//--------------------------
144+
145+
SessionDataFactory::~SessionDataFactory()
146+
{
147+
}
148+
149+
//--------------------------
150+
143151
SessionDataInterface::~SessionDataInterface()
144152
{
145153
}

src/sessions/sessiondrawerwidgetprivate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void SessionDrawerWidgetPrivate::init()
6060
void SessionDrawerWidgetPrivate::disconnectSessionManager()
6161
{
6262
if(NULL != _sessionManager) {
63+
disconnect(_sessionManager, SIGNAL(sessionStateChanged(Session::SessionState)), this, SLOT(onSessionStateChanged(Session::SessionState)));
6364
disconnect(_sessionManager, SIGNAL(dataChanged()), this, SLOT(onSessionDataChanged()));
6465
disconnect(_sessionManager, SIGNAL(enablingChanged()), this, SLOT(onEnablingChanged()));
6566
}

src/style.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,11 @@ void VStyle::updateFontMetrics()
801801

802802
bool VStyle::addId(const QString &newId, const bool isAlpha)
803803
{
804+
if(_elementIds.value(newId, NULL) != NULL) {
805+
return false;
806+
}
804807
IdEntry * entry = new IdEntry(newId, isAlpha) ;
805808
if(NULL != entry) {
806-
if(_elementIds.value(newId, NULL) != NULL) {
807-
return false;
808-
}
809809
_elementIds.insert(newId, entry) ;
810810
return true;
811811
}

test/app.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class App : public QObject
4949
QString sessionDBPath;
5050

5151
App();
52-
~App();
52+
virtual ~App();
5353

5454
bool init(const bool delegateYes=false);
5555
bool initNoWindow();

test/testxsddiff.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ bool TestXSDDiff::verifyAttributesUnordered( const QString &testName, XSDSchema
262262

263263
bool TestXSDDiff::doTest( const ETTType type, const QString &testName, const QString &fileNameIn, const QString &fileNameOut, QList<int> &expected, const bool areDifferent )
264264
{
265+
App app;
265266
if(!app.init() ) {
266267
return error(testName, "init app failed");
267268
}
@@ -317,6 +318,7 @@ bool TestXSDDiff::doTest( const ETTType type, const QString &testName, const QSt
317318

318319
bool TestXSDDiff::doCompare( const QString &testName, const QString &fileNameIn, const QString &fileNameOut, const int expAdd, const int expMod, const int expDel, const int expUn)
319320
{
321+
App app;
320322
if(!app.init() ) {
321323
return error(testName, "init app failed");
322324
}

test/testxsddiff.h

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class TestXSDDiff
3434
ATTRIBUTES
3535
};
3636

37-
App app;
3837
QMap<QString, QVariant> _configBackend;
3938

4039
bool one;

0 commit comments

Comments
 (0)