UEFITool/treeitem.cpp

226 lines
4.2 KiB
C++
Raw Permalink Normal View History

2013-10-08 15:07:03 +08:00
/* treeitem.cpp
Copyright (c) 2015, Nikolaj Schlej. All rights reserved.
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
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
*/
#include <QObject>
2013-10-08 15:07:03 +08:00
#include "treeitem.h"
#include "types.h"
2013-10-08 15:07:03 +08:00
TreeItem::TreeItem(const UINT8 type, const UINT8 subtype, const UINT8 compression,
const QString & name, const QString & text, const QString & info,
const QByteArray & header, const QByteArray & body,
TreeItem *parent) :
itemAction(Actions::NoAction),
itemType(type),
itemSubtype(subtype),
itemCompression(compression),
itemDictionarySize(0),
itemName(name),
itemText(text),
itemInfo(info),
itemHeader(header),
itemBody(body),
parentItem(parent)
{
2013-10-08 15:07:03 +08:00
}
TreeItem::~TreeItem()
{
qDeleteAll(childItems);
}
void TreeItem::appendChild(TreeItem *item)
{
childItems.append(item);
}
void TreeItem::prependChild(TreeItem *item)
{
childItems.prepend(item);
}
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
{
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
}
TreeItem *TreeItem::child(int row)
{
return childItems.value(row, NULL);
2013-10-08 15:07:03 +08:00
}
int TreeItem::childCount() const
{
return childItems.count();
}
int TreeItem::columnCount() const
{
return 5;
2013-10-08 15:07:03 +08:00
}
QVariant TreeItem::data(int column) const
2013-10-08 15:07:03 +08:00
{
switch (column)
2013-10-08 15:07:03 +08:00
{
case 0: // Name
return itemName;
case 1: // Action
return actionTypeToQString(itemAction);
case 2: // Type
return itemTypeToQString(itemType);
case 3: // Subtype
return itemSubtypeToQString(itemType, itemSubtype);
case 4: // Text
2013-10-08 15:07:03 +08:00
return itemText;
default:
return QVariant();
2013-10-08 15:07:03 +08:00
}
}
TreeItem *TreeItem::parent()
{
return parentItem;
}
QString TreeItem::name() const
2013-10-08 15:07:03 +08:00
{
return itemName;
2013-10-08 15:07:03 +08:00
}
void TreeItem::setName(const QString &name)
2013-10-08 15:07:03 +08:00
{
itemName = name;
2013-10-08 15:07:03 +08:00
}
QString TreeItem::text() const
2013-10-08 15:07:03 +08:00
{
return itemText;
2013-10-08 15:07:03 +08:00
}
void TreeItem::setText(const QString &text)
2013-10-08 15:07:03 +08:00
{
itemText = text;
2013-10-08 15:07:03 +08:00
}
QString TreeItem::info() const
2013-10-08 15:07:03 +08:00
{
return itemInfo;
}
void TreeItem::addInfo(const QString &info)
{
itemInfo += info;
}
void TreeItem::setInfo(const QString &info)
{
itemInfo = info;
}
2013-10-08 15:07:03 +08:00
int TreeItem::row() const
{
if (parentItem)
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
return 0;
}
UINT8 TreeItem::type() const
2013-10-08 15:07:03 +08:00
{
return itemType;
}
void TreeItem::setType(const UINT8 type)
{
itemType = type;
}
UINT8 TreeItem::subtype() const
2013-10-08 15:07:03 +08:00
{
return itemSubtype;
2013-10-08 15:07:03 +08:00
}
void TreeItem::setSubtype(const UINT8 subtype)
{
itemSubtype = subtype;
}
UINT8 TreeItem::compression() const
{
return itemCompression;
}
QByteArray TreeItem::header() const
2013-10-08 15:07:03 +08:00
{
return itemHeader;
}
QByteArray TreeItem::body() const
2013-10-08 15:07:03 +08:00
{
return itemBody;
}
bool TreeItem::hasEmptyHeader() const
2013-10-08 15:07:03 +08:00
{
return itemHeader.isEmpty();
}
bool TreeItem::hasEmptyBody() const
2013-10-08 15:07:03 +08:00
{
return itemBody.isEmpty();
}
UINT8 TreeItem::action() const
{
return itemAction;
}
UINT32 TreeItem::dictionarySize() const
{
return itemDictionarySize;
}
void TreeItem::setDictionarySize(const UINT32 dictionarySize)
{
itemDictionarySize = dictionarySize;
}
void TreeItem::setAction(const UINT8 action)
{
itemAction = action;
// On insert action, set insert action for children
if (action == Actions::Insert)
for (int i = 0; i < childCount(); i++)
child(i)->setAction(Actions::Insert);
// Set rebuild action for parent, if it has no action now
if (parentItem && parentItem->type() != Types::Root
2018-06-24 00:46:56 +08:00
&& parentItem->action() == Actions::NoAction)
parentItem->setAction(Actions::Rebuild);
2018-06-23 05:39:51 +08:00
}