/// // Reset to default widget state // void ProjectChooser::resetAll() { WAbstractItemModel *model = mProjectSelectionBox->model(); mProjectSelectionBox->clear(); mProjectSelectionBox->addItem("Default (All MRIDs)"); model->setData(model->index(0, 0), boost::any(std::string("")), UserRole); mProjectSelectionBox->setCurrentIndex(0); mDeleteButton->setEnabled(false); std::string userProjectDir = getConfigOptionsPtr()->GetProjectDir() + "/" + getCurrentUserName(); try { for(directory_iterator dirIter(userProjectDir); dirIter != directory_iterator(); ++dirIter) { const string extension = dirIter->path().extension().string(); if (extension == ".xml") { mProjectSelectionBox->addItem(dirIter->path().string()); } } } catch(...) { // Empty directory, which is fine } }
void WAbstractItemModel::dropEvent(const WDropEvent& e, DropAction action, int row, int column, const WModelIndex& parent) { // TODO: For now, we assumes selectionBehavior() == RowSelection ! WItemSelectionModel *selectionModel = dynamic_cast<WItemSelectionModel *>(e.source()); if (selectionModel) { WAbstractItemModel *sourceModel = selectionModel->model(); /* * (1) Insert new rows (or later: cells ?) */ if (action == MoveAction || row == -1) { if (row == -1) row = rowCount(parent); insertRows(row, selectionModel->selectedIndexes().size(), parent); } /* * (2) Copy data */ WModelIndexSet selection = selectionModel->selectedIndexes(); int r = row; for (WModelIndexSet::const_iterator i = selection.begin(); i != selection.end(); ++i) { WModelIndex sourceIndex = *i; if (selectionModel->selectionBehavior() == SelectRows) { WModelIndex sourceParent = sourceIndex.parent(); for (int col = 0; col < sourceModel->columnCount(sourceParent); ++col) { WModelIndex s = sourceModel->index(sourceIndex.row(), col, sourceParent); WModelIndex d = index(r, col, parent); copyData(sourceModel, s, this, d); } ++r; } else { } } /* * (3) Remove original data */ if (action == MoveAction) { while (!selectionModel->selectedIndexes().empty()) { WModelIndex i = Utils::last(selectionModel->selectedIndexes()); sourceModel->removeRow(i.row(), i.parent()); } } } }
/// // Load button clicked [slot] // void ProjectChooser::loadClicked() { if (mProjectSelectionBox->currentIndex() < 0) return; WAbstractItemModel *model = mProjectSelectionBox->model(); boost::any userData = model->data(model->index(mProjectSelectionBox->currentIndex(), 0), DisplayRole); std::string result; if (!userData.empty()) { result = boost::any_cast<WString>(userData).toUTF8(); } mProjectChosen.emit(result); }