COPASI API  4.16.103
CQTableView.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include "CQTableView.h"
7 
8 #include <QtGui/QKeyEvent>
9 #include <QtCore/QTimer>
10 
11 #include <iostream>
12 
13 CQTableView::CQTableView(QWidget * pParent):
14  QTableView(pParent),
15  mpTimer(NULL),
16  mpMouseEvent(NULL),
17  mMoveDown(false),
18  mpModel(NULL)
19 {
20  mpTimer = new QTimer(this);
21  mpTimer->setSingleShot(true);
22  mpTimer->setInterval(250);
23 
24  connect(mpTimer, SIGNAL(timeout()), this, SLOT(slotSingleClick()));
25 }
26 
27 // virtual
29 {}
30 
31 // virtual
32 void CQTableView::setModel(QAbstractItemModel * model)
33 {
34  if (mpModel != NULL)
35  disconnect(mpModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex)),
36  this, SLOT(slotMoveDown()));
37 
38  mpModel = model;
39 
40  if (mpModel != NULL)
41  connect(mpModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex)),
42  this, SLOT(slotMoveDown()));
43 
44  QTableView::setModel(model);
45 }
46 
47 // virtual
48 void CQTableView::keyPressEvent(QKeyEvent * pEvent)
49 {
50  QTableView::keyPressEvent(pEvent);
51 
52  switch (pEvent->key())
53  {
54  case Qt::Key_Return:
55  case Qt::Key_Enter:
56  mMoveDown = true;
57  break;
58 
59  default:
60  mMoveDown = false;
61  break;
62  }
63 }
64 
65 // virtual
66 void CQTableView::mousePressEvent(QMouseEvent * pEvent)
67 {
68  if (mpMouseEvent != NULL)
69  {
70  delete mpMouseEvent;
71  mpMouseEvent = NULL;
72  }
73 
74  if (mpTimer->isActive())
75  {
76  QTableView::mousePressEvent(pEvent);
77  emit doubleClicked(currentIndex());
78 
79  return;
80  }
81 
82  mpMouseEvent = new QMouseEvent(*pEvent);
83  pEvent->accept();
84  mpTimer->start();
85 }
86 
88 {
89  if (mpMouseEvent != NULL)
90  {
91  QTableView::mousePressEvent(mpMouseEvent);
92  mpMouseEvent = NULL;
93  }
94 }
95 
97 {
98  if (mMoveDown)
99  {
100  QKeyEvent Down(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
101  QTableView::keyPressEvent(&Down);
102  }
103 }
virtual ~CQTableView()
Definition: CQTableView.cpp:28
bool mMoveDown
Definition: CQTableView.h:50
virtual void mousePressEvent(QMouseEvent *pEvent)
Definition: CQTableView.cpp:66
void slotMoveDown()
Definition: CQTableView.cpp:96
virtual void setModel(QAbstractItemModel *model)
Definition: CQTableView.cpp:32
QMouseEvent * mpMouseEvent
Definition: CQTableView.h:49
virtual void keyPressEvent(QKeyEvent *pEvent)
Definition: CQTableView.cpp:48
QAbstractItemModel * mpModel
Definition: CQTableView.h:51
CQTableView(QWidget *pParent=NULL)
Definition: CQTableView.cpp:13
QTimer * mpTimer
Definition: CQTableView.h:48
void slotSingleClick()
Definition: CQTableView.cpp:87