From kde-commits Wed Nov 24 13:09:18 2010 From: =?utf-8?q?Jaros=C5=82aw=20Staniek?= Date: Wed, 24 Nov 2010 13:09:18 +0000 To: kde-commits Subject: koffice/kexi Message-Id: <20101124130918.E6482AC8A2 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=129060422313946 SVN commit 1200253 by staniek: Core *set ownership of SchemaData objects to KexiWindow if plain schema data was created (always the case except for Tables and Queries) M +10 -1 core/KexiWindow.cpp M +8 -2 core/KexiWindow.h M +15 -4 core/kexipart.cpp M +12 -2 core/kexipart.h M +6 -3 plugins/queries/kexiquerypart.cpp M +2 -2 plugins/queries/kexiquerypart.h M +5 -4 plugins/tables/kexitablepart.cpp M +1 -1 plugins/tables/kexitablepart.h --- trunk/koffice/kexi/core/KexiWindow.cpp #1200252:1200253 @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2003-2007 Jarosław Staniek + Copyright (C) 2003-2010 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -57,6 +57,7 @@ Private() // : viewModeGroup(0) : schemaData(0) + , schemaDataOwned(false) , isRegistered(false) , dirtyChangedEnabled(true) , switchToViewModeEnabled(true) { @@ -72,6 +73,8 @@ // delete d->stack; // d->stack = 0; // qDeleteAll(sharedViewActions); + if (schemaDataOwned) + delete schemaData; } inline int indexForView(int mode) const { @@ -105,6 +108,7 @@ KexiPart::Item *item; // QString origCaption; //!< helper KexiDB::SchemaData* schemaData; + bool schemaDataOwned; QPointer newlySelectedView; //!< Used in isDirty(), temporary set in switchToViewMode() //!< during view setup, when a new view is not yet raised. //! Used in viewThatRecentlySetDirtyFlag(), modified in dirtyChanged(). @@ -771,6 +775,11 @@ return d->schemaData; } +void KexiWindow::setSchemaDataOwned(bool set) +{ + d->schemaDataOwned = set; +} + KexiWindowData *KexiWindow::data() const { return d->data; --- trunk/koffice/kexi/core/KexiWindow.h #1200252:1200253 @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2003-2007 Jarosław Staniek + Copyright (C) 2003-2010 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -192,7 +192,13 @@ void setSchemaData(KexiDB::SchemaData* schemaData); - /*! Reimpelmented: "*" is added if for 'dirty' dialog's data. */ + //! Sets 'owned' property for schema data. + //! If true, the window will delete the schema data before destruction. + //! By default schema data is not owned. + //! @see setSchemaData(), KexiPart::loadSchemaData(), KexiPart::loadAndSetSchemaData() + void setSchemaDataOwned(bool set); + + /*! Reimplemented: "*" is added if for 'dirty' dialog's data. */ // QString caption() const; /*! Used by KexiView subclasses. \return temporary data shared between --- trunk/koffice/kexi/core/kexipart.cpp #1200252:1200253 @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2003-2007 Jarosław Staniek + Copyright (C) 2003-2010 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -294,7 +294,7 @@ if (!item.neverSaved()) { //we have to load schema data for this dialog - window->setSchemaData(loadSchemaData(window, sdata, viewMode)); + loadAndSetSchemaData(window, sdata, viewMode); if (!window->schemaData()) { //last chance: if (false == d->askForOpeningInTextMode( @@ -303,7 +303,7 @@ return 0; } viewMode = Kexi::TextViewMode; - window->setSchemaData(loadSchemaData(window, sdata, viewMode)); + loadAndSetSchemaData(window, sdata, viewMode); } if (!window->schemaData()) { if (!d->status.error()) @@ -382,15 +382,26 @@ } KexiDB::SchemaData* Part::loadSchemaData(KexiWindow *window, const KexiDB::SchemaData& sdata, - Kexi::ViewMode viewMode) + Kexi::ViewMode viewMode, bool *ownedByWindow) { Q_UNUSED(window); Q_UNUSED(viewMode); KexiDB::SchemaData *new_schema = new KexiDB::SchemaData(); *new_schema = sdata; + if (ownedByWindow) + *ownedByWindow = true; return new_schema; } +void Part::loadAndSetSchemaData(KexiWindow *window, const KexiDB::SchemaData& sdata, + Kexi::ViewMode viewMode) +{ + bool schemaDataOwned = true; + KexiDB::SchemaData* sd = loadSchemaData(window, sdata, viewMode, &schemaDataOwned); + window->setSchemaData(sd); + window->setSchemaDataOwned(schemaDataOwned); +} + bool Part::loadDataBlock(KexiWindow *window, QString &dataString, const QString& dataID) { if (!KexiMainWindowIface::global()->project()->dbConnection()->loadDataBlock( --- trunk/koffice/kexi/core/kexipart.h #1200252:1200253 @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2003-2007 Jarosław Staniek + Copyright (C) 2003-2010 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -287,8 +287,13 @@ virtual void initPartActions(); virtual void initInstanceActions(); + /*! Can be reimplemented if schema data is extended behind the default set of properties. + This is the case for table and query schema objects, + where object of KexiDB::SchemaData subclass is returned. + In this case value pointed by @a ownedByWindow is set to false. + Default implemenatation owned (value pointed by @a ownedByWindow is set to true). */ virtual KexiDB::SchemaData* loadSchemaData(KexiWindow *window, - const KexiDB::SchemaData& sdata, Kexi::ViewMode viewMode); + const KexiDB::SchemaData& sdata, Kexi::ViewMode viewMode, bool *ownedByWindow); bool loadDataBlock(KexiWindow *window, QString &dataString, const QString& dataID = QString()); @@ -343,6 +348,11 @@ // KAction* sharedViewAction(const char* name) const; private: + //! Calls loadSchemaData() (virtual), updates ownership of schema data for @a window + //! and assigns the created data to @a window. + void loadAndSetSchemaData(KexiWindow *window, const KexiDB::SchemaData& sdata, + Kexi::ViewMode viewMode); + class Private; Private * const d; --- trunk/koffice/kexi/plugins/queries/kexiquerypart.cpp #1200252:1200253 @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2004 Lucijan Busch - Copyright (C) 2004,2006 Jarosław Staniek + Copyright (C) 2004-2010 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -161,7 +161,8 @@ } KexiDB::SchemaData* KexiQueryPart::loadSchemaData( - KexiWindow *window, const KexiDB::SchemaData& sdata, Kexi::ViewMode viewMode) + KexiWindow *window, const KexiDB::SchemaData& sdata, Kexi::ViewMode viewMode, + bool *ownedByWindow) { KexiQueryPart::TempData * temp = static_cast(window->data()); QString sqlText; @@ -176,7 +177,7 @@ if (viewMode == Kexi::TextViewMode) { //for SQL view, no parsing is initially needed: //-just make a copy: - return KexiPart::Part::loadSchemaData(window, sdata, viewMode); + return KexiPart::Part::loadSchemaData(window, sdata, viewMode, ownedByWindow); } /* Set this to true on data loading loadSchemaData() to indicate that TextView mode could be used instead of DataView or DesignView, because there are problems @@ -189,6 +190,8 @@ (KexiDB::SchemaData&)*query = sdata; //copy main attributes temp->registerTableSchemaChanges(query); + if (ownedByWindow) + *ownedByWindow = false; query->debug(); return query; --- trunk/koffice/kexi/plugins/queries/kexiquerypart.h #1200252:1200253 @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2004,2006 Jarosław Staniek + Copyright (C) 2004-2010 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -111,7 +111,7 @@ // virtual QList createViewActions(Kexi::ViewMode mode); virtual KexiDB::SchemaData* loadSchemaData(KexiWindow *window, - const KexiDB::SchemaData& sdata, Kexi::ViewMode viewMode); + const KexiDB::SchemaData& sdata, Kexi::ViewMode viewMode, bool *ownedByWindow); }; #endif --- trunk/koffice/kexi/plugins/tables/kexitablepart.cpp #1200252:1200253 @@ -1,7 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2002, 2003 Joseph Wenninger - Copyright (C) 2004 Jarosław Staniek + Copyright (C) 2004-2010 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -155,11 +155,12 @@ return conn->alterTableName(*sch, newName); } -KexiDB::SchemaData* -KexiTablePart::loadSchemaData(KexiWindow *window, const KexiDB::SchemaData& sdata, - Kexi::ViewMode viewMode) +KexiDB::SchemaData* KexiTablePart::loadSchemaData(KexiWindow *window, const KexiDB::SchemaData& sdata, + Kexi::ViewMode viewMode, bool *ownedByWindow) { Q_UNUSED(viewMode); + if (ownedByWindow) + *ownedByWindow = false; return KexiMainWindowIface::global()->project()->dbConnection()->tableSchema(sdata.name()); } --- trunk/koffice/kexi/plugins/tables/kexitablepart.h #1200252:1200253 @@ -77,7 +77,7 @@ virtual void setupCustomPropertyPanelTabs(KTabWidget *tab); virtual KexiDB::SchemaData* loadSchemaData(KexiWindow *window, const KexiDB::SchemaData& sdata, - Kexi::ViewMode viewMode); + Kexi::ViewMode viewMode, bool *ownedByWindow); private: class Private;