ZPunctum *ZPunctaObjsModel::getPunctum(const QModelIndex &index) const
{
  if (!index.isValid())
    return NULL;

  ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());

  if (item->parent() && item->parent()->parent() == m_rootItem)
    return static_cast<ZPunctum*>(item->getObj());
  else
    return NULL;
}
Exemple #2
0
Swc_Tree_Node *ZSwcNodeObjsModel::getSwcTreeNode(const QModelIndex &index) const
{
  if (!index.isValid())
    return NULL;

  ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());

  if (item->parent() && item->parent()->parent() == m_rootItem)
    return static_cast<Swc_Tree_Node*>(item->getActuralData());
  else
    return NULL;
}
Exemple #3
0
QModelIndex ZObjsModel::parent(const QModelIndex &index) const
{
  if (!index.isValid())
    return QModelIndex();

  ZObjsItem *childItem = static_cast<ZObjsItem*>(index.internalPointer());
  ZObjsItem *parentItem = childItem->parent();

  if (parentItem == m_rootItem)
    return QModelIndex();

  return createIndex(parentItem->row(), 0, parentItem);
}
Exemple #4
0
ZStroke2d* ZStroke2dObjsModel::getStroke2d(const QModelIndex &index) const
{
  ZStroke2d *stroke = NULL;
  if (index.isValid()) {
    ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());

    if (item->parent() == m_rootItem) {
      stroke = ZStackObject::CastVoidPointer<ZStroke2d>(item->getActuralData());
    }
  }

  return stroke;
}
Exemple #5
0
int ZObjsModel::rowCount(const QModelIndex &parent) const
{
  ZObjsItem *parentItem;
  if (parent.column() > 0)
    return 0;

  if (!parent.isValid()) {
    parentItem = m_rootItem;
    return parentItem->childCount();
  } else {
    parentItem = static_cast<ZObjsItem*>(parent.internalPointer());
    return parentItem->childCount();
  }
}
void ZPunctaObjsModel::updateData(ZPunctum *punctum)
{
  QModelIndex index = getIndex(punctum);
  if (!index.isValid())
    return;
  ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());
  QList<QVariant> &data = item->getItemData();
  ZPunctum *p = punctum;
  QList<QVariant>::iterator beginit = data.begin();
  beginit++;
  data.erase(beginit, data.end());
  data << p->score() << p->name() << p->comment() << p->x() << p->y() <<
          p->z() << p->sDevOfIntensity() << p->volSize() << p->mass() << p->radius() <<
          p->meanIntensity() << p->maxIntensity() << p->property1() << p->property2() <<
          p->property3() << p->color() << p->source();
  emit dataChanged(index, getIndex(punctum, item->parent()->columnCount()-1));
}
Exemple #7
0
QVariant ZObjsModel::data(const QModelIndex &index, int role) const
{
  if (!index.isValid())
    return QVariant();

  ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());

  if (role == Qt::CheckStateRole && index.column() == 0 && needCheckbox(index))
    return item->checkState();

  if (role == Qt::ToolTipRole && !item->toolTip().isEmpty())
    return item->toolTip();

  if (role == Qt::DisplayRole)
    return item->data(index.column());

  return QVariant();
}
const std::vector<ZPunctum *> *ZPunctaObjsModel::getPuncta(const QModelIndex &index) const
{
  if (!index.isValid())
    return NULL;

  ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());

  if (item->parent() == m_rootItem) {
    std::map<ZObjsItem*, int>::const_iterator it;
    it = m_punctaSourceParentToRow.find(item);
    if (it == m_punctaSourceParentToRow.end()) {
      LERROR() << "Wrong Index";
    } else
      return &(m_punctaSeparatedByFile[it->second]);
  }

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

  ZObjsItem *parentItem;

  if (!parent.isValid())
    parentItem = m_rootItem;
  else
    parentItem = static_cast<ZObjsItem*>(parent.internalPointer());

  ZObjsItem *childItem = parentItem->child(row);
  if (childItem)
    return createIndex(row, column, childItem);
  else
    return QModelIndex();
}
Exemple #10
0
std::set<Swc_Tree_Node*> ZSwcNodeObjsModel::getSwcTreeNodeSet(
    const QModelIndex &index) const
{
  std::set<Swc_Tree_Node*> nodeSet;
  if (index.isValid()) {
    ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());
    if (item->parent() == m_rootItem) {
      int childNumber = item->childCount();
      for (int i = 0; i < childNumber; ++i) {
        ZObjsItem *childItem = item->child(i);
        Swc_Tree_Node *tn = static_cast<Swc_Tree_Node*>(childItem->getActuralData());
        if (tn != NULL) {
          nodeSet.insert(tn);
        }
      }
    } else {
      Swc_Tree_Node *tn = getSwcTreeNode(index);
      if (tn != NULL) {
        nodeSet.insert(tn);
      }
    }
  }

  return nodeSet;
}
Exemple #11
0
void ZSwcNodeObjsModel::setupModelData(ZObjsItem *parent)
{
  QList<QVariant> data;

  m_typeToRow.clear();
  m_swcTreeNodeToRow.clear();
  m_swcTreeNodeToType.clear();

  m_typeToRow[SwcTreeNode::TERMINAL] = 0;
  m_typeToRow[SwcTreeNode::BRANCH_POINT] = 1;

  data.clear();
  data << "Termini" << "id" << "type" << "radius" << "x" << "y" << "z"
       << "label";
  ZObjsItem *terminalItem = new ZObjsItem(data, NULL, parent);
  terminalItem->setCheckState(Qt::Checked);
  parent->appendChild(terminalItem);

  data.clear();
  data << "Branch Points" << "id" << "type" << "radius" << "x" << "y" << "z"
       << "label";
  ZObjsItem *branchPointItem = new ZObjsItem(data, NULL, parent);
  branchPointItem->setCheckState(Qt::Checked);
  parent->appendChild(branchPointItem);

  int terminalRow = 0;
  int branchPointRow = 0;

  QList<ZSwcTree*> swcList = m_doc->getSwcList();
  for (int i=0; i<swcList.size(); i++) {
    data.clear();
    ZSwcTree *swcTree = swcList.at(i);

    //ZObjsItem *nodeParent = new ZObjsItem(data, swcTree, parent);
    //nodeParent->setCheckState(swcTree->isVisible() ? Qt::Checked : Qt::Unchecked);
    //nodeParent->setToolTip(QString("source: %1").arg(QString::fromStdString(swcTree->source())));
    //parent->appendChild(nodeParent);

    swcTree->updateIterator(SWC_TREE_ITERATOR_DEPTH_FIRST);   //depth first
    for (Swc_Tree_Node *tn = swcTree->begin(); tn != swcTree->end(); tn = swcTree->next()) {
      if (!SwcTreeNode::isVirtual(tn)) {
        data.clear();
        data << "" << tn->node.id << tn->node.type << tn->node.d << tn->node.x
             << tn->node.y << tn->node.z  << tn->node.label << "";
        if (SwcTreeNode::isBranchPoint(tn)) {
          m_swcTreeNodeToType[tn] = SwcTreeNode::BRANCH_POINT;
          m_swcTreeNodeToRow[tn] = branchPointRow++;
          ZObjsItem *node = new ZObjsItem(data, tn, branchPointItem);
          branchPointItem->appendChild(node);
        } else if (SwcTreeNode::isRoot(tn) || SwcTreeNode::isLeaf(tn)) {
          m_swcTreeNodeToType[tn] = SwcTreeNode::TERMINAL;
          m_swcTreeNodeToRow[tn] = terminalRow++;
          ZObjsItem *node = new ZObjsItem(data, tn, terminalItem);
          terminalItem->appendChild(node);
        }
      }
    }
  }
}
Exemple #12
0
void ZObjsModel::setModelIndexCheckState(const QModelIndex &index, Qt::CheckState cs)
{
  ZObjsItem *item = static_cast<ZObjsItem*>(index.internalPointer());
  item->setCheckState(cs);
  emit dataChanged(index, index);
}
void ZPunctaObjsModel::setupModelData(ZObjsItem *parent)
{
  QList<QVariant> data;

  m_punctaSourceToParent.clear();
  m_punctaSourceToCount.clear();
  m_punctaToRow.clear();
  m_punctaSourceParentToRow.clear();
  m_punctaSeparatedByFile.clear();
  int sourceParentRow = 0;
  int numDigit = numDigits(m_doc->punctaList()->size()+1);
  for (int i=0; i<m_doc->punctaList()->size(); i++) {
    data.clear();
    ZPunctum *p = m_doc->punctaList()->at(i);
    QFileInfo sourceInfo(p->source());
    if (m_punctaSourceToParent.find(p->source()) != m_punctaSourceToParent.end()) {
      ZObjsItem *sourceParent = m_punctaSourceToParent[p->source()];
      data << QString("puncta %1").arg(m_punctaSourceToCount[p->source()] + 1, numDigit, 10, QLatin1Char('0')) << p->score() << p->name() << p->comment() << p->x() << p->y() <<
              p->z() << p->sDevOfIntensity() << p->volSize() << p->mass() << p->radius() <<
              p->meanIntensity() << p->maxIntensity() << p->property1() << p->property2() <<
              p->property3() << p->color() << sourceInfo.fileName();
      m_punctaToRow[p] = m_punctaSourceToCount[p->source()];
      m_punctaSourceToCount[p->source()]++;
      ZObjsItem *punctum = new ZObjsItem(data, p, sourceParent);
      punctum->setCheckState(p->isVisible() ? Qt::Checked : Qt::Unchecked);
      punctum->setToolTip(QString("puncta from: %1").arg(p->source()));
      sourceParent->appendChild(punctum);
      m_punctaSeparatedByFile[m_punctaSourceParentToRow[sourceParent]].push_back(m_doc->punctaList()->at(i));
    } else {
      data << sourceInfo.fileName() << "score" << "name" << "comment" << "x" << "y" << "z" << "sDev" <<
              "volSize" << "mass" << "radius" << "meanIntensity" << "maxIntensity" <<
              "property1" << "property2" << "property3" << "color" << "source";
      m_punctaSeparatedByFile.push_back(std::vector<ZPunctum*>());
      ZObjsItem *sourceParent = new ZObjsItem(data, NULL, parent);
      sourceParent->setToolTip(QString("puncta source: %1").arg(p->source()));
      m_punctaSourceToParent[p->source()] = sourceParent;
      m_punctaSourceToCount[p->source()] = 0;
      parent->appendChild(sourceParent);
      m_punctaSourceParentToRow[sourceParent] = sourceParentRow++;

      data.clear();
      data << QString("puncta %1").arg(m_punctaSourceToCount[p->source()] + 1, numDigit, 10, QLatin1Char('0')) << p->score() << p->name() << p->comment() << p->x() << p->y() <<
              p->z() << p->sDevOfIntensity() << p->volSize() << p->mass() << p->radius() <<
              p->meanIntensity() << p->maxIntensity() << p->property1() << p->property2() <<
              p->property3() << p->color() << sourceInfo.fileName();
      m_punctaToRow[p] = m_punctaSourceToCount[p->source()];
      m_punctaSourceToCount[p->source()]++;
      ZObjsItem *punctum = new ZObjsItem(data, p, sourceParent);
      punctum->setCheckState(p->isVisible() ? Qt::Checked : Qt::Unchecked);
      punctum->setToolTip(QString("puncta from: %1").arg(p->source()));
      sourceParent->appendChild(punctum);
      m_punctaSeparatedByFile[m_punctaSourceParentToRow[sourceParent]].push_back(m_doc->punctaList()->at(i));
    }
  }
}