r23174 by jghali - #15798: prevent selection of items on invisible layers

scribus-commit scribus-commit at lists.scribus.net
Mon Sep 2 14:20:53 UTC 2019


Author: jghali
Date: Mon Sep  2 14:20:52 2019
New Revision: 23174

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23174
Log:
#15798: prevent selection of items on invisible layers

Modified:
    trunk/Scribus/scribus/canvas.cpp
    trunk/Scribus/scribus/canvasmode_edit.cpp
    trunk/Scribus/scribus/canvasmode_normal.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h

Modified: trunk/Scribus/scribus/canvas.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23174&path=/trunk/Scribus/scribus/canvas.cpp
==============================================================================
--- trunk/Scribus/scribus/canvas.cpp	(original)
+++ trunk/Scribus/scribus/canvas.cpp	Mon Sep  2 14:20:52 2019
@@ -416,7 +416,7 @@
 		{
 			currItem = m_doc->currentPage()->FromMaster.at(currNr);
 			QTransform itemPos;
-			if (((currItem->m_layerID == m_doc->activeLayer()) || (m_doc->layerSelectable(currItem->m_layerID))) && (!m_doc->layerLocked(currItem->m_layerID)))
+			if (m_doc->canSelectItemOnLayer(currItem->m_layerID))
 			{
 				if (!currItem->ChangedMasterItem)
 				{
@@ -464,7 +464,7 @@
 			--currNr;
 			continue;
 		}
-		if (((currItem->m_layerID == m_doc->activeLayer()) || (m_doc->layerSelectable(currItem->m_layerID))) && (!m_doc->layerLocked(currItem->m_layerID)))
+		if (m_doc->canSelectItemOnLayer(currItem->m_layerID))
 		{
 			QTransform itemPos = currItem->getTransform();
 			QPainterPath currPath(itemPos.map(QPointF(0,0)));

Modified: trunk/Scribus/scribus/canvasmode_edit.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23174&path=/trunk/Scribus/scribus/canvasmode_edit.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_edit.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_edit.cpp	Mon Sep  2 14:20:52 2019
@@ -888,7 +888,7 @@
 				QRect apr2(docItem->getRedrawBounding(1.0));
 				if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName()))
 					continue;
-				if (((Sele.contains(apr.boundingRect())) || (Sele.contains(apr2))) && ((docItem->m_layerID == m_doc->activeLayer()) || (m_doc->layerSelectable(docItem->m_layerID))) && (!m_doc->layerLocked(docItem->m_layerID)))
+				if (((Sele.contains(apr.boundingRect())) || (Sele.contains(apr2))) && m_doc->canSelectItemOnLayer(docItem->m_layerID))
 				{
 					bool redrawSelection=false;
 					m_view->SelectItemNr(a, redrawSelection);

Modified: trunk/Scribus/scribus/canvasmode_normal.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23174&path=/trunk/Scribus/scribus/canvasmode_normal.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_normal.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_normal.cpp	Mon Sep  2 14:20:52 2019
@@ -1166,7 +1166,7 @@
 				PageItem* docItem = m_doc->Items->at(a);
 				if ((m_doc->masterPageMode()) && (docItem->OnMasterPage != m_doc->currentPage()->pageName()))
 					continue;
-				if (((docItem->m_layerID == m_doc->activeLayer()) || (m_doc->layerSelectable(docItem->m_layerID))) && (!m_doc->layerLocked(docItem->m_layerID)))
+				if (m_doc->canSelectItemOnLayer(docItem->m_layerID))
 				{
 					// get current item rect/bounding box
 					QRect apr2 = m_canvas->canvasToLocal( docItem->getCurrentBoundingRect(docItem->lineWidth()) );

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23174&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Mon Sep  2 14:20:52 2019
@@ -5111,12 +5111,12 @@
 		PageItem *currItem;
 		view->Deselect();
 		doc->m_Selection->delaySignalsOn();
-		int docItemsCount=doc->Items->count();
-		int docCurrentPage=doc->currentPageNumber();
+		int docItemsCount = doc->Items->count();
+		int docCurrentPage = doc->currentPageNumber();
 		for (int i = 0; i < docItemsCount; ++i)
 		{
 			currItem = doc->Items->at(i);
-			if (((currItem->m_layerID == doc->activeLayer()) || (doc->layerSelectable(currItem->m_layerID))) && (!doc->layerLocked(currItem->m_layerID)))
+			if (doc->canSelectItemOnLayer(currItem->m_layerID))
 			{
 				if (docWideSelect)
 					doc->m_Selection->addItem(currItem);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23174&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Mon Sep  2 14:20:52 2019
@@ -2871,7 +2871,7 @@
 	const ScLayer* ll = Layers.layerByID(layerToActivate);
 	Q_ASSERT(ll);
 	if (ll)
-		m_ActiveLayer=layerToActivate;
+		m_ActiveLayer = layerToActivate;
 	return (ll != nullptr);
 }
 
@@ -3395,11 +3395,22 @@
 	return found;
 }
 
-
-bool ScribusDoc::layerContainsItems(const int layerID)
+bool ScribusDoc::canSelectItemOnLayer(int layerID) const
+{
+	if ((m_ActiveLayer != layerID) && !layerSelectable(layerID))
+		return false;
+
+	bool canSelect = layerVisible(layerID);
+	if (!canSelect)
+		return false;
+	canSelect = !layerLocked(layerID);
+	return canSelect;
+}
+
+bool ScribusDoc::layerContainsItems(const int layerID) const
 {
 	QList<PageItem*> allItems;
-	int masterItemsCount=MasterItems.count();
+	int masterItemsCount = MasterItems.count();
 	for (int i = 0; i < masterItemsCount; ++i)
 	{
 		PageItem* currItem = MasterItems.at(i);
@@ -3415,7 +3426,8 @@
 		}
 		allItems.clear();
 	}
-	int docItemsCount=DocItems.count();
+
+	int docItemsCount = DocItems.count();
 	for (int i = 0; i < docItemsCount; ++i)
 	{
 		PageItem* currItem = DocItems.at(i);

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23174&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Mon Sep  2 14:20:52 2019
@@ -486,11 +486,21 @@
 	 */
 	bool changeLayerName(const int layerID, const QString& newName);
 	/**
+	 * @brief Test if items can be selected on a specific layer
+	 * 
+	 * This function check if items can be selected on the specified layer
+	 * by checking layer visibility and selectable property etc...
+	 *
+	 * @param layerID ID of the layer
+	 * @return a boolean
+	 */
+	bool canSelectItemOnLayer(int layerID) const;
+	/**
 	 * @brief Does the layer have items on it?
 	 * @param layerID ID of the layer
 	 * @return Layer contains items bool
 	 */
-	bool layerContainsItems(const int layerID);
+	bool layerContainsItems(const int layerID) const;
 	/**
 	 * @brief Renumber a layer. Used in particular for reinsertion for undo/redo
 	 * @param layerID old layer ID




More information about the scribus-commit mailing list