| 147 | updateEnabledTools(project_model_->getSelectionModel()->selection()); |
| 148 | } |
| 149 | void |
| 150 | pcl::cloud_composer::ToolBoxModel::updateEnabledTools( |
| 151 | const QItemSelection& current_selection) |
| 152 | { |
| 153 | // qDebug () << "UPDATING ENABLED TOOLS!"; |
| 154 | QModelIndexList current_indices = current_selection.indexes(); |
| 155 | QMultiMap<int, QStandardItem*> type_items_map; |
| 156 | foreach (QModelIndex current, current_indices) { |
| 157 | if (current.isValid()) { |
| 158 | QStandardItem* current_item = project_model_->itemFromIndex(current); |
| 159 | type_items_map.insert(current_item->type(), current_item); |
| 160 | } |
| 161 | } |
| 162 | enableAllTools(); |
| 163 | QList<QStandardItem*> enabled_tools = tool_items.values(); |
| 164 | QMap<QStandardItem*, QString> disabled_tools; |
| 165 | QMutableListIterator<QStandardItem*> enabled_itr(enabled_tools); |
| 166 | // Go through tools, removing from enabled list if they fail to pass tests |
| 167 | while (enabled_itr.hasNext()) { |
| 168 | QStandardItem* tool_item = enabled_itr.next(); |
| 169 | ToolFactory* tool_factory = (tool_item->data(FACTORY)).value<ToolFactory*>(); |
| 170 | CloudComposerItem::ItemType input_type = tool_factory->getInputItemType(); |
| 171 | QList<CloudComposerItem::ItemType> required_children_types = |
| 172 | tool_factory->getRequiredInputChildrenTypes(); |
| 173 | // Check if enough items for tool are selected |
| 174 | if (tool_factory->getNumInputItems() > current_indices.size()) { |
| 175 | enabled_itr.remove(); |
| 176 | disabled_tools.insert(tool_item, |
| 177 | tr("Tool Requires %1 Items (%2 Selected)") |
| 178 | .arg(tool_factory->getNumInputItems()) |
| 179 | .arg(current_indices.size())); |
| 180 | } |
| 181 | // Check if selection includes at least one item with correct input type |
| 182 | else if (!type_items_map.keys().contains(input_type)) { |
| 183 | enabled_itr.remove(); |
| 184 | disabled_tools.insert( |
| 185 | tool_item, |
| 186 | tr("Tool Requires item type %1 selected") |
| 187 | .arg(ITEM_TYPES_STRINGS.value(input_type - |
| 188 | CloudComposerItem::CLOUD_COMPOSER_ITEM))); |
| 189 | } |
| 190 | // Check if any of selected items have required children |
| 191 | else if (!required_children_types.empty()) { |
| 192 | QList<QStandardItem*> matching_selected_items = type_items_map.values(input_type); |
| 193 | bool found_valid_items = false; |
| 194 | QList<CloudComposerItem::ItemType> missing_children = required_children_types; |
| 195 | foreach (QStandardItem* item, matching_selected_items) { |
| 196 | QList<CloudComposerItem::ItemType> found_children_types; |
| 197 | if (!item->hasChildren()) |
| 198 | continue; |
| 199 | |
| 200 | // Find types of all children |
| 201 | for (int i = 0; i < item->rowCount(); ++i) |
| 202 | found_children_types.append( |
| 203 | static_cast<CloudComposerItem::ItemType>(item->child(i)->type())); |
| 204 | // Make temporary copy, remove type from it if is present as child |
| 205 | QList<CloudComposerItem::ItemType> req_children_temp = required_children_types; |
| 206 | foreach (CloudComposerItem::ItemType type, found_children_types) |
nothing calls this directly
no test coverage detected