16,225
社区成员
发帖
与我相关
我的任务
分享
QModelIndex CTreeModeBase::index(int row, int column, const QModelIndex &parent) const
{
if (TRUE == this->hasIndex(row, column, parent))
{
if (FALSE == parent.isValid())
{
CTreemodelNode* lpItem = m_lpTreeRoot->GetInfoByRow(row);
return this->createIndex(row, column, lpItem);
}
CTreemodelNode* lpItem = static_cast<CTreemodelNode*>(parent.internalPointer());
if (NULL != lpItem)
{
CTreemodelNode* lpSubItem = lpItem->GetChildByIndex(row);
return this->createIndex(row, column, lpSubItem);
}
}
return QModelIndex();
}
QModelIndex CTreeModeBase::parent(const QModelIndex &index) const
{
if (TRUE == index.isValid())
{
CTreemodelNode* lpchildItem = static_cast<CTreemodelNode*>(index.internalPointer());
CTreemodelNode* lpparentItem = lpchildItem->GetParent();
if (NULL != lpparentItem)
{
return this->createIndex(0, 0, lpparentItem);
}
}
return QModelIndex();
}
m_lpTreeMember = new QTreeView(this);
m_lpTreeMember->setEditTriggers(QAbstractItemView::SelectedClicked);
m_lpParamProxyModel = new QSortFilterProxyModel;
m_lpParamProxyModel->setDynamicSortFilter(true);
m_lpTreeMember->setModel(m_lpParamProxyModel);
QStringList strHeaderList;
strHeaderList << tr("type") << tr("name");
m_lpTreeModel = new CTreeModeBase(strHeaderList, m_lpTreeMember);
m_lpParamProxyModel->setSourceModel(m_lpTreeModel);
m_lpTreeModel->SetRootInfo(m_lpRoot);
m_lpTestDelegate = new CTestDelegate(m_lpTreeMember);
m_lpTreeMember->setItemDelegate(m_lpTestDelegate);
m_lpTreeMember->show();
QWidget* CTestDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (0 == index.column())
{
CTreemodelNode* lpItem = static_cast<CTreemodelNode*>(index.internalPointer());
if (PARAM_NAME_TYPE == lpItem->GetNodeType())
{
CDataEdit* lpEditor = new CDataEdit(parent);
return lpEditor;
}
else if (ATTACH_NAME_TYPE == lpItem->GetNodeType())
{
return NULL;
}
}
return new QLineEdit(parent);
}