LibEngsas
edelegateforeignkey.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2012 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 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  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  MA 02110-1301 USA.
18 */
19 
20 #ifndef DELEGATEFOREIGNKEY_H
21 #define DELEGATEFOREIGNKEY_H
22 
23 #include "eglobal.h"
24 
25 #include <QStyledItemDelegate>
26 
27 #include <QPainter>
28 
29 class QSqlQueryModel;
30 class QTimer;
31 
44 class E_CORE_EXPORT EDelegateForeignKey : public QStyledItemDelegate{
45  Q_OBJECT
46  public:
54  EDelegateForeignKey(QString table, QString matchColumn, QString resultColumn, QWidget *parent = 0);
60  EDelegateForeignKey(QString table, QString matchColumn, QString resultColumn, QString (*translator)(const QString), QWidget *parent = 0);
61  void setTranslator(QString (*translator)(const QString));
62  void reloadForeignKeys();
63 
67  void paint(QPainter *painter, const QStyleOptionViewItem &option,
68  const QModelIndex &index) const;
69  QWidget *createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const;
70  void setEditorData(QWidget *editor, const QModelIndex &index) const;
71  void setModelData(QWidget *editor, QAbstractItemModel *model,
72  const QModelIndex &index) const;
73 
74  private slots:
75  void commitAndCloseEditor();
76  void doCloseEditor();
80  void updateCompleter();
81 // void doAddPair(QString key, unsigned int value);
82 
83  private:
84  void init(QString table, QString matchColumn, QString resultColumn);
89  QMap<QString, unsigned int> mapOutIn;
90  QString resTable, matchCol, resCol;
91  QSqlQueryModel *resultModel;
92  int maxComboItems, maxCompleteItems;
93  bool useComboBox, useCompleter, useExtendedCompleter;
94  QTimer *timer;
98  QString (*translator)(const QString);
99 
100  signals:
101 // void addPair(QString key, unsigned int value);
102 };
103 
104 #endif // DELEGATEFOREIGNKEY_H