Exemple #1
0
QModelIndex GraphModel::index(int row, int column, const QModelIndex &parent) const
{
    if (!hasIndex(row, column, parent))
	{
		return QModelIndex();
	}

    GraphItem *parentItem = NULL;
	if (!parent.isValid())
	{
		parentItem = rootItem;
	}
    else
	{
		parentItem = static_cast<GraphItem*>(parent.internalPointer());
	}

    GraphItem *childItem = parentItem->Child(row);
    if (childItem)
	{
		return createIndex(row, column, childItem);
	}

	return QModelIndex();
}
void * GraphModel::ItemData(const QModelIndex &index) const
{
    if (index.isValid())
	{
        GraphItem *item = static_cast<GraphItem*>(index.internalPointer());
        return item->GetUserData();
	}
    
    return NULL;
}
Exemple #3
0
QVariant GraphModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
	{
		return QVariant();
	}

    if (role != Qt::DisplayRole)
	{
		return QVariant();
	}

    GraphItem *item = static_cast<GraphItem*>(index.internalPointer());
    return item->Data(index.column());
}
int GraphModel::rowCount(const QModelIndex &parent) const
{
    if (parent.column() > 0)
	{
		return 0;
	}

    GraphItem *parentItem = ParentItem(parent);
    if(parentItem)
    {
        return parentItem->ChildrenCount();
    }

    return 0;
}
QModelIndex GraphModel::index(int row, int column, const QModelIndex &parent) const
{
    if (!hasIndex(row, column, parent))
	{
		return QModelIndex();
	}

    GraphItem *parentItem = ParentItem(parent);
    GraphItem *childItem = parentItem->Child(row);
    if (childItem)
	{
		return createIndex(row, column, childItem);
	}

	return QModelIndex();
}
Exemple #6
0
QModelIndex GraphModel::parent(const QModelIndex &index) const
{
    if (!index.isValid())
	{
		return QModelIndex();
	}

    GraphItem *childItem = static_cast<GraphItem*>(index.internalPointer());
    GraphItem *parentItem = childItem->GetParent();

    if (parentItem == rootItem)
	{
		return QModelIndex();
	}

    return createIndex(parentItem->Row(), 0, parentItem);
}
Exemple #7
0
int GraphModel::rowCount(const QModelIndex &parent) const
{
    GraphItem *parentItem;
    if (parent.column() > 0)
	{
		return 0;
	}

    if (!parent.isValid())
	{
		parentItem = rootItem;
	}
    else
	{
		parentItem = static_cast<GraphItem*>(parent.internalPointer());
	}

    return parentItem->ChildrenCount();
}
Exemple #8
0
void GraphView::showGraph(bool show, int id)
{
	if (show)
		_hide.remove(id);
	else
		_hide.insert(id);

	_visible.clear();
	_bounds = QRectF();
	for (int i = 0; i < _graphs.count(); i++) {
		GraphItem* gi = _graphs.at(i);
		if (_hide.contains(gi->id()))
			removeItem(gi);
		else {
			addItem(gi);
			_visible.append(gi);
			_bounds |= gi->bounds();
		}
	}
}
Exemple #9
0
void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
{
	if (graph.size() < 2)
		return;

	GraphItem *gi = new GraphItem(graph);
	gi->setGraphType(_graphType);
	gi->setId(id);
	gi->setColor(_palette.nextColor());
	gi->setWidth(_width);

	connect(this, SIGNAL(sliderPositionChanged(qreal)), gi,
	  SLOT(emitSliderPositionChanged(qreal)));
	connect(gi, SIGNAL(sliderPositionChanged(qreal)), path,
	  SLOT(moveMarker(qreal)));
	connect(path, SIGNAL(selected(bool)), gi, SLOT(selected(bool)));

	_graphs.append(gi);

	if (!_hide.contains(id)) {
		_visible.append(gi);
		_scene->addItem(gi);
		_bounds |= gi->bounds();
		setXUnits();
	}
}