void InspectorPanel::newItemsInspected(const Selection& objects) { // Ignore items in both // Create items in objects and not in current // Delete items in current and not in objects Selection toCreate, toDelete; std::set_difference(objects.begin(), objects.end(), m_currentSel.begin(), m_currentSel.end(), std::inserter(toCreate, toCreate.begin())); std::set_difference(m_currentSel.begin(), m_currentSel.end(), objects.begin(), objects.end(), std::inserter(toDelete, toDelete.begin())); for(const auto& object : toDelete) { auto widget_it = m_map.get<0>().find(object); if(widget_it != m_map.get<0>().end()) { (*widget_it)->deleteLater(); *m_map.get<0>().erase(widget_it); } } for(const auto& object : toCreate) { auto widget = InspectorWidgetList::makeInspectorWidget(object->objectName(), object, m_tabWidget); m_tabWidget->addTab(widget, widget->tabName()); m_map.insert(widget); } m_currentSel = objects; }
void TerrainImpl::avgFlatten(const Selection& selection, float intensity) { // add by 王宏张 2007-7-25 // 计算平均高度 float avgHeiht = 0.0f; for(Selection::const_iterator iter = selection.begin() ; iter != selection.end() ; ++iter) { if(size_t(iter->first.getX() + selection.getPosition().getX()) >= mInfo->getWidth() || size_t(iter->first.getY() + selection.getPosition().getY()) >= mInfo->getHeight()) continue; float height = mInfo->at(size_t(iter->first.getX() + selection.getPosition().getX()) , size_t(iter->first.getY() + selection.getPosition().getY())); avgHeiht += height; } avgHeiht /= selection.size(); for(Selection::const_iterator iter = selection.begin() ; iter != selection.end() ; ++iter) { if(size_t(iter->first.getX() + selection.getPosition().getX()) >= mInfo->getWidth() || size_t(iter->first.getY() + selection.getPosition().getY()) >= mInfo->getHeight()) continue; float& height = mInfo->at(size_t(iter->first.getX() + selection.getPosition().getX()) , size_t(iter->first.getY() + selection.getPosition().getY())); height = avgHeiht; // avgFlatten算法 } updateTiles(selection.getMin().getX(), selection.getMin().getY(), selection.getMax().getX(), selection.getMax().getY()); }
void DisplayedElementsModel::setSelection(const Selection & s) { m_startEvent->selection.set(s.find(m_startEvent) != s.end()); m_endEvent->selection.set(s.find(m_endEvent) != s.end()); m_startState->selection.set(s.find(m_startState) != s.end()); m_endState->selection.set(s.find(m_endState) != s.end()); m_constraint->selection.set(s.find(m_constraint) != s.end()); }
static void writeSelection(QTextStream &ts, const RenderObject *o) { NodeImpl *n = o->element(); if (!n || !n->isDocumentNode()) return; DocumentImpl *doc = static_cast<DocumentImpl *>(n); if (!doc->part()) return; Selection selection = doc->part()->selection(); if (selection.isNone()) return; if (!selection.start().node()->isContentEditable() || !selection.end().node()->isContentEditable()) return; Position startPosition = selection.start(); Position endPosition = selection.end(); QString startNodeTagName(getTagName(startPosition.node())); QString endNodeTagName(getTagName(endPosition.node())); NodeImpl *rootNode = doc->getElementById("root"); if (selection.isCaret()) { Position upstream = startPosition.upstream(DOM::StayInBlock); Position downstream = startPosition.downstream(DOM::StayInBlock); QString positionString = nodePositionRelativeToRoot(startPosition.node(), rootNode); QString upstreamString = nodePositionRelativeToRoot(upstream.node(), rootNode); QString downstreamString = nodePositionRelativeToRoot(downstream.node(), rootNode); ts << "selection is CARET:\n" << "start: position " << startPosition.offset() << " of " << positionString << "\n" "upstream: position " << upstream.offset() << " of " << upstreamString << "\n" "downstream: position " << downstream.offset() << " of " << downstreamString << "\n"; } else if (selection.isRange()) { QString startString = nodePositionRelativeToRoot(startPosition.node(), rootNode); Position upstreamStart = startPosition.upstream(DOM::StayInBlock); QString upstreamStartString = nodePositionRelativeToRoot(upstreamStart.node(), rootNode); Position downstreamStart = startPosition.downstream(DOM::StayInBlock); QString downstreamStartString = nodePositionRelativeToRoot(downstreamStart.node(), rootNode); QString endString = nodePositionRelativeToRoot(endPosition.node(), rootNode); Position upstreamEnd = endPosition.upstream(DOM::StayInBlock); QString upstreamEndString = nodePositionRelativeToRoot(upstreamEnd.node(), rootNode); Position downstreamEnd = endPosition.downstream(DOM::StayInBlock); QString downstreamEndString = nodePositionRelativeToRoot(downstreamEnd.node(), rootNode); ts << "selection is RANGE:\n" << "start: position " << startPosition.offset() << " of " << startString << "\n" << "upstream: position " << upstreamStart.offset() << " of " << upstreamStartString << "\n" "downstream: position " << downstreamStart.offset() << " of " << downstreamStartString << "\n" "end: position " << endPosition.offset() << " of " << endString << "\n" "upstream: position " << upstreamEnd.offset() << " of " << upstreamEndString << "\n" "downstream: position " << downstreamEnd.offset() << " of " << downstreamEndString << "\n"; } }
void ScenarioModel::setSelection(const Selection& s) const { // TODO optimize if possible? for(auto& elt : m_constraints) elt->selection.set(s.find(elt) != s.end()); for(auto& elt : m_events) elt->selection.set(s.find(elt) != s.end()); for(auto& elt : m_timeNodes) elt->selection.set(s.find(elt) != s.end()); for(auto& elt : m_states) elt->selection.set(s.find(elt) != s.end()); }
void MoveSelectionCommand::doApply() { Selection selection = endingSelection(); ASSERT(selection.isRange()); Position pos = m_position; if (pos.isNull()) return; // Update the position otherwise it may become invalid after the selection is deleted. Node *positionNode = m_position.node(); int positionOffset = m_position.offset(); Position selectionEnd = selection.end(); int selectionEndOffset = selectionEnd.offset(); if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) { positionOffset -= selectionEndOffset; Position selectionStart = selection.start(); if (selectionStart.node() == positionNode) { positionOffset += selectionStart.offset(); } pos = Position(positionNode, positionOffset); } deleteSelection(m_smartMove); // If the node for the destination has been removed as a result of the deletion, // set the destination to the ending point after the deletion. // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelectionCommand; // selection is empty, leading to null deref if (!pos.node()->inDocument()) pos = endingSelection().start(); setEndingSelection(Selection(pos, endingSelection().affinity())); applyCommandToComposite(ReplaceSelectionCommand::create(positionNode->document(), m_fragment, true, m_smartMove)); }
void PropertyTreeModel::setSelection(const Selection& selection) { deselectAll(); Selection::const_iterator it; for(it = selection.begin(); it != selection.end(); ++it){ const TreePath& path = *it; PropertyRow* row = rowFromPath(path); if(row) selectRow(row, true, false); } }
void BaseGrid::AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) { if (batch_level > 0) { // Remove all previously added lines that are now removed Selection temp; set_difference(batch_selection_added, lines_removed, temp); std::swap(temp, batch_selection_added); temp.clear(); // Remove all previously removed lines that are now added set_difference(batch_selection_removed, lines_added, temp); std::swap(temp, batch_selection_removed); // Add new stuff to batch sets batch_selection_added.insert(lines_added.begin(), lines_added.end()); batch_selection_removed.insert(lines_removed.begin(), lines_removed.end()); } else { SubtitleSelectionController::AnnounceSelectedSetChanged(lines_added, lines_removed); } }
void TerrainImpl::deform(const Selection& selection, float intensity) { for(Selection::const_iterator iter = selection.begin() ; iter != selection.end() ; iter ++) { if(size_t(iter->first.getX() + selection.getPosition().getX()) >= mInfo->getWidth() || size_t(iter->first.getY() + selection.getPosition().getY()) >= mInfo->getHeight()) continue; float& height = mInfo->at(size_t(iter->first.getX() + selection.getPosition().getX()) , size_t(iter->first.getY() + selection.getPosition().getY())); height += intensity * iter->second; } updateTiles(selection.getMin().getX(), selection.getMin().getY(), selection.getMax().getX(), selection.getMax().getY()); }
void TFCompositeModifier::updateComposition_(){ Selection selection = manager_.getComposition(); clearLayout_(); bool recalculate = false; M4D::Common::TimeStamp lastChange; Editor* editor; Composition newComposition; Composition::iterator found; for(Selection::iterator it = selection.begin(); it != selection.end(); ++it) { found = composition_.find(*it); if(found == composition_.end()) { editor = new Editor(editors_.find(*it)->second); newComposition.insert(std::make_pair<TF::Size, Editor*>( *it, editor) ); recalculate = true; } else { lastChange = found->second->editor->lastChange(); if(found->second->change != lastChange) { recalculate = true; found->second->change = lastChange; } editor = found->second; editor->updateName(); newComposition.insert(*found); composition_.erase(found); } layout_->addWidget(editor->name); } layout_->addItem(pushUpSpacer_); if(!composition_.empty()) recalculate = true; for(Composition::iterator it = composition_.begin(); it != composition_.end(); ++it) { layout_->removeWidget(it->second->name); delete it->second; } composition_.swap(newComposition); if(recalculate) computeResultFunction_(); }
/// @brief Retrieve a list of selected lines in the actual ASS file (ie. not as displayed in the grid but as represented in the file) /// @return /// std::vector<int> SubtitlesGrid::GetAbsoluteSelection() const { Selection sel = GetSelectedSet(); std::vector<int> result; result.reserve(sel.size()); int line_index = 0; for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it, ++line_index) { if (sel.find(dynamic_cast<AssDialogue*>(*it)) != sel.end()) result.push_back(line_index); } return result; }
// This needs to be static so it can be called by canIncreaseSelectionListLevel and canDecreaseSelectionListLevel static bool getStartEndListChildren(const Selection& selection, Node*& start, Node*& end) { if (selection.isNone()) return false; // start must be in a list child Node* startListChild = enclosingListChild(selection.start().node()); if (!startListChild) return false; // end must be in a list child Node* endListChild = selection.isRange() ? enclosingListChild(selection.end().node()) : startListChild; if (!endListChild) return false; // For a range selection we want the following behavior: // - the start and end must be within the same overall list // - the start must be at or above the level of the rest of the range // - if the end is anywhere in a sublist lower than start, the whole sublist gets moved // In terms of this function, this means: // - endListChild must start out being be a sibling of startListChild, or be in a // sublist of startListChild or a sibling // - if endListChild is in a sublist of startListChild or a sibling, it must be adjusted // to be the ancestor that is startListChild or its sibling while (startListChild->parentNode() != endListChild->parentNode()) { endListChild = endListChild->parentNode(); if (!endListChild) return false; } // if the selection ends on a list item with a sublist, include the entire sublist if (endListChild->renderer()->isListItem()) { RenderObject* r = endListChild->renderer()->nextSibling(); if (r && isListElement(r->element())) endListChild = r->element(); } start = startListChild; end = endListChild; return true; }
static void writeSelection(TextStream& ts, const RenderObject* o) { Node* n = o->element(); if (!n || !n->isDocumentNode()) return; Document* doc = static_cast<Document*>(n); Frame* frame = doc->frame(); if (!frame) return; Selection selection = frame->selection()->selection(); if (selection.isCaret()) { ts << "caret: position " << selection.start().offset() << " of " << nodePosition(selection.start().node()); if (selection.affinity() == UPSTREAM) ts << " (upstream affinity)"; ts << "\n"; } else if (selection.isRange()) ts << "selection start: position " << selection.start().offset() << " of " << nodePosition(selection.start().node()) << "\n" << "selection end: position " << selection.end().offset() << " of " << nodePosition(selection.end().node()) << "\n"; }
void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity) { Selection selectionToDelete; Selection selectionAfterUndo; switch (endingSelection().state()) { case Selection::RANGE: selectionToDelete = endingSelection(); selectionAfterUndo = selectionToDelete; break; case Selection::CARET: { m_smartDelete = false; // Handle delete at beginning-of-block case. // Do nothing in the case that the caret is at the start of a // root editable element or at the start of a document. SelectionController selection; selection.setSelection(endingSelection()); selection.modify(SelectionController::EXTEND, SelectionController::FORWARD, granularity); Position downstreamEnd = endingSelection().end().downstream(); VisiblePosition visibleEnd = endingSelection().visibleEnd(); if (visibleEnd == endOfParagraph(visibleEnd)) downstreamEnd = visibleEnd.next(true).deepEquivalent().downstream(); // When deleting tables: Select the table first, then perform the deletion if (downstreamEnd.node() && downstreamEnd.node()->renderer() && downstreamEnd.node()->renderer()->isTable() && downstreamEnd.offset() == 0) { setEndingSelection(Selection(endingSelection().end(), Position(downstreamEnd.node(), maxDeepOffset(downstreamEnd.node())), DOWNSTREAM)); typingAddedToOpenCommand(); return; } // deleting to end of paragraph when at end of paragraph needs to merge the next paragraph (if any) if (granularity == ParagraphBoundary && selection.selection().isCaret() && isEndOfParagraph(selection.selection().visibleEnd())) selection.modify(SelectionController::EXTEND, SelectionController::FORWARD, CharacterGranularity); selectionToDelete = selection.selection(); if (!startingSelection().isRange() || selectionToDelete.base() != startingSelection().start()) selectionAfterUndo = selectionToDelete; else { // It's a little tricky to compute what the starting selection would have been in the original document. // We can't let the Selection class's validation kick in or it'll adjust for us based on // the current state of the document and we'll get the wrong result. Position extent = startingSelection().end(); if (extent.node() != selectionToDelete.end().node()) extent = selectionToDelete.extent(); else { int extraCharacters; if (selectionToDelete.start().node() == selectionToDelete.end().node()) extraCharacters = selectionToDelete.end().offset() - selectionToDelete.start().offset(); else extraCharacters = selectionToDelete.end().offset(); extent = Position(extent.node(), extent.offset() + extraCharacters); } selectionAfterUndo.setWithoutValidation(startingSelection().start(), extent); } break; } case Selection::NONE: ASSERT_NOT_REACHED(); break; } if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteSelection(selectionToDelete)) { // make undo select what was deleted setStartingSelection(selectionAfterUndo); CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete); setSmartDelete(false); typingAddedToOpenCommand(); } }
/// @brief Recombine void SubtitlesGrid::RecombineLines() { using namespace std; Selection selectedSet = GetSelectedSet(); if (selectedSet.size() < 2) return; AssDialogue *activeLine = GetActiveLine(); vector<AssDialogue*> sel; sel.reserve(selectedSet.size()); copy(selectedSet.begin(), selectedSet.end(), back_inserter(sel)); for_each(sel.begin(), sel.end(), trim_text); sort(sel.begin(), sel.end(), &AssFile::CompStart); typedef vector<AssDialogue*>::iterator diag_iter; diag_iter end = sel.end() - 1; for (diag_iter cur = sel.begin(); cur != end; ++cur) { AssDialogue *d1 = *cur; diag_iter d2 = cur + 1; // 1, 1+2 (or 2+1), 2 gets turned into 1, 2, 2 so kill the duplicate if (d1->Text == (*d2)->Text) { expand_times(d1, *d2); delete d1; context->ass->Line.remove(d1); continue; } // 1, 1+2, 1 turns into 1, 2, [empty] if (d1->Text.empty()) { delete d1; context->ass->Line.remove(d1); continue; } // If d2 is the last line in the selection it'll never hit the above test if (d2 == end && (*d2)->Text.empty()) { delete *d2; context->ass->Line.remove(*d2); continue; } // 1, 1+2 while (d2 <= end && (*d2)->Text.StartsWith(d1->Text, &(*d2)->Text)) { expand_times(*d2, d1); trim_text(*d2); ++d2; } // 1, 2+1 while (d2 <= end && (*d2)->Text.EndsWith(d1->Text, &(*d2)->Text)) { expand_times(*d2, d1); trim_text(*d2); ++d2; } // 1+2, 2 while (d2 <= end && d1->Text.EndsWith((*d2)->Text, &d1->Text)) { expand_times(d1, *d2); trim_text(d1); ++d2; } // 2+1, 2 while (d2 <= end && d1->Text.StartsWith((*d2)->Text, &d1->Text)) { expand_times(d1, *d2); trim_text(d1); ++d2; } } // Remove now non-existent lines from the selection Selection lines; transform(context->ass->Line.begin(), context->ass->Line.end(), inserter(lines, lines.begin()), cast<AssDialogue*>()); Selection newSel; set_intersection(lines.begin(), lines.end(), selectedSet.begin(), selectedSet.end(), inserter(newSel, newSel.begin())); if (newSel.empty()) newSel.insert(*lines.begin()); // Restore selection if (!newSel.count(activeLine)) activeLine = *newSel.begin(); SetSelectionAndActive(newSel, activeLine); context->ass->Commit(_("combining"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL); }
void BaseGrid::UpdateMaps(bool preserve_selected_rows) { BeginBatch(); int active_row = line_index_map[active_line]; std::vector<int> sel_rows; if (preserve_selected_rows) { sel_rows.reserve(selection.size()); transform(selection.begin(), selection.end(), back_inserter(sel_rows), [this](AssDialogue *diag) { return GetDialogueIndex(diag); }); } index_line_map.clear(); line_index_map.clear(); for (auto curdiag : context->ass->Line | agi::of_type<AssDialogue>()) { line_index_map[curdiag] = (int)index_line_map.size(); index_line_map.push_back(curdiag); } if (preserve_selected_rows) { Selection sel; // If the file shrank enough that no selected rows are left, select the // last row if (sel_rows.empty()) sel_rows.push_back(index_line_map.size() - 1); else if (sel_rows[0] >= (int)index_line_map.size()) sel_rows[0] = index_line_map.size() - 1; for (int row : sel_rows) { if (row >= (int)index_line_map.size()) break; sel.insert(index_line_map[row]); } SetSelectedSet(sel); } else { Selection lines; copy(index_line_map.begin(), index_line_map.end(), inserter(lines, lines.begin())); Selection new_sel; // Remove lines which no longer exist from the selection set_intersection(selection.begin(), selection.end(), lines.begin(), lines.end(), inserter(new_sel, new_sel.begin())); SetSelectedSet(new_sel); } // Force a reannounce of the active line if it hasn't changed, as it isn't // safe to touch the active line while processing a commit event which would // cause this function to be called AssDialogue *line = active_line; active_line = 0; // The active line may have ceased to exist; pick a new one if so if (line_index_map.size() && line_index_map.find(line) == line_index_map.end()) { if (active_row < (int)index_line_map.size()) { SetActiveLine(index_line_map[active_row]); } else if (preserve_selected_rows && !selection.empty()) { SetActiveLine(index_line_map[sel_rows[0]]); } else { SetActiveLine(index_line_map.back()); } } else { SetActiveLine(line); } if (selection.empty() && active_line) { Selection sel; sel.insert(active_line); SetSelectedSet(sel); } EndBatch(); SetColumnWidths(); Refresh(false); }