1 /* This file is part of the KDE project
2 * Copyright (C) 2009 Pierre Stirnweiss <pstirnweiss@googlemail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 
20 #include "TrackedChangeManager.h"
21 
22 #include "TrackedChangeModel.h"
23 
24 #include <klocalizedstring.h>
25 
26 #include <QModelIndex>
27 #include <QTreeView>
28 
29 #include <QDebug>
30 
TrackedChangeManager(QWidget * parent)31 TrackedChangeManager::TrackedChangeManager(QWidget *parent)
32     : QWidget(parent)
33     , m_model(0)
34 {
35     widget.setupUi(this);
36 }
37 
~TrackedChangeManager()38 TrackedChangeManager::~TrackedChangeManager()
39 {
40 }
41 
setModel(TrackedChangeModel * model)42 void TrackedChangeManager::setModel(TrackedChangeModel *model)
43 {
44     m_model = model;
45     widget.treeView->setModel(m_model);
46     widget.treeView->reset();
47     connect(widget.treeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
48 }
49 
currentChanged(const QModelIndex & newIndex,const QModelIndex & previousIndex)50 void TrackedChangeManager::currentChanged(const QModelIndex &newIndex, const QModelIndex &previousIndex)
51 {
52     Q_UNUSED(previousIndex);
53     emit currentChanged(newIndex);
54 }
55 
selectItem(const QModelIndex & newIndex)56 void TrackedChangeManager::selectItem(const QModelIndex &newIndex)
57 {
58     QModelIndex currentIndex = widget.treeView->currentIndex();
59     widget.treeView->setCurrentIndex(newIndex);
60     currentChanged(newIndex, currentIndex);
61 }
62