示例#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());
    }

}
void medDatabaseView::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
    if (selected.count() == 0)
    {
        emit noPatientOrSeriesSelected();
        return;
    }
        
    // so far we only allow single selection
    QModelIndex index = selected.indexes()[0];

    medAbstractDatabaseItem *item = NULL;

    if(QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(this->model()))
        item = static_cast<medAbstractDatabaseItem *>(proxy->mapToSource(index).internalPointer());
    else if (dynamic_cast<QAbstractItemModel *>(this->model()))
        item = static_cast<medAbstractDatabaseItem *>(index.internalPointer());

    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());
    }
}