Exemple #1
0
void medDatabaseView::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
    if (selected.count() == 0)
    {
        emit noPatientOrSeriesSelected();
        return;
    }

    // If we're already holding down CTRL or SHIFT, change behaviour to not open but rather just select, so we can select multiple elements
    Qt::KeyboardModifiers activeKeyboardModifiers = QApplication::keyboardModifiers();

    if (activeKeyboardModifiers & (Qt::ControlModifier | Qt::ShiftModifier))
    {
        QVector<medDataIndex> test;
        for (int i = 0; i < selected.size(); i++)
        {
            QModelIndex index = selected.indexes()[i];
            medAbstractDatabaseItem* item = getItemFromIndex(index);

            if (item)
                test.push_back(item->dataIndex());

        }
        emit multipleEntriesSelected(test);
        return;
    }
        
    // If we don't have the modifer keys pressed, expand the selected element.
    QModelIndex index = selected.indexes()[0];
    medAbstractDatabaseItem *item = getItemFromIndex(index);

    if (!item)
        return;

    if (item->dataIndex().isValidForSeries())
    {
        this->setExpanded(index.parent().parent(), true);
        this->setExpanded(index.parent(), true);
        this->setExpanded(index, true);
        emit seriesClicked(item->dataIndex());
    }
    else if (item->dataIndex().isValidForStudy())
    {
        this->setExpanded(index, true);
        emit studyClicked(item->dataIndex());
    }
    else if (item->dataIndex().isValidForPatient())
    {
        this->setExpanded(index, true);
        emit patientClicked(item->dataIndex());
    }

}
FrameData *CObjectModel::getFrameDataFromPrevFrame(QModelIndex index, int frame, bool bRepeat)
{
	if ( !isLayer(index) ) { return NULL ; }
	ObjectItem *p = getItemFromIndex(index) ;

	return getFrameDataFromPrevFrame(p, frame, bRepeat) ;
}
bool CObjectModel::isLayer(const QModelIndex &index) const
{
	if ( !index.isValid() ) { return false ; }
	ObjectItem *p = getItemFromIndex(index) ;
	return p->parent() == m_pRoot ? false : true ;
//	return index.parent().internalPointer() != m_pRoot ? true : false ;
}
QModelIndex CObjectModel::addItem(QString name, const QModelIndex &parent)
{
	ObjectItem *p = getItemFromIndex(parent) ;
	int row = p->childCount() ;

	return insertItem(row, name, parent) ;
}
FrameData *ObjectModel::getFrameDataFromNextFrame(QModelIndex index, int frame)
{
    if (!isLayer(index))
    {
        return NULL;
    }
    ObjectItem *p = getItemFromIndex(index);
    return getFrameDataFromNextFrame(p, frame);
}
bool CObjectModel::removeRows(int row, int count, const QModelIndex &parent)
{
	beginRemoveRows(parent, row, row+count-1) ;

	ObjectItem *p = getItemFromIndex(parent) ;
	p->removeChild(p->child(row)) ;

	endRemoveRows();
	return true ;
}
bool CObjectModel::insertRows(int row, int count, const QModelIndex &parent)
{
//	qDebug() << "insertRows " << row << count << parent ;
	beginInsertRows(parent, row, row+count-1) ;

	ObjectItem *p = getItemFromIndex(parent) ;
	p->insertChild(row, new ObjectItem(QString(), p)) ;

	endInsertRows();
	return true ;
}
bool CObjectModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	if ( role != Qt::DisplayRole && role != Qt::EditRole ) {
		return false ;
	}

	ObjectItem *p = getItemFromIndex(index) ;
	p->setName(value.toString()) ;
	emit dataChanged(index, index);
	return true ;
}
QModelIndex CObjectModel::index(int row, int column, const QModelIndex &parent) const
{
	if ( !hasIndex(row, column, parent) ) { return QModelIndex() ; }

	ObjectItem *p = getItemFromIndex(parent) ;

	ObjectItem *pChild = p->child(row) ;
	if ( pChild ) {
		return createIndex(row, column, pChild) ;
	}
	return QModelIndex() ;
}
int CObjectModel::getRow(QModelIndex index)
{
	ObjectItem *p = getItemFromIndex(index) ;
	int row = 0 ;
	return getRow(m_pRoot, p, &row) ;
}
int CObjectModel::rowCount(const QModelIndex &parent) const
{
	ObjectItem *p = getItemFromIndex(parent) ;
	return p->childCount() ;
}
QVariant CObjectModel::data(const QModelIndex &index, int role) const
{
	ObjectItem *p = getItemFromIndex(index) ;
	return p->data(role) ;
}