Commit d0b0eaa4 authored by Alexander Semke's avatar Alexander Semke
Browse files

[worksheet] implemented a better logic to handle the selection and

deselection of items in the worksheet view when objects are set to
visible or unvisible in the properties widget.
parent 6e74ec55
......@@ -690,7 +690,15 @@ void TextLabelPrivate::updateBorder() {
bool TextLabelPrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
emit q->changed();
emit q->visibleChanged(on);
return oldValue;
......
......@@ -405,6 +405,11 @@ void Worksheet::setIsClosing() {
m_view->setIsClosing();
}
void Worksheet::suppressSelectionChangedEvent(bool value) {
if (m_view)
m_view->suppressSelectionChangedEvent(value);
}
/*!
* \brief Worksheet::getPlotCount
* \return number of CartesianPlot's in the Worksheet
......
......@@ -80,6 +80,7 @@ public:
void setSelectedInView(const bool);
void deleteAspectFromGraphicsItem(const QGraphicsItem*);
void setIsClosing();
void suppressSelectionChangedEvent(bool);
CartesianPlotActionMode cartesianPlotActionMode();
void setCartesianPlotActionMode(CartesianPlotActionMode mode);
......
......@@ -935,8 +935,16 @@ QString AxisPrivate::name() const{
bool AxisPrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
gridItem->setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
emit q->visibilityChanged(on);
return oldValue;
}
......
......@@ -468,7 +468,15 @@ QPainterPath CartesianPlotLegendPrivate::shape() const {
bool CartesianPlotLegendPrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
emit q->visibilityChanged(on);
return oldValue;
}
......
......@@ -249,7 +249,15 @@ void CustomPointPrivate::retransform() {
bool CustomPointPrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
emit q->changed();
emit q->visibleChanged(on);
return oldValue;
......
......@@ -817,7 +817,15 @@ void HistogramPrivate::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
bool HistogramPrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
emit q->visibilityChanged(on);
return oldValue;
}
......
......@@ -324,7 +324,15 @@ void ReferenceLinePrivate::retransform() {
bool ReferenceLinePrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
// emit q->changed();
emit q->visibleChanged(on);
return oldValue;
......
......@@ -973,7 +973,15 @@ void XYCurvePrivate::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
bool XYCurvePrivate::swapVisible(bool on) {
bool oldValue = isVisible();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
//We need to supress the deselection in the view.
auto* worksheet = static_cast<Worksheet*>(q->parent(AspectType::Worksheet));
worksheet->suppressSelectionChangedEvent(true);
setVisible(on);
worksheet->suppressSelectionChangedEvent(false);
emit q->visibilityChanged(on);
retransform();
return oldValue;
......
......@@ -1550,24 +1550,16 @@ void WorksheetView::selectionChanged() {
QList<QGraphicsItem*> items = scene()->selectedItems();
//When making a graphics item invisible, it gets deselected in the scene.
//In this case we don't want to deselect the item in the project explorer.
bool invisibleDeselected = false;
//check, whether the previously selected items were deselected now.
//Forward the deselection prior to the selection of new items
//in order to avoid the unwanted multiple selection in project explorer
for (auto* item : m_selectedItems ) {
if ( items.indexOf(item) == -1 ) {
if (item->isVisible())
m_worksheet->setItemSelectedInView(item, false);
else
invisibleDeselected = true;
}
if ( items.indexOf(item) == -1 )
m_worksheet->setItemSelectedInView(item, false);
}
//select new items
if (items.isEmpty() && invisibleDeselected == false) {
if (items.isEmpty()) {
//no items selected -> select the worksheet again.
m_worksheet->setSelectedInView(true);
......@@ -1810,6 +1802,10 @@ void WorksheetView::layoutChanged(Worksheet::Layout layout) {
}
}
void WorksheetView::suppressSelectionChangedEvent(bool value) {
m_suppressSelectionChangedEvent = value;
}
void WorksheetView::registerShortcuts() {
selectAllAction->setShortcut(Qt::CTRL+Qt::Key_A);
deleteAction->setShortcut(Qt::Key_Delete);
......
......@@ -77,6 +77,7 @@ public:
void setCartesianPlotActionMode(Worksheet::CartesianPlotActionMode mode);
void setCartesianPlotCursorMode(Worksheet::CartesianPlotActionMode mode);
void setPlotLock(bool lock);
void suppressSelectionChangedEvent(bool);
Worksheet::CartesianPlotActionMode getCartesianPlotActionMode();
void registerShortcuts();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment