-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClientTabBar.cpp
132 lines (119 loc) · 3.14 KB
/
ClientTabBar.cpp
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
#include <QVariant>
#include <QString>
#include "qtimemage.h"
#include "ClientTabBar.h"
ClientTabBar::
ClientTabBar(QWidget *parent)
/*****************************************************************************
* Constructor
*/
: QTabBar(parent)
{}
ClientTabBar::
~ClientTabBar()
/*****************************************************************************
* Find the QTabWidget index for the client of prj_id project, or -1;
*/
{}
int
ClientTabBar::
addTab(const QString &text, int64_t client_id, int64_t currentProject_id)
/*****************************************************************************
* Add a tab with a ClientTabData object attached.
*/
{
ClientTabData *td= new ClientTabData(client_id, currentProject_id);
int ndx= QTabBar::addTab(text);
QTabBar::setTabData(ndx, QVariant::fromValue(td));
return ndx;
}
ClientTabData*
ClientTabBar::
tabData(int ndx)
/*****************************************************************************
* Retrieve ClientTabData object attached.
*/
{
if(-1 == ndx) return NULL;
QVariant qv= QTabBar::tabData(ndx);
if(!qv.isValid()) return NULL;
ClientTabData *td= qv.value<ClientTabData*>();
Q_ASSERT(td);
return td;
}
ClientTabData*
ClientTabBar::
currentData()
/*****************************************************************************
* Retrieve ClientTabData object attached.
*/
{
return tabData(currentIndex());
}
int64_t
ClientTabBar::
tabClient_id(int ndx)
/*****************************************************************************
* Return the client_id for ndx, or -1;
*/
{
ClientTabData *td= tabData(ndx);
return td ? td->client_id : -1;
}
int64_t
ClientTabBar::
tabCurrentProject_id(int ndx)
/*****************************************************************************
* Return the currentProject_id for ndx, or -1;
*/
{
ClientTabData *td= tabData(ndx);
return td ? td->currentProject_id : -1;
}
int64_t
ClientTabBar::
currentClient_id()
/*****************************************************************************
* Return the current client_id, or -1;
*/
{
return tabClient_id(currentIndex());
}
int64_t
ClientTabBar::
currentCurrentProject_id()
/*****************************************************************************
* Return the current currentProject_id, or -1;
*/
{
return tabCurrentProject_id(currentIndex());
}
void
ClientTabBar::
removeTab(int ndx)
/*****************************************************************************
* Function overloaded to free ClientTabData object.
*/
{
ClientTabData *td= tabData(ndx);
if(td) delete td;
QTabBar::removeTab(ndx);
}
void
ClientTabBar::
projectSelected(int64_t client_id, int64_t project_id)
/*****************************************************************************
* Function sets value in ClientTabData.
*/
{
//J_DBG_FN;
ClientTabData *data;
for(int i= 0; i < count(); ++i) {
data= tabData(i);
if(data->client_id == client_id) {
data->currentProject_id= project_id;
//J_DBG_FN << "ndx= " << i << ", data= " << data << " { client_id= " << data->client_id << ", currentProject_id= " << data->currentProject_id << " }";
break;
}
}
}