ODIN
odinqt_callback.h
1 #include <qobject.h>
2 #include <qlistview.h>
3 #include <qpushbutton.h>
4 #include <qtoolbutton.h>
5 #include <qlineedit.h>
6 
7 #include "odinqt.h"
8 
9 #if QT_VERSION > 0x03FFFF
10 #define QT_VERSION_4
11 #else
12 #if QT_VERSION > 299
13 #define QT_VERSION_3
14 #else
15 #define QT_VERSION_PRE3
16 #endif
17 #endif
18 
19 
20 
24 class SlotDispatcher : public QObject {
25  Q_OBJECT
26 
27  public:
28 
29  SlotDispatcher(GuiListView* glv, GuiListViewCallback* glv_cb) {
30  glv_cache=glv;
31  glv_cb_cache=glv_cb;
32 #ifdef QT_VERSION_4
33  connect(glv->get_widget(), SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(qtwi_clicked(QTableWidgetItem*)) );
34 #else
35  connect(glv->get_widget(), SIGNAL(clicked(QListViewItem*)), this, SLOT(qlvi_clicked(QListViewItem*)) );
36 #endif
37  }
38 
39 
40  SlotDispatcher(GuiToolButton* gtb, QObject* receiver, const char* member) {
41  if(receiver) connect(gtb->qtb, SIGNAL(clicked()), receiver, member );
42  }
43 
44  SlotDispatcher(GuiButton* gb, QObject* receiver, const char* member) {
45  if(receiver) connect(gb->qpb, SIGNAL(clicked()), receiver, member );
46  }
47 
48  SlotDispatcher(GuiLineEdit* gle, QObject* receiver, const char* member) {
49  if(receiver) {
50 #ifdef QT_VERSION_4
51  connect(gle->qle, SIGNAL(editingFinished()), receiver, member );
52 #else
53 #ifdef QT_VERSION_3
54  connect(gle->qle, SIGNAL(lostFocus()), receiver, member ); // only available on Qt3
55 #endif
56  connect(gle->qle, SIGNAL(returnPressed()), receiver, member );
57 #endif
58  }
59  }
60 
61 
62  public slots:
63 
64  void qlvi_clicked(QListViewItem* item) {
65 #ifndef QT_VERSION_4
66  Log<OdinQt> odinlog("SlotDispatcher","qlvi_clicked");
67  ODINLOG(odinlog,normalDebug) << "item=" << item << STD_endl;
68  if(!glv_cb_cache) return;
69  GuiListItem* itemptr=0;
70  GuiListItem(); // create listmap
71  ODINLOG(odinlog,normalDebug) << "GuiListItem(); done" << STD_endl;
72  STD_map<QListViewItem*,GuiListItem*>::iterator it=GuiListItem::listmap->find(item);
73  if(it!=GuiListItem::listmap->end()) itemptr=it->second;
74  ODINLOG(odinlog,normalDebug) << "itemptr=" << itemptr << STD_endl;
75  glv_cb_cache->clicked(itemptr);
76 #endif
77  }
78 
79  void qtwi_clicked(QTableWidgetItem* item) {
80 #ifdef QT_VERSION_4
81  Log<OdinQt> odinlog("SlotDispatcher","qtwi_clicked");
82  ODINLOG(odinlog,normalDebug) << "item=" << item << STD_endl;
83  if(!glv_cb_cache) return;
84  GuiListItem* itemptr=0;
85  GuiListItem(); // create tablemap
86  ODINLOG(odinlog,normalDebug) << "GuiListItem(); done" << STD_endl;
87  STD_map<QTableWidgetItem*,GuiListItem*>::iterator it=GuiListItem::tablemap->find(item);
88  if(it!=GuiListItem::tablemap->end()) itemptr=it->second;
89  ODINLOG(odinlog,normalDebug) << "itemptr=" << itemptr << STD_endl;
90  glv_cb_cache->clicked(itemptr);
91 #endif
92  }
93 
94 
95  private:
96  void common_int() {
97  glv_cache=0;
98  glv_cb_cache=0;
99  }
100 
101  GuiListView* glv_cache;
102  GuiListViewCallback* glv_cb_cache;
103 
104 };
Definition: tjlog.h:218