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
|
/***************************************************************************
copyright : (C) 2005-2007 by Robby Stephenson
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
#include "loanview.h"
#include "loanitem.h"
#include "controller.h"
#include "borrower.h"
#include "entry.h"
#include "collection.h"
#include "tellico_kernel.h"
#include "tellico_debug.h"
#include "listviewcomparison.h"
#include <klocale.h>
#include <kpopupmenu.h>
#include <kiconloader.h>
#include <tqheader.h>
using Tellico::LoanView;
LoanView::LoanView(TQWidget* parent_, const char* name_) : GUI::ListView(parent_, name_), m_notSortedYet(true) {
addColumn(i18n("Borrower"));
header()->setStretchEnabled(true, 0);
setResizeMode(TQListView::NoColumn);
setRootIsDecorated(true);
setShowSortIndicator(true);
setTreeStepSize(15);
setFullWidth(true);
connect(this, TQT_SIGNAL(contextMenuRequested(TQListViewItem*, const TQPoint&, int)),
TQT_SLOT(contextMenuRequested(TQListViewItem*, const TQPoint&, int)));
connect(this, TQT_SIGNAL(expanded(TQListViewItem*)),
TQT_SLOT(slotExpanded(TQListViewItem*)));
connect(this, TQT_SIGNAL(collapsed(TQListViewItem*)),
TQT_SLOT(slotCollapsed(TQListViewItem*)));
}
bool LoanView::isSelectable(GUI::ListViewItem* item_) const {
if(!GUI::ListView::isSelectable(item_)) {
return false;
}
// because the popup menu has modify, only
// allow one loan item to get selected
if(item_->isLoanItem()) {
return selectedItems().isEmpty();
}
return true;
}
void LoanView::contextMenuRequested(TQListViewItem* item_, const TQPoint& point_, int) {
if(!item_) {
return;
}
GUI::ListViewItem* item = static_cast<GUI::ListViewItem*>(item_);
if(item->isLoanItem()) {
KPopupMenu menu(this);
menu.insertItem(SmallIconSet(TQString::tqfromLatin1("2downarrow")),
i18n("Check-in"), this, TQT_SLOT(slotCheckIn()));
menu.insertItem(SmallIconSet(TQString::tqfromLatin1("2downarrow")),
i18n("Modify Loan..."), this, TQT_SLOT(slotModifyLoan()));
menu.exec(point_);
}
}
// this gets called when header() is clicked, so cycle through
void LoanView::setSorting(int col_, bool asc_) {
if(asc_ && !m_notSortedYet) {
if(sortStyle() == ListView::SortByText) {
setSortStyle(ListView::SortByCount);
} else {
setSortStyle(ListView::SortByText);
}
}
if(sortStyle() == ListView::SortByText) {
setColumnText(0, i18n("Borrower"));
} else {
setColumnText(0, i18n("Borrower (Sort by Count)"));
}
m_notSortedYet = false;
ListView::setSorting(col_, asc_);
}
void LoanView::addCollection(Data::CollPtr coll_) {
Data::BorrowerVec borrowers = coll_->borrowers();
for(Data::BorrowerVec::Iterator it = borrowers.begin(); it != borrowers.end(); ++it) {
addBorrower(it);
}
Data::FieldPtr f = coll_->fieldByName(TQString::tqfromLatin1("title"));
if(f) {
setComparison(0, ListViewComparison::create(f));
}
}
void LoanView::addField(Data::CollPtr, Data::FieldPtr) {
resetComparisons();
}
void LoanView::modifyField(Data::CollPtr, Data::FieldPtr, Data::FieldPtr) {
resetComparisons();
}
void LoanView::removeField(Data::CollPtr, Data::FieldPtr) {
resetComparisons();
}
void LoanView::addBorrower(Data::BorrowerPtr borrower_) {
if(!borrower_ || borrower_->isEmpty()) {
return;
}
BorrowerItem* borrowerItem = new BorrowerItem(this, borrower_);
borrowerItem->setExpandable(!borrower_->loans().isEmpty());
m_itemDict.insert(borrower_->name(), borrowerItem);
}
void LoanView::modifyBorrower(Data::BorrowerPtr borrower_) {
if(!borrower_) {
return;
}
BorrowerItem* borrowerItem = m_itemDict[borrower_->name()];
if(!borrowerItem) {
myDebug() << "LoanView::modifyBorrower() - borrower was never added" << endl;
return;
}
if(borrower_->isEmpty()) {
m_itemDict.remove(borrower_->name());
delete borrowerItem;
return;
}
bool open = borrowerItem->isOpen();
borrowerItem->setOpen(false);
borrowerItem->setOpen(open);
}
void LoanView::slotCollapsed(TQListViewItem* item_) {
// only change icon for group items
if(static_cast<GUI::ListViewItem*>(item_)->isBorrowerItem()) {
static_cast<GUI::ListViewItem*>(item_)->clear();
}
}
void LoanView::slotExpanded(TQListViewItem* item_) {
// only change icon for group items
if(!static_cast<GUI::ListViewItem*>(item_)->isBorrowerItem()) {
kdWarning() << "GroupView::slotExpanded() - non entry group item - " << item_->text(0) << endl;
return;
}
setUpdatesEnabled(false);
BorrowerItem* item = static_cast<BorrowerItem*>(item_);
Data::LoanVec loans = item->borrower()->loans();
for(Data::LoanVec::Iterator it = loans.begin(); it != loans.end(); ++it) {
new LoanItem(item, it);
}
setUpdatesEnabled(true);
triggerUpdate();
}
void LoanView::slotCheckIn() {
GUI::ListViewItem* item = selectedItems().getFirst();
if(!item || !item->isLoanItem()) {
return;
}
Data::EntryVec entries;
// need a copy since we may be deleting
GUI::ListViewItemList list = selectedItems();
for(GUI::ListViewItemListIt it(list); it.current(); ++it) {
Data::EntryPtr entry = static_cast<LoanItem*>(it.current())->entry();
if(!entry) {
myDebug() << "LoanView::slotCheckIn() - no entry!" << endl;
continue;
}
entries.append(entry);
}
Controller::self()->slotCheckIn(entries);
Controller::self()->slotClearSelection(); // so the checkout menu item gets disabled
}
void LoanView::slotModifyLoan() {
GUI::ListViewItem* item = selectedItems().getFirst();
if(!item || !item->isLoanItem()) {
return;
}
Kernel::self()->modifyLoan(static_cast<LoanItem*>(item)->loan());
}
void LoanView::resetComparisons() {
// this is only allowed when the view is not empty, so we can grab a collection ptr
if(childCount() == 0) {
return;
}
Data::EntryVec entries = static_cast<BorrowerItem*>(firstChild())->entries();
if(entries.isEmpty()) {
return;
}
Data::EntryPtr entry = entries[0];
if(!entry) {
return;
}
Data::CollPtr coll = entry->collection();
if(!coll) {
return;
}
Data::FieldPtr f = coll->fieldByName(TQString::tqfromLatin1("title"));
if(f) {
setComparison(0, ListViewComparison::create(f));
}
}
#include "loanview.moc"
|