keepassxc/src/gui/GroupView.cpp

81 lines
2.2 KiB
C++
Raw Normal View History

2010-08-22 10:02:44 -04:00
/*
* 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"
2010-10-06 13:40:50 -04:00
#include <QtCore/QMetaObject>
2010-08-22 10:02:44 -04:00
#include "core/Database.h"
#include "core/Group.h"
#include "gui/GroupModel.h"
2010-08-24 17:12:01 -04:00
GroupView::GroupView(Database* db, QWidget* parent)
: QTreeView(parent)
2012-04-23 13:44:43 -04:00
, m_model(new GroupModel(db, this))
2010-08-22 10:02:44 -04:00
{
2010-08-23 14:57:38 -04:00
QTreeView::setModel(m_model);
2010-08-22 10:02:44 -04:00
setHeaderHidden(true);
2010-10-06 13:40:50 -04:00
setUniformRowHeights(true);
2010-08-24 16:26:52 -04:00
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(emitGroupChanged()));
2010-10-06 13:40:50 -04:00
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)));
2010-08-22 10:02:44 -04:00
}
Group* GroupView::currentGroup()
{
return m_model->groupFromIndex(currentIndex());
}
2010-08-22 10:02:44 -04:00
void GroupView::expandedChanged(const QModelIndex& index)
{
Group* group = m_model->groupFromIndex(index);
2010-08-22 10:02:44 -04:00
group->setExpanded(isExpanded(index));
}
void GroupView::recInitExpanded(Group* group)
2010-08-22 10:02:44 -04:00
{
2010-08-23 14:57:38 -04:00
QModelIndex index = m_model->index(group);
2010-08-22 10:02:44 -04:00
setExpanded(index, group->isExpanded());
Q_FOREACH (Group* child, group->children()) {
2010-08-22 10:02:44 -04:00
recInitExpanded(child);
}
}
2010-08-24 16:26:52 -04:00
void GroupView::emitGroupChanged(const QModelIndex& index)
{
Q_EMIT groupChanged(m_model->groupFromIndex(index));
}
2010-08-22 10:02:44 -04:00
void GroupView::setModel(QAbstractItemModel* model)
{
Q_UNUSED(model);
Q_ASSERT(false);
}
void GroupView::emitGroupChanged()
{
Q_EMIT groupChanged(currentGroup());
}