~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/widget/dataviewcommon/kexidataprovider.h

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2005 Jarosław Staniek <staniek@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#ifndef KEXIFORMDATAPROVIDER_H
 
21
#define KEXIFORMDATAPROVIDER_H
 
22
 
 
23
#include "kexidataviewcommon_export.h"
 
24
#include "kexiformdataiteminterface.h"
 
25
#include <QSet>
 
26
#include <QList>
 
27
 
 
28
class KDbQuerySchema;
 
29
class KDbRecordData;
 
30
 
 
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.
 
36
 
 
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.
 
41
*/
 
42
class KEXIDATAVIEWCOMMON_EXPORT KexiFormDataProvider : public KexiDataItemChangesListener
 
43
{
 
44
public:
 
45
    KexiFormDataProvider();
 
46
    virtual ~KexiFormDataProvider();
 
47
 
 
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);
 
53
 
 
54
    QStringList usedDataSources() const {
 
55
        return m_usedDataSources;
 
56
    }
 
57
 
 
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);
 
61
 
 
62
    /*! Implementation for KexiDataItemChangesListener.
 
63
     Reaction for change of \a item. Does nothing here. */
 
64
    virtual void valueChanged(KexiDataItemInterface* item);
 
65
 
 
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;
 
71
 
 
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);
 
78
 
 
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);
 
83
 
 
84
protected:
 
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;
 
92
};
 
93
 
 
94
#endif