2013-10-08 15:07:03 +08:00
|
|
|
/* treeitem.cpp
|
|
|
|
|
2015-01-31 22:00:00 +08:00
|
|
|
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
|
2013-12-29 23:13:46 +08:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2013-12-29 23:13:46 +08:00
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2013-10-08 15:07:03 +08:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
#include <QObject>
|
2013-10-08 15:07:03 +08:00
|
|
|
#include "treeitem.h"
|
2014-02-27 17:14:41 +08:00
|
|
|
#include "types.h"
|
2013-10-08 15:07:03 +08:00
|
|
|
|
2015-03-13 14:48:53 +08:00
|
|
|
TreeItem::TreeItem(const UINT8 type, const UINT8 subtype,
|
2014-07-25 07:59:51 +08:00
|
|
|
const QString & name, const QString & text, const QString & info,
|
2015-12-30 06:39:43 +08:00
|
|
|
const QByteArray & header, const QByteArray & body,
|
|
|
|
const BOOLEAN fixed, const BOOLEAN compressed, const QByteArray & parsingData,
|
2015-01-31 22:00:00 +08:00
|
|
|
TreeItem *parent) :
|
|
|
|
itemAction(Actions::NoAction),
|
|
|
|
itemType(type),
|
2015-02-06 16:47:19 +08:00
|
|
|
itemSubtype(subtype),
|
2015-01-31 22:00:00 +08:00
|
|
|
itemName(name),
|
|
|
|
itemText(text),
|
|
|
|
itemInfo(info),
|
|
|
|
itemHeader(header),
|
|
|
|
itemBody(body),
|
2015-02-06 16:47:19 +08:00
|
|
|
itemParsingData(parsingData),
|
2015-12-30 06:39:43 +08:00
|
|
|
itemFixed(fixed),
|
|
|
|
itemCompressed(compressed),
|
2015-01-31 22:00:00 +08:00
|
|
|
parentItem(parent)
|
2013-11-07 21:46:28 +08:00
|
|
|
{
|
2015-12-30 06:39:43 +08:00
|
|
|
setFixed(fixed);
|
2013-11-07 21:46:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT8 TreeItem::insertChildBefore(TreeItem *item, TreeItem *newItem)
|
|
|
|
{
|
|
|
|
int index = childItems.indexOf(item);
|
|
|
|
if (index == -1)
|
|
|
|
return ERR_ITEM_NOT_FOUND;
|
|
|
|
childItems.insert(index, newItem);
|
|
|
|
return ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT8 TreeItem::insertChildAfter(TreeItem *item, TreeItem *newItem)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2013-11-07 21:46:28 +08:00
|
|
|
int index = childItems.indexOf(item);
|
|
|
|
if (index == -1)
|
|
|
|
return ERR_ITEM_NOT_FOUND;
|
|
|
|
childItems.insert(index + 1, newItem);
|
|
|
|
return ERR_SUCCESS;
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 21:46:28 +08:00
|
|
|
QVariant TreeItem::data(int column) const
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2014-07-25 07:59:51 +08:00
|
|
|
switch (column)
|
2013-10-08 15:07:03 +08:00
|
|
|
{
|
2015-01-31 22:00:00 +08:00
|
|
|
case 0: // Name
|
2013-11-14 18:40:39 +08:00
|
|
|
return itemName;
|
2015-01-31 22:00:00 +08:00
|
|
|
case 1: // Action
|
2014-02-27 17:14:41 +08:00
|
|
|
return actionTypeToQString(itemAction);
|
2015-01-31 22:00:00 +08:00
|
|
|
case 2: // Type
|
|
|
|
return itemTypeToQString(itemType);
|
2015-02-06 16:47:19 +08:00
|
|
|
case 3: // Subtype
|
|
|
|
return itemSubtypeToQString(itemType, itemSubtype);
|
2015-01-31 22:00:00 +08:00
|
|
|
case 4: // Text
|
2013-10-08 15:07:03 +08:00
|
|
|
return itemText;
|
|
|
|
default:
|
2013-11-07 21:46:28 +08:00
|
|
|
return QVariant();
|
2013-10-08 15:07:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TreeItem::row() const
|
|
|
|
{
|
|
|
|
if (parentItem)
|
|
|
|
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|