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
|
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GroupView.h"
#include <QtCore/QMetaObject>
#include "core/Database.h"
#include "core/Group.h"
#include "gui/GroupModel.h"
GroupView::GroupView(Database* db, QWidget* parent)
: QTreeView(parent)
{
m_model = new GroupModel(db, this);
QTreeView::setModel(m_model);
setHeaderHidden(true);
setUniformRowHeights(true);
connect(this, SIGNAL(clicked(const QModelIndex&)), SLOT(emitGroupChanged(const QModelIndex&)));
recInitExpanded(db->rootGroup());
setCurrentIndex(m_model->index(0, 0));
// invoke later so the EntryView is connected
QMetaObject::invokeMethod(this, "emitGroupChanged", Qt::QueuedConnection,
Q_ARG(QModelIndex, m_model->index(0, 0)));
}
void GroupView::expandedChanged(const QModelIndex& index)
{
Group* group = m_model->groupFromIndex(index);
group->setExpanded(isExpanded(index));
}
void GroupView::recInitExpanded(Group* group)
{
QModelIndex index = m_model->index(group);
setExpanded(index, group->isExpanded());
Q_FOREACH (Group* child, group->children()) {
recInitExpanded(child);
}
}
void GroupView::emitGroupChanged(const QModelIndex& index)
{
Q_EMIT groupChanged(m_model->groupFromIndex(index));
}
void GroupView::setModel(QAbstractItemModel* model)
{
Q_UNUSED(model);
Q_ASSERT(false);
}
|