File: virtualCluster.h

package info (click to toggle)
postbooks 4.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 112,660 kB
  • ctags: 22,890
  • sloc: cpp: 310,358; sh: 607; xml: 214; python: 140; awk: 104; makefile: 50
file content (397 lines) | stat: -rw-r--r-- 13,925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
 * This file is part of the xTuple ERP: PostBooks Edition, a free and
 * open source Enterprise Resource Planning software suite,
 * Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 * It is licensed to you under the Common Public Attribution License
 * version 1.0, the full text of which (including xTuple-specific Exhibits)
 * is available at www.xtuple.com/CPAL.  By using this software, you agree
 * to be bound by its terms.
 */

#ifndef virtCluster_h
#define virtCluster_h

#include "widgets.h"
#include "guiclientinterface.h"
#include "parameter.h"
#include "xlineedit.h"
#include "xtextedit.h"
#include "xtreewidget.h"
#include "xcheckbox.h"
#include "xdatawidgetmapper.h"

#include <QSqlQueryModel>
#include <QAction>
#include <QDialogButtonBox>
#include <QCheckBox>
#include <QCompleter>
#include <QDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QSqlQueryModel>
#include <QVBoxLayout>
#include <QWidget>

class QGridLayout;
class VirtualClusterLineEdit;

#define ID              1
#define NUMBER          2
#define DESCRIPTION     3
#define ACTIVE          4

class XTUPLEWIDGETS_EXPORT VirtualList : public QDialog
{
    Q_OBJECT

    friend class VirtualClusterLineEdit;

    public:
        VirtualList();
        VirtualList(QWidget*, Qt::WindowFlags = 0);

    public slots:
        virtual void sClose();
        virtual void sFillList();
        virtual void sSearch(const QString&);
        virtual void sSelect();

    protected:
        virtual void init();
        void showEvent(QShowEvent *);

        VirtualClusterLineEdit* _parent;
        QVBoxLayout* _dialogLyt;
        QLabel*      _searchLit;
        QLineEdit*   _search;
        QLabel*      _titleLit;
        QDialogButtonBox*  _buttonBox;
        QPushButton* _select;
        XTreeWidget* _listTab;
        int          _id;
};

class XTUPLEWIDGETS_EXPORT VirtualSearch : public QDialog
{
    Q_OBJECT

    friend class VirtualClusterLineEdit;

    public:
        VirtualSearch(QWidget*, Qt::WindowFlags = 0);

        Q_INVOKABLE virtual void setQuery(QSqlQuery query);
        Q_INVOKABLE virtual void setSearchText(const QString& text);

    public slots:
        virtual void sClose();
        virtual void sFillList();
        virtual void sSelect();

    protected:
        VirtualClusterLineEdit* _parent;
        QVBoxLayout* _dialogLyt;
        int  _id;
        QLabel*      _searchLit;
        QLineEdit*   _search;
        XCheckBox*   _searchNumber;
        XCheckBox*   _searchName;
        XCheckBox*   _searchDescrip;
        QLabel*      _titleLit;
        QDialogButtonBox*  _buttonBox;
        QPushButton* _select;
        XTreeWidget* _listTab;
        QLayout*     dialogLyt;
        QLayout*     searchLyt;
        QLayout*     searchStrLyt;
        QGridLayout* selectorsLyt;
        QLayout*     tableLyt;
        QLayout*     buttonsLyt;
};

class XTUPLEWIDGETS_EXPORT VirtualInfo : public QDialog
{
    Q_OBJECT

    friend class VirtualClusterLineEdit;

    public:
        VirtualInfo(QWidget*,  Qt::WindowFlags = 0);

    public slots:
        virtual void sPopulate();

    protected:
        VirtualClusterLineEdit* _parent;
        QLabel*         _titleLit;
        QLabel*         _numberLit;
        QLabel*         _number;
        QLabel*         _nameLit;
        QLabel*         _name;
        QLabel*         _descripLit;
        QLabel*         _descrip;
        QPushButton*    _close;

    private:
        int _id;
};

/*
    VirtualClusterLineEdit is an abstract class that encapsulates
    the basics of retrieving an ID given a NUMBER or a NUMBER given
    an ID.  This class and its subclasses are intended to be used
    by VirtualCluster objects, not directly by an application.

    Users of this class need to supply the names of the table, its
    id column, and its number column (numbers are user-readable
    strings such as customer abbreviations or purchase order numbers).

    Subclasses must supply implementations for the sInfo(), sList(),
    and sSearch() slots.  sInfo() is a distinct dialog that shows
    extended data from the record with table_id = id(). sList() and
    sSearch() are dialogs that let the user select a number/id pair
    value for the widget.
*/

class XTUPLEWIDGETS_EXPORT VirtualClusterLineEdit : public XLineEdit
{
    Q_OBJECT
    
    friend class VirtualCluster;
    friend class VirtualInfo;
    friend class VirtualList;
    friend class VirtualSearch;

    public:
        VirtualClusterLineEdit(QWidget*, const char*, const char*, const char*,
                               const char*, const char*, const char*,
                               const char* = 0, const char* = 0);

       void setMenu(QMenu *menu);
       QMenu *menu() const { return _menu; }

       static GuiClientInterface *_guiClientInterface;

       Q_INVOKABLE        virtual bool canOpen();
       Q_INVOKABLE inline virtual QString uiName()         const { return _uiName; }
       Q_INVOKABLE inline virtual QString editPriv()       const { return _editPriv; }
       Q_INVOKABLE inline virtual QString viewPriv()       const { return _viewPriv; }

       Q_INVOKABLE inline virtual QSqlQueryModel* model() const { return _model;}

       Q_INVOKABLE inline virtual QString name()        const { return _name; }
       Q_INVOKABLE inline virtual QString description() const { return _description; }

    public slots:
        virtual void clear();
        virtual QString extraClause() const { return _extraClause; }
        virtual void sEllipses();
        virtual void sInfo();
        virtual void sList();
        virtual void sOpen();
        virtual void sCopy();
        virtual void sNew();
        virtual void sSearch();
        virtual void setId(const int);
        virtual void setId(const int, const QString&);
        virtual void setNumber(const QString&);
        virtual void setShowInactive(const bool);

        virtual void setUiName(const QString& name);
        virtual void setEditPriv(const QString& priv);
        virtual void setNewPriv(const QString& priv);
        virtual void setViewPriv(const QString& priv);

    protected slots:
        inline virtual void clearExtraClause() { _extraClause = ""; }

        virtual VirtualList*    listFactory();
        virtual VirtualSearch*  searchFactory();
        virtual VirtualInfo*    infoFactory();

        virtual void setStrikeOut(bool enable = false);
        virtual void sHandleCompleter();
        virtual void sHandleNullStr();
        virtual void sParse();
        virtual void sUpdateMenu();
        virtual QWidget* sOpenWindow(const QString& uiName, ParameterList &params);

        virtual void setTitles(const QString&, const QString& = 0);
        inline virtual void setExtraClause(const QString& pExt) { _extraClause = pExt; }
        virtual void setTableAndColumnNames(const char* pTabName,
                                            const char* pIdColumn,
                                            const char* pNumberColumn,
                                            const char* pNameColumn,
                                            const char* pDescripColumn,
                                            const char* pActiveColumn,
                                            const char* = 0,
                                            const char* = 0);

        void setStrict(bool);
        bool isStrict() const { return _strict; }

        virtual void completerHighlighted(const QModelIndex &);

    signals:
        void newId(int);
        void parsed();
        void valid(bool);

    protected:
        virtual bool eventFilter(QObject *obj, QEvent* event);
        virtual void focusInEvent(QFocusEvent * event);
        virtual void resizeEvent(QResizeEvent *e);

        QAction* _infoAct;
        QAction* _openAct;
        QAction* _copyAct;
        QAction* _newAct;
        QCompleter* _completer;
        QLabel* _menuLabel;
        QMenu* _menu;
        QString _titleSingular;
        QString _titlePlural;
        QString _query;
        QString _activeClause;
        QString _idClause;
        QString _numClause;
        QString _extraClause;
        QString _name;
        QString _description;
        QString _idColName;
        QString _numColName;
        QString _nameColName;
        QString _descripColName;
        QString _activeColName;
        QString _uiName;
        QString _editPriv;
        QString _newPriv;
        QString _viewPriv;
        bool _hasDescription;
        bool _hasName;
        bool _hasActive;
        bool _strict;
        bool _showInactive;
        int _completerId;

        virtual void silentSetId(const int);

        QSqlQueryModel* _model;

    private:
        void positionMenuLabel();

        QString _cText;
};

/*

    VirtualCluster is a widget that contains a VirtualClusterLineEdit
    and surrounds it with a label and two buttons.  One button lets
    the user invoke VirtualClusterLineEdit's sInfo slot while another
    button invokes either sSearch() or sList(), depending on the
    user's preferences.
    
    VirtualCluster provides a copy of much of the VirtualClusterLineEdit
    API to hide from the caller the fact that it contains one of these
    objects.  It also lets the calling code set it as read-only.

*/

class XTUPLEWIDGETS_EXPORT VirtualCluster : public QWidget
{
    Q_OBJECT

    Q_PROPERTY(QString label          READ label          WRITE setLabel)
    Q_PROPERTY(bool    nameVisible    READ nameVisible    WRITE setNameVisible)
    Q_PROPERTY(bool    descriptionVisible    READ descriptionVisible    WRITE setDescriptionVisible)
    Q_PROPERTY(bool    readOnly       READ readOnly       WRITE setReadOnly)
    Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
    Q_PROPERTY(QString fieldName      READ fieldName      WRITE setFieldName)
    Q_PROPERTY(QString number         READ number         WRITE setNumber         DESIGNABLE false)
    Q_PROPERTY(QString defaultNumber  READ defaultNumber  WRITE setDefaultNumber  DESIGNABLE false)
    Q_PROPERTY(QString nullStr        READ nullStr        WRITE setNullStr)

    friend class VirtualClusterLineEdit;

    public:
        VirtualCluster(QWidget*, const char* = 0);
        VirtualCluster(QWidget*, VirtualClusterLineEdit* = 0, const char* = 0);

        Q_INVOKABLE inline virtual int     id()             const { return _number->id(); }
                    inline virtual QString label()          const { return _label->text(); }
                    inline virtual QString number()         const { return _number->text(); }
        Q_INVOKABLE inline virtual QString description()    const { return _description->text(); }
        Q_INVOKABLE inline virtual bool    isValid()        const { return _number->isValid(); }
        Q_INVOKABLE        virtual QString name()           const { return _name->text(); }
        Q_INVOKABLE inline virtual bool    isStrict()       const { return _number->isStrict(); }
                    inline virtual bool    readOnly()       const { return _readOnly; }
                           virtual QString defaultNumber()  const { return _default; }
                    inline virtual QString fieldName()      const { return _fieldName; }
        Q_INVOKABLE inline virtual QString extraClause()    const { return _number->extraClause(); }

        virtual Qt::Orientation orientation();
        virtual void setOrientation(Qt::Orientation orientation);

        virtual bool   nameVisible() const;
        virtual void   setNameVisible(const bool p);

        virtual bool   descriptionVisible() const;
        virtual void   setDescriptionVisible(const bool p);

        virtual QString nullStr() const;
        virtual void setNullStr(const QString &text);

    public slots:
        // most of the heavy lifting is done by VirtualClusterLineEdit _number
        virtual void clearExtraClause()                { _number->clearExtraClause(); }
        virtual void setDefaultNumber(const QString& p){ _default=p;}
        virtual void setDescription(const QString& p)  { _description->setText(p); }
        virtual void setExtraClause(const QString& p, const QString& = QString::null)  { _number->setExtraClause(p); }
        virtual void setFieldName(QString p)           { _fieldName = p; }
        virtual void setId(const int p, const QString& = QString::null)                { _number->setId(p); }
        virtual void setName(int, const QString& p)    { _name->setText(p); }
        virtual void setNumber(const int p)            { _number->setNumber(QString::number(p)); }
        virtual void setNumber(QString p)              { _number->setNumber(p); }

        virtual void clear();
        virtual void setDataWidgetMap(XDataWidgetMapper* m);
        virtual void setEnabled(const bool p);
        virtual void setLabel(const QString& p);
        virtual void setStrict(const bool b);
        virtual void setReadOnly(const bool b);
        virtual void setShowInactive(const bool);
        virtual void sRefresh();
        virtual void updateMapperData();

        virtual void sEllipses();
        virtual void sInfo();
        virtual void sList();
        virtual void sSearch();

    signals:
        void newId(int);
        void valid(bool);

    protected:
        virtual void addNumberWidget(VirtualClusterLineEdit* pNumberWidget);

        QGridLayout*            _grid;
        QLabel*                 _label;
        VirtualClusterLineEdit* _number;
        QLabel*                 _description;
        QLabel*                 _name;
        QSpacerItem*            _hspcr;
        bool                    _readOnly;
	QString                 _fieldName;
        QString                 _default;
        XDataWidgetMapper       *_mapper;
        Qt::Orientation         _orientation;

    private:
        virtual void init();
};

#endif