2010-04-07 20:38:20 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file treeitem.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
* @defgroup uavobjectbrowser
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "treeitem.h"
|
|
|
|
|
2010-04-15 17:42:47 +02:00
|
|
|
int TreeItem::m_highlightTimeMs = 500;
|
|
|
|
|
2010-04-07 20:38:20 +02:00
|
|
|
TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent) :
|
2010-04-15 17:42:47 +02:00
|
|
|
QObject(0),
|
2010-04-07 20:38:20 +02:00
|
|
|
m_data(data),
|
2010-04-12 07:54:54 +02:00
|
|
|
m_parent(parent),
|
2010-04-15 12:42:01 +02:00
|
|
|
m_highlight(false),
|
|
|
|
m_changed(false)
|
2010-04-07 20:38:20 +02:00
|
|
|
{
|
2010-04-15 17:42:47 +02:00
|
|
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
2010-04-07 20:38:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem::TreeItem(const QVariant &data, TreeItem *parent) :
|
2010-04-15 17:42:47 +02:00
|
|
|
QObject(0),
|
2010-04-12 07:54:54 +02:00
|
|
|
m_parent(parent),
|
2010-04-15 12:42:01 +02:00
|
|
|
m_highlight(false),
|
|
|
|
m_changed(false)
|
2010-04-07 20:38:20 +02:00
|
|
|
{
|
|
|
|
m_data << data << "" << "";
|
2010-04-15 17:42:47 +02:00
|
|
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(removeHighlight()));
|
2010-04-07 20:38:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem::~TreeItem()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_children);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TreeItem::appendChild(TreeItem *child)
|
|
|
|
{
|
|
|
|
m_children.append(child);
|
2010-04-15 17:42:47 +02:00
|
|
|
child->setParentTree(this);
|
2010-04-07 20:38:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TreeItem::insert(int index, TreeItem *child)
|
|
|
|
{
|
|
|
|
m_children.insert(index, child);
|
2010-04-15 17:42:47 +02:00
|
|
|
child->setParentTree(this);
|
2010-04-07 20:38:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TreeItem *TreeItem::child(int row)
|
|
|
|
{
|
|
|
|
return m_children.value(row);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TreeItem::childCount() const
|
|
|
|
{
|
|
|
|
return m_children.count();
|
|
|
|
}
|
|
|
|
int TreeItem::row() const
|
|
|
|
{
|
|
|
|
if (m_parent)
|
|
|
|
return m_parent->m_children.indexOf(const_cast<TreeItem*>(this));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TreeItem::columnCount() const
|
|
|
|
{
|
|
|
|
return m_data.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant TreeItem::data(int column) const
|
|
|
|
{
|
|
|
|
return m_data.value(column);
|
|
|
|
}
|
|
|
|
|
2010-04-12 07:54:54 +02:00
|
|
|
void TreeItem::setData(QVariant value, int column)
|
2010-04-07 20:38:20 +02:00
|
|
|
{
|
|
|
|
m_data.replace(column, value);
|
|
|
|
}
|
2010-04-15 17:42:47 +02:00
|
|
|
|
|
|
|
void TreeItem::update() {
|
|
|
|
foreach(TreeItem *child, treeChildren())
|
|
|
|
child->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TreeItem::apply() {
|
|
|
|
foreach(TreeItem *child, treeChildren())
|
|
|
|
child->apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TreeItem::setHighlight(bool highlight) {
|
|
|
|
m_highlight = highlight;
|
|
|
|
m_changed = false;
|
|
|
|
if (highlight) {
|
|
|
|
if (m_timer.isActive()) {
|
|
|
|
m_timer.stop();
|
|
|
|
}
|
|
|
|
m_timer.setSingleShot(true);
|
|
|
|
m_timer.start(m_highlightTimeMs);
|
|
|
|
}
|
2010-04-16 07:47:29 +02:00
|
|
|
emit updateHighlight(this);
|
2010-04-15 17:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TreeItem::removeHighlight() {
|
|
|
|
m_highlight = false;
|
|
|
|
update();
|
2010-04-16 07:47:29 +02:00
|
|
|
emit updateHighlight(this);
|
2010-04-15 17:42:47 +02:00
|
|
|
}
|