1
/* This file is part of the KDE project
2
Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#ifndef KEXIFORMDATAPROVIDER_H
21
#define KEXIFORMDATAPROVIDER_H
23
#include "kexidataviewcommon_export.h"
24
#include "kexiformdataiteminterface.h"
31
//! @short The KexiFormDataProvider class is a data provider for Kexi Forms
32
/*! This provider collects data-aware widgets using setMainWidget().
33
Then, usedDataSources() unique list of required field names is available.
34
On every call of fillDataItems() method, the provider will fill data items
35
with appropriate data from a database cursor.
37
Field names are collected effectively, so eg. having widgets using data sources:
38
("name", "surname", "surname", "name") - "name" and "surname" repeated - will only
39
return ("name", "surname") list, so the cursor's query can be simplified
40
and thus more effective.
42
class KEXIDATAVIEWCOMMON_EXPORT KexiFormDataProvider : public KexiDataItemChangesListener
45
KexiFormDataProvider();
46
virtual ~KexiFormDataProvider();
48
/*! sets \a mainWidget to be a main widget for this data provider.
49
Also find widgets whose will work as data items
50
(all of them must implement KexiFormDataItemInterface), so these could be
51
filled with data on demand. */
52
void setMainDataSourceWidget(QWidget* mainWidget);
54
QStringList usedDataSources() const {
55
return m_usedDataSources;
58
/*! Fills data items with appropriate data fetched from \a data.
59
\a cursorAtNewRecord == true means that we are at new (not yet inserted) database row. */
60
void fillDataItems(KDbRecordData *data, bool cursorAtNewRecord);
62
/*! Implementation for KexiDataItemChangesListener.
63
Reaction for change of \a item. Does nothing here. */
64
virtual void valueChanged(KexiDataItemInterface* item);
66
/*! Implementation for KexiDataItemChangesListener.
67
Implement this to return information whether we're currently at new record or not.
68
This can be used e.g. by data-aware widgets to determine if "(autonumber)"
69
label should be displayed. Returns false here. */
70
virtual bool cursorAtNewRecord() const;
72
/*! Invalidates data sources collected by this provided.
73
\a invalidSources is the set of data sources that should
74
be omitted for fillDataItems().
75
Used by KexiFormView::initDataSource(). */
76
void invalidateDataSources(const QSet<QString>& invalidSources,
77
KDbQuerySchema* query = 0);
79
/*! Fills the same data provided by \a value to every data item (other than \a item)
80
having the same data source as \a item. This method is called immediately when
81
\a value is changed, so duplicated data items are quickly updated. */
82
void fillDuplicatedDataItems(KexiFormDataItemInterface* item, const QVariant& value);
85
QWidget *m_mainWidget;
86
QSet<KDbField*> *m_duplicatedItems;
87
typedef QMap<KexiFormDataItemInterface*, int> KexiFormDataItemInterfaceToIntMap;
88
QList<KexiFormDataItemInterface*> m_dataItems;
89
QStringList m_usedDataSources;
90
KexiFormDataItemInterfaceToIntMap m_fieldNumbersForDataItems;
91
bool m_disableFillDuplicatedDataItems;