|
25 | 25 | #include "accountdetail.h"
|
26 | 26 |
|
27 | 27 | AccountList::AccountList(QWidget *parent) :
|
28 |
| - QWidget(parent) |
| 28 | + AbstractItemList(parent) |
29 | 29 | {
|
30 |
| - // initialize members |
31 |
| - accountList = new QListView(); |
32 |
| - accountTabs = new QTabWidget(); |
33 |
| - welcomeText = new QLabel(tr("Waehlen sie in der Liste einen Eintrag aus, um hier die dazugehoerigen Details anzuzeigen.")); |
34 |
| - search = new SearchField(); |
35 |
| - |
36 |
| - accountList->setAlternatingRowColors(true); |
37 |
| - accountTabs->setTabsClosable(true); |
38 |
| - |
39 |
| - // layout |
40 |
| - QHBoxLayout *layout = new QHBoxLayout(); |
41 |
| - QVBoxLayout *left = new QVBoxLayout(); |
42 |
| - stack = new QStackedLayout(); |
43 |
| - |
44 |
| - left->setSpacing(4); |
45 |
| - left->addWidget(search); |
46 |
| - left->addWidget(accountList); |
47 |
| - |
48 |
| - stack->addWidget(accountTabs); |
49 |
| - stack->addWidget(welcomeText); |
50 |
| - stack->setCurrentWidget(welcomeText); |
51 |
| - |
52 |
| - layout->setSpacing(0); |
53 |
| - layout->addLayout(left, 1); |
54 |
| - layout->addLayout(stack, 2); |
55 |
| - |
56 |
| - setLayout(layout); |
57 |
| - |
58 |
| - // connect signals and slots |
59 |
| - connect(accountList, SIGNAL(doubleClicked(QModelIndex)), |
60 |
| - this, SLOT(openAccountDetails(QModelIndex))); |
61 |
| - connect(search, SIGNAL(searchPhraseChanged(QString)), |
62 |
| - this, SLOT(filterAccountList(QString))); |
63 |
| - connect(accountTabs, SIGNAL(tabCloseRequested(int)), |
64 |
| - this, SLOT(closeAccountTab(int))); |
65 | 30 | }
|
66 | 31 |
|
67 | 32 | void AccountList::setModel(AccountProxyModel *model)
|
68 | 33 | {
|
69 |
| - accountModel = model; |
70 |
| - accountList->setModel(accountModel); |
| 34 | + itemsModel = model; |
| 35 | + listView->setModel(itemsModel); |
71 | 36 | }
|
72 | 37 |
|
73 |
| -void AccountList::openAccountDetails(const QModelIndex index) |
| 38 | +AccountProxyModel* AccountList::getModel() |
74 | 39 | {
|
75 |
| - QModelIndex num(accountModel->mapToSource(index)); |
76 |
| - qDebug() << "[app] now's a good time to open the info for " << num.row(); |
77 |
| - AccountDetail *item = new AccountDetail(&num); |
78 |
| - accountTabs->setCurrentIndex(accountTabs->addTab(item, item->getItem()->name)); |
79 |
| - |
80 |
| - // make the tabwidget visible |
81 |
| - stack->setCurrentWidget(accountTabs); |
| 40 | + return itemsModel; |
82 | 41 | }
|
83 | 42 |
|
84 |
| -void AccountList::filterAccountList(QString phrase) |
| 43 | +void AccountList::openDetail(const QModelIndex index) |
85 | 44 | {
|
86 |
| - accountModel->setFilterRegExp(QRegExp(phrase, Qt::CaseInsensitive, QRegExp::FixedString)); |
87 |
| -} |
| 45 | + QModelIndex num(getModel()->mapToSource(index)); |
| 46 | + qDebug() << "[app] now's a good time to open the info for " << num.row(); |
| 47 | + AccountDetail *item = new AccountDetail(&num); |
| 48 | + tabView->setCurrentIndex(tabView->addTab(item, item->getItem()->name)); |
88 | 49 |
|
89 |
| -void AccountList::closeAccountTab(const int index) |
90 |
| -{ |
91 |
| - QWidget *tab = accountTabs->widget(index); |
92 |
| - accountTabs->removeTab(index); |
93 |
| - if(!tab->property("doNotDelete").toBool()) { |
94 |
| - tab->deleteLater(); |
95 |
| - } |
96 |
| - if(accountTabs->count() < 1) { |
97 |
| - stack->setCurrentWidget(welcomeText); |
98 |
| - } |
| 50 | + // make the tabwidget visible |
| 51 | + stack->setCurrentWidget(tabView); |
99 | 52 | }
|
0 commit comments