diff --git a/src/plugins/tables/kexitabledesigner_dataview.cpp b/src/plugins/tables/kexitabledesigner_dataview.cpp index b53cd8c75..b95ffbbfe 100644 --- a/src/plugins/tables/kexitabledesigner_dataview.cpp +++ b/src/plugins/tables/kexitabledesigner_dataview.cpp @@ -1,90 +1,92 @@ /* This file is part of the KDE project Copyright (C) 2004-2014 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kexitabledesigner_dataview.h" #include #include #include #include #include #include KexiTableDesigner_DataView::KexiTableDesigner_DataView(QWidget *parent) : KexiDataTableView(parent, true/*db-aware*/) { setObjectName("KexiTableDesigner_DataView"); // setup main menu actions QList mainMenuActions; mainMenuActions << sharedAction("project_export_data_table") << sharedAction("edit_clear_table"); setMainMenuActions(mainMenuActions); } KexiTableDesigner_DataView::~KexiTableDesigner_DataView() { //! @todo KEXI3 crash /*TODO if (dynamic_cast(tableView()) && dynamic_cast(tableView())->cursor()) { KexiMainWindowIface::global()->project()->dbConnection()->deleteCursor( dynamic_cast(tableView())->cursor() ); }*/ } tristate KexiTableDesigner_DataView::beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore) { Q_UNUSED(dontStore); if (mode != Kexi::DataViewMode) { //accept editing before switching if (!acceptRecordEditing()) { return cancelled; } } return true; } tristate KexiTableDesigner_DataView::afterSwitchFrom(Kexi::ViewMode mode) { Q_UNUSED(mode); if (tempData()->tableSchemaChangedInPreviousView) { KexiUtils::WaitCursor wait; KDbConnection *conn = KexiMainWindowIface::global()->project()->dbConnection(); KDbCursor *c = conn->prepareQuery(tempData()->table()); if (!c) { return false; } - setData(c); + if (!setData(c)) { + return false; + } tempData()->tableSchemaChangedInPreviousView = false; } return true; } KexiTablePartTempData* KexiTableDesigner_DataView::tempData() const { return static_cast(window()->data()); } diff --git a/src/widget/tableview/KexiDataTableView.cpp b/src/widget/tableview/KexiDataTableView.cpp index 27f805b33..66cf9b63c 100644 --- a/src/widget/tableview/KexiDataTableView.cpp +++ b/src/widget/tableview/KexiDataTableView.cpp @@ -1,159 +1,159 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2003 Joseph Wenninger Copyright (C) 2003-2014 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KexiDataTableView.h" #include "KexiDataTableScrollArea.h" #include #include #include #include #include #include #include #include #include #include #include class Q_DECL_HIDDEN KexiDataTableView::Private { public: bool storeUserDataBlock(int objectID, const QString& dataID, const QString &dataString, KDbTransactionGuard *tg) { if (transaction.isNull()) { transaction = KexiMainWindowIface::global()->project()->dbConnection()->beginTransaction(); tg->setTransaction(transaction); } return KexiMainWindowIface::global()->project()->storeUserDataBlock( objectID, dataID, dataString); } KDbTransaction transaction; }; KexiDataTableView::KexiDataTableView(QWidget *parent, bool dbAware) : KexiDataAwareView(parent) , d(new Private) { KexiTableScrollArea *view; if (dbAware) view = new KexiDataTableScrollArea(this); else view = new KexiTableScrollArea(0, this); view->setObjectName("datatableview"); KexiDataAwareView::init(view, view, view); } KexiDataTableView::KexiDataTableView(QWidget *parent, KDbCursor *cursor) : KexiDataAwareView(parent) , d(new Private) { KexiTableScrollArea *view = new KexiDataTableScrollArea(this, cursor); KexiDataAwareView::init(view, view, view); } KexiDataTableView::~KexiDataTableView() { delete d; } bool KexiDataTableView::loadTableViewSettings(KDbTableViewData* data) { Q_ASSERT(data); const int id = window()->id(); if (id > 0 && data->columnCount() > 0) { QString columnWidthsString; tristate res = KexiMainWindowIface::global()->project()->loadUserDataBlock( id, "columnWidths", &columnWidthsString); if (false == res) { return false; } else if (true == res) { bool ok; const QList columnWidths = KDb::deserializeIntList(columnWidthsString, &ok); if (!ok) { qWarning() << "Invalid format of 'columnWidths' value:" << columnWidthsString; return false; } QList* columns = data->columns(); if (columnWidths.count() == columns->count()) { int i = 0; foreach (int width, columnWidths) { // qDebug() << width; columns->at(i)->setWidth(width); ++i; } } } } return true; } -void +bool KexiDataTableView::setData(KDbCursor *c) { KexiDataTableScrollArea* area = dynamic_cast(mainWidget()); if (!area) - return; - area->setData(c); + return false; + return area->setData(c); } void KexiDataTableView::filter() { } KexiTableScrollArea* KexiDataTableView::tableView() const { return dynamic_cast(internalView()); } bool KexiDataTableView::saveSettings() { //! @todo KEXI3 save only if changed bool ok = true; KDbTransactionGuard tg; if (dynamic_cast(mainWidget())) { // db-aware KexiTableScrollArea* tv = tableView(); const int id = window()->id(); if (id > 0 && tv->data() && tv->data()->columnCount() > 0) { QStringList widths; bool equal = true; // will be only saved if widths are not equal for (int i = 0; i < tv->data()->columnCount(); ++i) { if (equal) { equal = tv->data()->column(i)->width() == tv->columnWidth(i); } widths.append(QString::number(tv->columnWidth(i))); } if ( !equal && !d->storeUserDataBlock(id, "columnWidths", KDb::variantToString(widths), &tg)) { return false; } } ok = tg.commit(); } return ok; } diff --git a/src/widget/tableview/KexiDataTableView.h b/src/widget/tableview/KexiDataTableView.h index 89d4cd764..a8af99bff 100644 --- a/src/widget/tableview/KexiDataTableView.h +++ b/src/widget/tableview/KexiDataTableView.h @@ -1,83 +1,83 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch Copyright (C) 2003 Joseph Wenninger Copyright (C) 2003-2014 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 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KEXIDATATABLE_H #define KEXIDATATABLE_H #include "kexidatatable_export.h" #include class KDbCursor; class KDbTableViewData; class KexiTableScrollArea; /*! @short Provides a data-driven (record-based) tabular view. The KexiDataTableView can display data provided "by hand" or from KDb-compatible database source. @see KexiFormView */ class KEXIDATATABLE_EXPORT KexiDataTableView : public KexiDataAwareView { Q_OBJECT public: /*! CTOR1: Creates, empty table view that can be initialized later with setData(). If \a dbAware is true, table will be db-aware, and KexiDataTableView is used internally. Otherwise, table will be not-db-aware, and KexiTableView is used internally. In the latter case, data can be set by calling tableView()->setData(KDbTableViewData* data). */ explicit KexiDataTableView(QWidget *parent, bool dbAware = true); /*! CTOR2: Creates db-aware, table view initialized with \a cursor. KexiDataTableView is used internally. */ KexiDataTableView(QWidget *parent, KDbCursor *cursor); virtual ~KexiDataTableView(); KexiTableScrollArea* tableView() const; //! Loads settings for table into @a data model. //! Used after loading data model in KexiDataTableView::setData(KDbCursor*), before calling KexiTableView::setData(). //! @return true on success bool loadTableViewSettings(KDbTableViewData* data); public Q_SLOTS: /*! Sets data. Only works for db-aware table. */ - void setData(KDbCursor *cursor); + bool setData(KDbCursor *cursor); /*! Saves settings for the view. Implemented for KexiView. */ virtual bool saveSettings() override; protected Q_SLOTS: //! @todo void filter(); protected: void init(); class Private; Private * const d; }; #endif