Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/forms/kexiformpart.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2004 Lucijan Busch <lucijan@kde.org> | 2 | Copyright (C) 2004 Lucijan Busch <lucijan@kde.org> | ||
3 | Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> | 3 | Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> | ||
4 | Copyright (C) 2005 Jarosław Staniek <staniek@kde.org> | 4 | Copyright (C) 2005-2017 Jarosław Staniek <staniek@kde.org> | ||
5 | 5 | | |||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public | ||
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either | ||
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. | ||
10 | 10 | | |||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 115 | #endif | |||
142 | menu->addAction(createSharedAction(Kexi::DesignViewMode, xi18n("To Narrowest"), koIconName("fit-narrowest"), | 142 | menu->addAction(createSharedAction(Kexi::DesignViewMode, xi18n("To Narrowest"), koIconName("fit-narrowest"), | ||
143 | QKeySequence(), "formpart_adjust_width_small")); | 143 | QKeySequence(), "formpart_adjust_width_small")); | ||
144 | menu->addAction(createSharedAction(Kexi::DesignViewMode, xi18n("To Widest"), koIconName("fit-widest"), | 144 | menu->addAction(createSharedAction(Kexi::DesignViewMode, xi18n("To Widest"), koIconName("fit-widest"), | ||
145 | QKeySequence(), "formpart_adjust_width_big")); | 145 | QKeySequence(), "formpart_adjust_width_big")); | ||
146 | } | 146 | } | ||
147 | 147 | | |||
148 | KexiWindowData* KexiFormPart::createWindowData(KexiWindow* window) | 148 | KexiWindowData* KexiFormPart::createWindowData(KexiWindow* window) | ||
149 | { | 149 | { | ||
150 | return new KexiFormPartTempData(window); | 150 | KexiMainWindowIface *win = KexiMainWindowIface::global(); | ||
151 | return new KexiFormPartTempData(window, win->project()->dbConnection()); | ||||
151 | } | 152 | } | ||
152 | 153 | | |||
153 | KexiView* KexiFormPart::createView(QWidget *parent, KexiWindow* window, | 154 | KexiView* KexiFormPart::createView(QWidget *parent, KexiWindow* window, | ||
154 | KexiPart::Item *item, Kexi::ViewMode viewMode, QMap<QString, QVariant>*) | 155 | KexiPart::Item *item, Kexi::ViewMode viewMode, QMap<QString, QVariant>*) | ||
155 | { | 156 | { | ||
156 | Q_ASSERT(item); | 157 | Q_ASSERT(item); | ||
157 | Q_UNUSED(window); | 158 | Q_UNUSED(window); | ||
158 | Q_UNUSED(viewMode); | 159 | Q_UNUSED(viewMode); | ||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Line(s) | 368 | if (!d->widgetTreeWidget) { | |||
373 | lyr->addWidget(d->widgetTree); | 374 | lyr->addWidget(d->widgetTree); | ||
374 | } | 375 | } | ||
375 | tab->addTab(d->widgetTreeWidget, KexiIcon("widgets"), QString()); | 376 | tab->addTab(d->widgetTreeWidget, KexiIcon("widgets"), QString()); | ||
376 | tab->setTabToolTip(tab->indexOf(d->widgetTreeWidget), xi18n("Widgets")); | 377 | tab->setTabToolTip(tab->indexOf(d->widgetTreeWidget), xi18n("Widgets")); | ||
377 | } | 378 | } | ||
378 | 379 | | |||
379 | //---------------- | 380 | //---------------- | ||
380 | 381 | | |||
381 | KexiFormPartTempData::KexiFormPartTempData(KexiWindow* parent) | 382 | class Q_DECL_HIDDEN KexiFormPartTempData::Private | ||
382 | : KexiWindowData(parent) | 383 | { | ||
384 | public: | ||||
385 | Private(KexiFormPartTempData *temp) | ||||
386 | : q(temp) | ||||
383 | { | 387 | { | ||
384 | } | 388 | } | ||
385 | 389 | | |||
390 | void unregisterForChanges() | ||||
391 | { | ||||
392 | if (dataSource.isEmpty()) { | ||||
393 | return; | ||||
394 | } | ||||
395 | if (pluginId == "org.kexi-project.table") { | ||||
396 | KDbTableSchema *table = conn->tableSchema(dataSource); | ||||
397 | if (!table) { | ||||
398 | return; | ||||
399 | } | ||||
400 | KDbTableSchemaChangeListener::unregisterForChanges(conn, table); | ||||
401 | } else if (pluginId == "org.kexi-project.query") { | ||||
402 | KDbQuerySchema *query = conn->querySchema(dataSource); | ||||
403 | if (!query) { | ||||
404 | return; | ||||
405 | } | ||||
406 | KDbTableSchemaChangeListener::unregisterForChanges(conn, query); | ||||
407 | } else { | ||||
408 | return; | ||||
409 | } | ||||
410 | } | ||||
411 | | ||||
412 | void registerForChanges(const QString &newPluginId, const QString &newDataSource) | ||||
413 | { | ||||
414 | if (newPluginId == "org.kexi-project.table") { | ||||
415 | KDbTableSchema *table = conn->tableSchema(newDataSource); | ||||
416 | if (!table) { | ||||
417 | return; | ||||
418 | } | ||||
419 | KDbTableSchemaChangeListener::registerForChanges(conn, q, table); | ||||
420 | } else if (pluginId == "org.kexi-project.query") { | ||||
421 | KDbQuerySchema *query = conn->querySchema(newDataSource); | ||||
422 | if (!query) { | ||||
423 | return; | ||||
424 | } | ||||
425 | KDbTableSchemaChangeListener::registerForChanges(conn, q, query); | ||||
426 | } else { | ||||
427 | return; | ||||
428 | } | ||||
429 | pluginId = newPluginId; | ||||
430 | dataSource = newDataSource; | ||||
431 | } | ||||
432 | | ||||
433 | KDbConnection *conn; | ||||
434 | QString pluginId; | ||||
435 | QString dataSource; | ||||
436 | | ||||
437 | private: | ||||
438 | KexiFormPartTempData * const q; | ||||
439 | }; | ||||
440 | | ||||
441 | KexiFormPartTempData::KexiFormPartTempData(KexiWindow* parent, KDbConnection *conn) | ||||
442 | : KexiWindowData(parent), d(new Private(this)) | ||||
443 | { | ||||
444 | d->conn = conn; | ||||
445 | setName(KexiUtils::localizedStringToHtmlSubstring( | ||||
446 | kxi18nc("@info", "Form <resource>%1</resource>").subs(parent->partItem()->name()))); | ||||
447 | } | ||||
448 | | ||||
386 | KexiFormPartTempData::~KexiFormPartTempData() | 449 | KexiFormPartTempData::~KexiFormPartTempData() | ||
387 | { | 450 | { | ||
451 | KDbTableSchemaChangeListener::unregisterForChanges(d->conn, this); | ||||
452 | delete d; | ||||
388 | } | 453 | } | ||
389 | 454 | | |||
455 | void KexiFormPartTempData::setDataSource(const QString &pluginId, const QString &dataSource) | ||||
456 | { | ||||
457 | if (d->pluginId != pluginId || d->dataSource != dataSource) { | ||||
458 | d->unregisterForChanges(); | ||||
459 | d->registerForChanges(pluginId, dataSource); | ||||
460 | } | ||||
461 | } | ||||
462 | | ||||
463 | tristate KexiFormPartTempData::closeListener() | ||||
464 | { | ||||
465 | KexiWindow* window = static_cast<KexiWindow*>(parent()); | ||||
466 | qDebug() << window->partItem()->name(); | ||||
467 | return KexiMainWindowIface::global()->closeWindow(window); | ||||
468 | } |