QWidget* medDatabaseDataSource::mainViewWidget() { if(d->mainWidget.isNull()) { d->mainWidget = new QWidget; d->largeView = new medDatabaseView(d->mainWidget); d->largeView->setModel(d->proxy); QVBoxLayout *database_layout = new QVBoxLayout(d->mainWidget); database_layout->setContentsMargins(0, 0, 0, 0); database_layout->setSpacing(0); database_layout->addWidget(d->largeView); connect(d->largeView, SIGNAL(open(const medDataIndex&)), this, SIGNAL(open(const medDataIndex&))); connect(d->largeView, SIGNAL(exportData(const medDataIndex&)), this, SIGNAL(exportData(const medDataIndex&))); connect(d->largeView, SIGNAL(dataRemoved(const medDataIndex&)), this, SIGNAL(dataRemoved(const medDataIndex&))); if(!d->toolBoxes.isEmpty()) { connect(d->actionsToolBox, SIGNAL(removeClicked()), d->largeView, SLOT(onRemoveSelectedItemRequested())); connect(d->actionsToolBox, SIGNAL(exportClicked()), d->largeView, SLOT(onExportSelectedItemRequested())); connect(d->actionsToolBox, SIGNAL(viewClicked()), d->largeView, SLOT(onViewSelectedItemRequested())); connect(d->actionsToolBox, SIGNAL(saveClicked()), d->largeView, SLOT(onSaveSelectedItemRequested())); connect(d->actionsToolBox, SIGNAL(newPatientClicked()), d->largeView, SLOT(onCreatePatientRequested())); connect(d->actionsToolBox, SIGNAL(newStudyClicked()), d->largeView, SLOT(onCreateStudyRequested())); connect(d->actionsToolBox, SIGNAL(editClicked()), d->largeView, SLOT(onEditRequested())); connect(d->largeView, SIGNAL(patientClicked(const medDataIndex&)), d->actionsToolBox, SLOT(patientSelected(const medDataIndex&))); connect(d->largeView, SIGNAL(seriesClicked(const medDataIndex&)), d->actionsToolBox, SLOT(seriesSelected(const medDataIndex&))); connect(d->largeView, SIGNAL(noPatientOrSeriesSelected()), d->actionsToolBox, SLOT(noPatientOrSeriesSelected())); connect(d->largeView, SIGNAL(multipleEntriesSelected(const QVector<medDataIndex>&)), d->actionsToolBox, SLOT(multipleEntriesSelected(const QVector<medDataIndex>&))); }
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()); } }