Select newly created groups and expand parent.

This commit is contained in:
Florian Geyer 2012-04-27 18:45:26 +02:00 committed by Felix Geyer
parent 84a9e397d2
commit 554029ac31
3 changed files with 16 additions and 2 deletions

View File

@ -206,6 +206,8 @@ void DatabaseWidget::switchToView(bool accepted)
if (m_newGroup) {
if (accepted) {
m_newGroup->setParent(m_newParent);
m_groupView->setCurrentGroup(m_newGroup);
m_groupView->expandGroup(m_newParent);
}
else {
delete m_newGroup;

View File

@ -72,14 +72,19 @@ void GroupView::expandedChanged(const QModelIndex& index)
void GroupView::recInitExpanded(Group* group)
{
QModelIndex index = m_model->index(group);
setExpanded(index, group->isExpanded());
expandGroup(group, group->isExpanded());
Q_FOREACH (Group* child, group->children()) {
recInitExpanded(child);
}
}
void GroupView::expandGroup(Group* group, bool expand)
{
QModelIndex index = m_model->index(group);
setExpanded(index, expand);
}
void GroupView::emitGroupChanged(const QModelIndex& index)
{
Q_EMIT groupChanged(m_model->groupFromIndex(index));
@ -95,3 +100,8 @@ void GroupView::emitGroupChanged()
{
Q_EMIT groupChanged(currentGroup());
}
void GroupView::setCurrentGroup(Group* group)
{
setCurrentIndex(m_model->index(group));
}

View File

@ -32,6 +32,8 @@ public:
explicit GroupView(Database* db, QWidget* parent = 0);
void setModel(QAbstractItemModel* model);
Group* currentGroup();
void setCurrentGroup(Group* group);
void expandGroup(Group* group, bool expand = true);
Q_SIGNALS:
void groupChanged(Group* group);