/**
 * @brief ProjectManagerTreeModel::shaderRemoved Call this method when shader was removed.
 * @param name Name of the removed shader.
 */
void ProjectManagerTreeModel::shaderRemoved(QString name, MetaShader::SHADERTYPE type)
{
    ProjectTreeItem* item;

    MetaProject* proj = dynamic_cast<MetaProject*>(sender());

    if(proj == NULL)
        return;

    //convert path to -> projectName '/' path
    QString projName = proj->getName();
    name.insert(0,projName + '/');

    if(type == MetaShader::FRAGMENT)
        //item = root->findLastCreated(name.split(QDir::separator()),ProjectTreeItem::FRAGMENT);
        item = root->findLastCreated(name.split('/'),ProjectTreeItem::FRAGMENT);
    else
        //item = root->findLastCreated(name.split(QDir::separator()),ProjectTreeItem::VERTEX);
        item = root->findLastCreated(name.split('/'),ProjectTreeItem::VERTEX);


    ProjectTreeItem* candidate = item->getRemoveCandidate();

    int row = candidate->getRow();
    insertData = name;
    insertType = ProjectTreeItem::SHADER;

    QModelIndex index = createIndex(candidate->getParent()->getRow(), 0, candidate->getParent());
    removeRows(row,1,index);



    emit dataChanged(index,index);
}
/**
 * @brief ProjectManagerTreeModel::parent Get parent of item with index.
 * @param child Child where we want get parent item.
 * @return Parent of given child.
 */
QModelIndex ProjectManagerTreeModel::parent(const QModelIndex &child) const
{
    if(!child.isValid())
        return QModelIndex();

    ProjectTreeItem* cItem = static_cast<ProjectTreeItem*>(child.internalPointer());
    ProjectTreeItem* pItem = cItem->getParent();

    if(pItem == root)
        return QModelIndex();

    return createIndex(pItem->getRow(), 0, pItem);
}