Exemplo n.º 1
0
void ProjectModel::finishSingleMetadataUpdate(ThreadWeaver::Job* _job)
{
    UpdateStatsJob* job = static_cast<UpdateStatsJob*>(_job);

    if (job->m_status != 0)
    {
        delete job;
        return;
    }

    const KFileMetaInfo& info=job->m_info.first();
    QModelIndex index = indexForUrl(info.url());
    if (!index.isValid())
        return;

    ProjectNode* node = nodeForIndex(index);
    node->setFileStats(job->m_info.first());
    updateDirStats(nodeForIndex(index.parent()));

    QModelIndex topLeft = index.sibling(index.row(), Graph);
    QModelIndex bottomRight = index.sibling(index.row(), ProjectModelColumnCount - 1);
    emit dataChanged(topLeft, bottomRight);

    delete job;
}
Exemplo n.º 2
0
bool GSeqModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
{
	if(action == Qt::IgnoreAction) {
		return true;
	}
	if(!data->hasFormat("LabExe/EventNodes.list")) {
		return false;
	}
	if(column >= columnCount(parent)) {
		return false;
	}
	GEventNode* parentNode = nodeForIndex(parent);
	QByteArray encodedData = data->data("LabExe/EventNodes.list");
	QDataStream stream(&encodedData, QIODevice::ReadOnly);
	while(!stream.atEnd()) {
		QString text;
		stream >> text;
		qDebug() << text;
// 		GEventNode* node = tempNodeMime;
		GEventNode* node = EventManagerInstance()->GetEvent(text);
		if(node)
			insertNode(parentNode, row, node);
	}
	return true;
}
Exemplo n.º 3
0
int CObjectInspectorTreeModel::rowCount(const QModelIndex &parent) const
{
    if(parent.isValid() && parent.column()!=0)
        return  0;
    TreeNode * node = nodeForIndex(parent);
    return  node?node->childCount():0;
}
Exemplo n.º 4
0
QModelIndex PuppyFileSystemModel::index(int row, int column, const QModelIndex &parent) const
{
    if(hasIndex(row, column, parent)) {
        Node *parentNode = nodeForIndex(parent);
        Node *childNode = parentNode->children.at(row);
        return createIndex(row, column, childNode);
    }
    return QModelIndex();
}
Exemplo n.º 5
0
QModelIndex GSeqModel::index(int row, int column, const QModelIndex & parent) const
{
	if(!hasIndex(row, column, parent))
		return QModelIndex();

	GEventNode* parentNode = nodeForIndex(parent);
	GEventNode* childNode = parentNode->ChildNodes().at(row);
	return createIndex(row, column, childNode);
}
Exemplo n.º 6
0
QVariant FlatModel::data(const QModelIndex &index, int role) const
{
    QVariant result;

    if (Node *node = nodeForIndex(index)) {
        FolderNode *folderNode = node->asFolderNode();
        switch (role) {
        case Qt::DisplayRole: {
            QString name = node->displayName();

            if (node->nodeType() == NodeType::Project
                    && node->parentFolderNode()
                    && node->parentFolderNode()->nodeType() == NodeType::Session) {
                const QString vcsTopic = static_cast<ProjectNode *>(node)->vcsTopic();

                if (!vcsTopic.isEmpty())
                    name += QLatin1String(" [") + vcsTopic + QLatin1Char(']');
            }

            result = name;
            break;
        }
        case Qt::EditRole: {
            result = node->filePath().fileName();
            break;
        }
        case Qt::ToolTipRole: {
            result = node->tooltip();
            break;
        }
        case Qt::DecorationRole: {
            if (folderNode)
                result = folderNode->icon();
            else
                result = Core::FileIconProvider::icon(node->filePath().toString());
            break;
        }
        case Qt::FontRole: {
            QFont font;
            if (node == m_startupProject)
                font.setBold(true);
            result = font;
            break;
        }
        case Project::FilePathRole: {
            result = node->filePath().toString();
            break;
        }
        case Project::EnabledRole: {
            result = node->isEnabled();
            break;
        }
        }
    }

    return result;
}
Exemplo n.º 7
0
void ProjectModel::pot_dataChanged(const QModelIndex& pot_topLeft, const QModelIndex& pot_bottomRight)
{
    //tricky here - some of the pot items may be represented by po items
    //let's propagate that all subitems changed


    QModelIndex pot_parent = pot_topLeft.parent();
    QModelIndex parent = indexForPotIndex(pot_parent);

    ProjectNode* node = nodeForIndex(parent);
    int count = node->rows.count();

    QModelIndex topLeft = index(0, pot_topLeft.column(), parent);
    QModelIndex bottomRight = index(count-1, pot_bottomRight.column(), parent);

    emit dataChanged(topLeft, bottomRight);

    enqueueNodeForMetadataUpdate(nodeForIndex(topLeft.parent()));
}
Exemplo n.º 8
0
QModelIndex FlatModel::parent(const QModelIndex &idx) const
{
    QModelIndex parentIndex;
    if (Node *node = nodeForIndex(idx)) {
        FolderNode *parentNode = visibleFolderNode(node->parentFolderNode());
        if (parentNode)
            return indexForNode(parentNode);
    }
    return parentIndex;
}
Exemplo n.º 9
0
void ProjectModel::po_rowsInserted(const QModelIndex& po_parent, int first, int last)
{
    QModelIndex parent = indexForPoIndex(po_parent);
    QModelIndex pot_parent = potIndexForOuter(parent);
    ProjectNode* node = nodeForIndex(parent);

    //insert po rows
    beginInsertRows(parent, first, last);

    for (int pos = first; pos <= last; pos ++)
    {
        ProjectNode * childNode = new ProjectNode(node, pos, pos, -1);
        node->rows.insert(pos, childNode);
    }

    node->poCount += last - first + 1;

    //update rowNumber
    for (int pos = last + 1; pos < node->rows.count(); pos++)
        node->rows[pos]->rowNumber = pos;

    endInsertRows();

    //remove unneeded pot rows, update PO rows
    if (pot_parent.isValid() || !parent.isValid())
    {
        QVector<int> pot2PoMapping;
        generatePOTMapping(pot2PoMapping, po_parent, pot_parent);

        for (int pos = node->poCount; pos < node->rows.count(); pos ++)
        {
            ProjectNode* potNode = node->rows.at(pos);
            int potIndex = potNode->potRowNumber;
            int poIndex = pot2PoMapping[potIndex];

            if (poIndex != -1)
            {
                //found pot node, that now has a PO index.
                //remove the pot node and change the corresponding PO node
                beginRemoveRows(parent, pos, pos);
                node->rows.removeAt(pos);
                deleteSubtree(potNode);
                endRemoveRows();

                node->rows[poIndex]->potRowNumber = potIndex;
                //This change does not need notification
                //dataChanged(index(poIndex, 0, parent), index(poIndex, ProjectModelColumnCount, parent));

                pos--;
            }
        }
    }

    enqueueNodeForMetadataUpdate(node);
}
Exemplo n.º 10
0
void ProjectModel::po_dataChanged(const QModelIndex& po_topLeft, const QModelIndex& po_bottomRight)
{
    //nothing special here
    //map from source and propagate
    QModelIndex topLeft = indexForPoIndex(po_topLeft);
    QModelIndex bottomRight = indexForPoIndex(po_bottomRight);

    emit dataChanged(topLeft, bottomRight);

    enqueueNodeForMetadataUpdate(nodeForIndex(topLeft.parent()));
}
Exemplo n.º 11
0
bool GSeqModel::insertRows( int row, int count, const QModelIndex & parent /*= QModelIndex()*/ )
{
	return false;
	beginInsertRows(parent, row, row+count);
	GEventNode *parentNode = nodeForIndex(parent);
	for(int i=0; i<count; i++) {
		new GEventNode(parentNode);
	}
	endInsertRows();
	return true;
}
Exemplo n.º 12
0
QModelIndex ProjectModel::index(int row, int column, const QModelIndex& parent) const
{
    ProjectNode* parentNode = nodeForIndex(parent);
    //kWarning()<<(sizeof(ProjectNode))<<nodeCounter;
    if (row>=parentNode->rows.size())
    {
        kWarning()<<"SHIT HAPPENED WITH INDEXES"<<row<<parentNode->rows.size()<<itemForIndex(parent).url();
        return QModelIndex();
    }
    return createIndex(row, column, parentNode->rows.at(row));
}
Exemplo n.º 13
0
bool FlatModel::canFetchMore(const QModelIndex & parent) const
{
    if (!parent.isValid()) {
        return false;
    } else {
        if (FolderNode *folderNode = nodeForIndex(parent)->asFolderNode())
            return !m_childNodes.contains(folderNode);
        else
            return false;
    }
}
Exemplo n.º 14
0
int FlatModel::rowCount(const QModelIndex &parent) const
{
    int rows = 0;
    if (!parent.isValid()) {
        rows = 1;
    } else {
        FolderNode *folderNode = nodeForIndex(parent)->asFolderNode();
        if (folderNode && m_childNodes.contains(folderNode))
            rows = m_childNodes.value(folderNode).size();
    }
    return rows;
}
Exemplo n.º 15
0
QModelIndex PuppyFileSystemModel::parent(const QModelIndex &child) const
{
    Node *childNode = nodeForIndex(child);
    Node *parentNode = childNode->parent;

    if(parentNode == m_rootNode) {
        return QModelIndex();
    }
    int row = rowForNode(parentNode);
    int column = 0;
    return createIndex(row, column, parentNode);
}
Exemplo n.º 16
0
QModelIndex GSeqModel::parent(const QModelIndex & child) const
{
	GEventNode* childNode = nodeForIndex(child);
	GEventNode* parentNode = childNode->ParentNode();

	if(parentNode == m_pSequence->RootTimeEvent()) {
		return QModelIndex();
	}

	int row = rowForNode(parentNode);
	int col = 0;
	return createIndex(row, col, parentNode);
}
Exemplo n.º 17
0
QModelIndex ProjectModel::parent(const QModelIndex& childIndex) const
{
    if (!childIndex.isValid())
        return QModelIndex();

    ProjectNode* childNode = nodeForIndex(childIndex);
    ProjectNode* parentNode = childNode->parent;

    if (!parentNode || (childNode == &m_rootNode) || (parentNode == &m_rootNode))
        return QModelIndex();

    return createIndex(parentNode->rowNumber, 0, parentNode);
}
Exemplo n.º 18
0
bool GSeqModel::setData( const QModelIndex & index, const QVariant & value, int role /*= Qt::EditRole*/ )
{
	if(!index.isValid() || role != Qt::EditRole) {
		return false;
	}
	GEventNode* childNode = nodeForIndex(index);
//	node->text = value.toString();
	qDebug() << index.column();
	qDebug() << value;
	QModelIndex topLeft = index;
	QModelIndex botRight = index;
	emit dataChanged(topLeft, botRight);
	return true;
}
Exemplo n.º 19
0
bool FlatModel::hasChildren(const QModelIndex &parent) const
{
    if (!parent.isValid())
        return true;

    FolderNode *folderNode = nodeForIndex(parent)->asFolderNode();
    if (!folderNode)
        return false;

    QHash<FolderNode*, QList<Node*> >::const_iterator it = m_childNodes.constFind(folderNode);
    if (it == m_childNodes.constEnd()) {
        fetchMore(folderNode);
        it = m_childNodes.constFind(folderNode);
    }
    return !it.value().isEmpty();
}
Exemplo n.º 20
0
bool FlatModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if (!index.isValid())
        return false;
    if (role != Qt::EditRole)
        return false;

    Node *node = nodeForIndex(index);

    Utils::FileName orgFilePath = node->filePath();
    Utils::FileName newFilePath = orgFilePath.parentDir().appendPath(value.toString());

    ProjectExplorerPlugin::renameFile(node, newFilePath.toString());
    emit renamed(orgFilePath, newFilePath);
    return true;
}
Exemplo n.º 21
0
QModelIndex CObjectInspectorTreeModel::index(int row, int column, const QModelIndex &parent) const
{
    if(!frootNode || row<0 || column<0 || column>=maxColumn || (parent.isValid() && parent.column()!=0))
        return  QModelIndex();

    TreeNode    *   parentNode = nodeForIndex(parent);
    Q_ASSERT(parentNode);
    if(TreeNode * item = dynamic_cast<TreeNode*>(parentNode->childAt(row)))
    {
        QModelIndex createdIndex = createIndex(row,column,item);
        item->setModelIndex(createdIndex);
        connect(item,SIGNAL(updateModel(QModelIndex,QModelIndex)),this,SIGNAL(dataChanged(QModelIndex,QModelIndex)));
        return  createdIndex;
    }
    return  QModelIndex();
}
Exemplo n.º 22
0
QMimeData* GSeqModel::mimeData( const QModelIndexList & indexes ) const
{
	QByteArray encodedData;
	QDataStream stream(&encodedData, QIODevice::WriteOnly);
	foreach(const QModelIndex & index, indexes) {
		if(index.isValid()) {
			GEventNode* node = nodeForIndex(index);
			if(index.column() == 0 && node) {
				QString text = node->UniqueSystemID();
				stream << text;
			}
			tempNodeMime = node;
		}
	}
	QMimeData* mimeData = new QMimeData();
	mimeData->setData("LabExe/EventNodes.list", encodedData);
	return mimeData;
}
Exemplo n.º 23
0
Qt::ItemFlags FlatModel::flags(const QModelIndex &index) const
{
    if (!index.isValid())
        return 0;
    // We claim that everything is editable
    // That's slightly wrong
    // We control the only view, and that one does the checks
    Qt::ItemFlags f = Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsDragEnabled;
    if (Node *node = nodeForIndex(index)) {
        if (node == m_rootNode)
            return 0; // no flags for session node...
        if (!node->asProjectNode()) {
            // either folder or file node
            if (node->supportedActions(node).contains(Rename))
                f = f | Qt::ItemIsEditable;
        }
    }
    return f;
}
Exemplo n.º 24
0
QModelIndex CObjectInspectorTreeModel::parent(const QModelIndex &child) const
{
    if(!child.isValid())
        return  QModelIndex();
    if(TreeNode * childNode = nodeForIndex(child))
    {
        if(TreeNode * parentNode = dynamic_cast<TreeNode*>(childNode->parent()))
        {
            if(parentNode == frootNode)
                return  QModelIndex();
            if(TreeNode * grandParentNode = dynamic_cast<TreeNode*>(parentNode->parent()))
            {
                int row = grandParentNode->childRow(parentNode);
                return  createIndex(row,0,parentNode);
            }
        }
    }
    return  QModelIndex();
}
Exemplo n.º 25
0
bool GSeqModel::removeRows( int row, int count, const QModelIndex & parent /*= QModelIndex()*/ )
{

	return false;


	GEventNode* parentNode = nodeForIndex(parent);
	const QList<GEventNode*> listEv = parentNode->ChildNodes();

	Q_ASSERT_X(row >= 0, "GSeqModel::removeRows", "row < 0");
	Q_ASSERT_X(row + count <= listEv.count(), "GSeqModel::removeRows", "row + count > list.count()");
	
	beginRemoveRows(parent, row, row+count);
	for(int i = 0; i < count; i++) {
		GEventNode* node = listEv.at(row);
		removeNode(node);
	}
	endRemoveRows();
	return true;
}
Exemplo n.º 26
0
QModelIndex ProjectModel::indexForPotIndex(const QModelIndex& potIndex) const
{
    if (!potIndex.isValid())
        return QModelIndex();

    QModelIndex outerParent = indexForPotIndex(potIndex.parent());
    ProjectNode* node = nodeForIndex(outerParent);

    int potRow = potIndex.row();
    int row = 0;

    while(row<node->rows.count() && node->rows.at(row)->potRowNumber!=potRow)
        row++;

    if (row != node->rows.count())
        return index(row, potIndex.column(), outerParent);

    kWarning()<<"error mapping index from POT to outer, searched for potRow:"<<potRow;
    return QModelIndex();
}
Exemplo n.º 27
0
QVariant GSeqModel::data(const QModelIndex &index, int role) const
{
	if (!index.isValid())
		return QVariant();

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

	GEventNode* node = nodeForIndex(index);

	switch(index.column()) {
		 case 0:
			 return node->UniqueSystemID();
		 case 1:
			 return node->data();//5555555
		 case 2:
			 return rowForNode(node);
		 default:
			 return QVariant();
	}
}
Exemplo n.º 28
0
/**
 * Theese methods map from project model indices to PO and POT model indices.
 * In each folder files form PO model comes first, and files from POT that do not exist in PO model come after.
 */
QModelIndex ProjectModel::indexForOuter(const QModelIndex& outerIndex, IndexType type) const
{
    if (!outerIndex.isValid())
        return QModelIndex();

    QModelIndex parent = outerIndex.parent();

    QModelIndex internalParent;
    if (parent.isValid())
    {
        internalParent = indexForOuter(parent, type);
        if (!internalParent.isValid())
            return QModelIndex();
    }

    ProjectNode* node = nodeForIndex(outerIndex);

    short rowNumber=(type==PoIndex?node->poRowNumber:node->potRowNumber);
    if (rowNumber == -1)
        return QModelIndex();
    return (type==PoIndex?m_poModel:m_potModel).index(rowNumber, outerIndex.column(), internalParent);
}
Exemplo n.º 29
0
bool NavigatorTreeModel::dropMimeData(const QMimeData *data,
                  Qt::DropAction action,
                  int row,
                  int column,
                  const QModelIndex &dropIndex)
{
    if (action == Qt::IgnoreAction)
        return true;
    if (action != Qt::LinkAction)
        return false;
    if (!data->hasFormat("application/vnd.modelnode.list"))
        return false;
    if (column > 1)
        return false;
    if (dropIndex.model() != this)
        return false;

    QModelIndex parentIndex, parentItemIndex;
    PropertyName parentPropertyName;
    int targetIndex;

    parentIndex = dropIndex.sibling(dropIndex.row(), 0);
    targetIndex = (row > -1)? row : rowCount(parentIndex);

    if (this->data(parentIndex, NavigatorRole).isValid()) {
        parentItemIndex = parentIndex;
        ModelNode parentNode = nodeForIndex(parentItemIndex);
        if (!parentNode.metaInfo().hasDefaultProperty())
            return false;
        targetIndex -= visibleProperties(parentNode).count();
        parentPropertyName = parentNode.metaInfo().defaultPropertyName();
    } else {
        parentItemIndex = parentIndex.parent();
        parentPropertyName = parentIndex.data(Qt::DisplayRole).toByteArray();
    }

    // Disallow dropping items between properties, which are listed first.
    if (targetIndex < 0)
        return false;

    Q_ASSERT(parentItemIndex.isValid());

    QByteArray encodedData = data->data("application/vnd.modelnode.list");
    QDataStream stream(&encodedData, QIODevice::ReadOnly);

    QList<ModelNode> nodeList;
    while (!stream.atEnd()) {
        uint nodeHash;
        stream >> nodeHash;
        if (containsNodeHash(nodeHash)) {
            ModelNode node(nodeForHash(nodeHash));
            nodeList.append(node);
        }
    }

    ModelNode parentNode(nodeForIndex(parentItemIndex));
    NodeAbstractProperty parentProperty = parentNode.nodeAbstractProperty(parentPropertyName);

    if (parentProperty.isNodeProperty() &&
        nodeList.count() > 1) {
        return false;
    }

    moveNodesInteractive(parentProperty, nodeList, targetIndex);
    propagateInvisible(parentNode, isNodeInvisible(parentNode));

    return false; // don't let the view do drag&drop on its own
}
Exemplo n.º 30
0
QVariant CObjectInspectorTreeModel::data(const QModelIndex &index, int role) const
{
    if(!frootNode || !index.isValid() || index.column()<0 || index.column()>=maxColumn)
        return  QVariant();

    TreeNode * node = nodeForIndex(index);

    if(node && node!=frootNode)
    {
        switch (role) {
        case Qt::DisplayRole:
        switch (index.column())
        {
            case    columnName:
                return  node->objectName();
            case    columnValue:
                return  node->stringValue();
            default:
                break;
        }
        break;
        case Qt::EditRole:
        {
            if(index.column()==columnValue)
            {
                PropertyTreeNode    *   propertyNode = qobject_cast<PropertyTreeNode*>(node);
                if(propertyNode)
                {
                    return  propertyNode->value();
                }
            }
        }
        break;
        case CObjectInspectorTreeModel::TreeNodeRole:
        switch (index.column())
        {
        case    columnValue:
            {
                PropertyTreeNode    *   propertyNode = qobject_cast<PropertyTreeNode*>(node);
                return  propertyNode?QVariant::fromValue(propertyNode):QVariant();
            }
        default:
            break;
        }
        break;
        case    Qt::BackgroundColorRole:
        {
            PropertyTreeNode    *   propertyNode = qobject_cast<PropertyTreeNode*>(node);
            return  colorByType(propertyNode->value().type());
        }
        case    Qt::ToolTipRole:
        {
            PropertyTreeNode    *   propertyNode = qobject_cast<PropertyTreeNode*>(node);
            if(propertyNode)
                return  QString(propertyNode->value().typeName());
        }
            break;
        default:
            break;
        }
    }

    return  QVariant();
}