Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014, Regents of the University of California, |
| 4 | * |
| 5 | * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD |
| 6 | * authors and contributors. |
| 7 | * |
| 8 | * NFD Control Center is free software: you can redistribute it and/or modify it under the |
| 9 | * terms of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 14 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with NFD |
| 17 | * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <QStringList> |
| 22 | #include "key-tree-item.hpp" |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ncc { |
| 26 | |
Yingdi Yu | 95dbc71 | 2016-03-21 09:56:57 -0700 | [diff] [blame] | 27 | KeyTreeItem::KeyTreeItem(const QVariant& name, const QVariant& data, |
| 28 | Type type, KeyTreeItem* parent) |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 29 | : m_name(name) |
| 30 | , m_data(data) |
| 31 | , m_type(type) |
Yingdi Yu | 95dbc71 | 2016-03-21 09:56:57 -0700 | [diff] [blame] | 32 | , m_isDefault(false) |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 33 | , m_parentItem(parent) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | KeyTreeItem::~KeyTreeItem() |
| 38 | { |
| 39 | qDeleteAll(m_childItems); |
| 40 | } |
| 41 | |
| 42 | void |
Yingdi Yu | 95dbc71 | 2016-03-21 09:56:57 -0700 | [diff] [blame] | 43 | KeyTreeItem::setDefault(bool isDefault) |
| 44 | { |
| 45 | m_isDefault = isDefault; |
| 46 | } |
| 47 | |
| 48 | void |
Yingdi Yu | 1f82464 | 2016-03-20 17:07:22 -0700 | [diff] [blame] | 49 | KeyTreeItem::setParent(KeyTreeItem* parent) |
| 50 | { |
| 51 | m_parentItem = parent; |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | KeyTreeItem::appendChild(KeyTreeItem* item) |
| 56 | { |
| 57 | m_childItems.append(item); |
| 58 | } |
| 59 | |
| 60 | KeyTreeItem* |
| 61 | KeyTreeItem::child(int row) |
| 62 | { |
| 63 | return m_childItems.value(row); |
| 64 | } |
| 65 | |
| 66 | int |
| 67 | KeyTreeItem::childCount() const |
| 68 | { |
| 69 | return m_childItems.count(); |
| 70 | } |
| 71 | |
| 72 | int |
| 73 | KeyTreeItem::columnCount() const |
| 74 | { |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | QVariant |
| 79 | KeyTreeItem::name() const |
| 80 | { |
| 81 | return m_name; |
| 82 | } |
| 83 | |
| 84 | QVariant |
| 85 | KeyTreeItem::data() const |
| 86 | { |
| 87 | return m_data; |
| 88 | } |
| 89 | |
| 90 | KeyTreeItem::Type |
| 91 | KeyTreeItem::type() const |
| 92 | { |
| 93 | return m_type; |
| 94 | } |
| 95 | |
| 96 | KeyTreeItem* |
| 97 | KeyTreeItem::parentItem() |
| 98 | { |
| 99 | return m_parentItem; |
| 100 | } |
| 101 | |
| 102 | int |
| 103 | KeyTreeItem::row() const |
| 104 | { |
| 105 | if (m_parentItem) |
| 106 | return m_parentItem->m_childItems.indexOf(const_cast<KeyTreeItem*>(this)); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | } // namespace ndn |
| 112 | } // namespace ncc |