r17092 by jghali - - simplify retrieval of item level relative to its parent by adding proper function to PageItem class
scribus-commit
scribus-commit at lists.scribus.net
Sat Dec 17 12:24:01 UTC 2011
Author: jghali
Date: Sat Dec 17 12:24:01 2011
New Revision: 17092
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17092
Log:
- simplify retrieval of item level relative to its parent by adding proper function to PageItem class
- add function to Selection class in order to check if all selected objects have same parent doc or group
Modified:
trunk/Scribus/scribus/pageitem.cpp
trunk/Scribus/scribus/pageitem.h
trunk/Scribus/scribus/selection.cpp
trunk/Scribus/scribus/selection.h
trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp
Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17092&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Sat Dec 17 12:24:01 2011
@@ -42,6 +42,7 @@
#include "colorblind.h"
#include "commonstrings.h"
+#include "pageitem_group.h"
#include "pageitem_textframe.h"
#include "pageitem_latexframe.h"
#include "prefsmanager.h"
@@ -848,6 +849,20 @@
if (drawingOnly || m_Doc->isLoading())
return;
checkChanges();
+}
+
+int PageItem::level()
+{
+ if (Parent == NULL)
+ {
+ if (m_Doc)
+ {
+ QList<PageItem*>* items = OnMasterPage.isEmpty() ? &m_Doc->DocItems : &m_Doc->MasterItems;
+ return (items->indexOf(this) + 1);
+ }
+ return 0;
+ }
+ return (Parent->asGroupFrame()->groupItemList.indexOf(this) + 1);
}
void PageItem::moveBy(const double dX, const double dY, bool drawingOnly)
Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17092&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h (original)
+++ trunk/Scribus/scribus/pageitem.h Sat Dec 17 12:24:01 2011
@@ -246,6 +246,9 @@
// if (isWelded())
// unWeldChild();
}
+
+ // Get item level relative to its parent doc or group
+ int level();
void saxx(SaxHandler& handler, const Xml_string& elemtag) const {}
void saxx(SaxHandler& handler) const {}
Modified: trunk/Scribus/scribus/selection.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17092&path=/trunk/Scribus/scribus/selection.cpp
==============================================================================
--- trunk/Scribus/scribus/selection.cpp (original)
+++ trunk/Scribus/scribus/selection.cpp Sat Dec 17 12:24:01 2011
@@ -503,6 +503,25 @@
return layerID;
}
+bool Selection::objectsHaveSameParent(void) const
+{
+ int selectedItemCount = m_SelList.count();
+ if (selectedItemCount <= 1)
+ return true;
+
+ bool haveSameParent = true;
+ const PageItem *firstItem = itemAt(0);
+ for (int a = 1; a < selectedItemCount; ++a)
+ {
+ if (itemAt(a)->Parent != firstItem->Parent)
+ {
+ haveSameParent = false;
+ break;
+ }
+ }
+ return haveSameParent;
+}
+
bool Selection::signalsDelayed(void)
{
return (m_isGUISelection && (m_delaySignals > 0));
Modified: trunk/Scribus/scribus/selection.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17092&path=/trunk/Scribus/scribus/selection.h
==============================================================================
--- trunk/Scribus/scribus/selection.h (original)
+++ trunk/Scribus/scribus/selection.h Sat Dec 17 12:24:01 2011
@@ -158,6 +158,12 @@
*/
int objectsLayer(void) const;
+ /**
+ * \brief detect if selected object have all same parent (doc or group)
+ * @return true if objects share same parent, false otherwise
+ */
+ bool objectsHaveSameParent(void) const;
+
bool signalsDelayed(void);
void delaySignalsOn(void);
void delaySignalsOff(void);
Modified: trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17092&path=/trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp (original)
+++ trunk/Scribus/scribus/ui/propertiespalette_xyz.cpp Sat Dec 17 12:24:01 2011
@@ -294,11 +294,7 @@
m_item = i;
nameEdit->setText(m_item->itemName());
- QString tm;
- if (m_item->Parent == NULL)
- levelLabel->setText(tm.setNum(m_doc->Items->indexOf(m_item) + 1));
- else
- levelLabel->setText(tm.setNum(m_item->Parent->asGroupFrame()->groupItemList.indexOf(m_item) + 1));
+ levelLabel->setText( QString::number(m_item->level()) );
connect(nameEdit, SIGNAL(Leaved()), this, SLOT(handleNewName()));
@@ -356,20 +352,7 @@
}
xposSpin->setEnabled(!setter);
yposSpin->setEnabled(!setter);
- bool haveSameParent = true;
- int selectedItemCount = m_doc->m_Selection->count();
- if (selectedItemCount > 1)
- {
- PageItem *firstItem = m_doc->m_Selection->itemAt(0);
- for (int a = 1; a < selectedItemCount; ++a)
- {
- if (m_doc->m_Selection->itemAt(a)->Parent != firstItem->Parent)
- {
- haveSameParent = false;
- break;
- }
- }
- }
+ bool haveSameParent = m_doc->m_Selection->objectsHaveSameParent();
levelGroup->setEnabled(haveSameParent && !i->locked());
if ((m_item->isGroup()) && (!m_item->isSingleSel))
{
@@ -1131,11 +1114,7 @@
if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_doc->itemSelection_LowerItem();
- QString tm;
- if (m_item->Parent == NULL)
- levelLabel->setText(tm.setNum(m_doc->Items->indexOf(m_item) + 1));
- else
- levelLabel->setText(tm.setNum(m_item->Parent->asGroupFrame()->groupItemList.indexOf(m_item) + 1));
+ levelLabel->setText( QString::number(m_item->level()) );
}
void PropertiesPalette_XYZ::handleRaise()
@@ -1143,11 +1122,7 @@
if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_doc->itemSelection_RaiseItem();
- QString tm;
- if (m_item->Parent == NULL)
- levelLabel->setText(tm.setNum(m_doc->Items->indexOf(m_item) + 1));
- else
- levelLabel->setText(tm.setNum(m_item->Parent->asGroupFrame()->groupItemList.indexOf(m_item) + 1));
+ levelLabel->setText( QString::number(m_item->level()) );
}
void PropertiesPalette_XYZ::handleFront()
@@ -1155,11 +1130,7 @@
if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_doc->bringItemSelectionToFront();
- QString tm;
- if (m_item->Parent == NULL)
- levelLabel->setText(tm.setNum(m_doc->Items->indexOf(m_item) + 1));
- else
- levelLabel->setText(tm.setNum(m_item->Parent->asGroupFrame()->groupItemList.indexOf(m_item) + 1));
+ levelLabel->setText( QString::number(m_item->level()) );
}
void PropertiesPalette_XYZ::handleBack()
@@ -1167,11 +1138,7 @@
if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_doc->sendItemSelectionToBack();
- QString tm;
- if (m_item->Parent == NULL)
- levelLabel->setText(tm.setNum(m_doc->Items->indexOf(m_item) + 1));
- else
- levelLabel->setText(tm.setNum(m_item->Parent->asGroupFrame()->groupItemList.indexOf(m_item) + 1));
+ levelLabel->setText( QString::number(m_item->level()) );
}
void PropertiesPalette_XYZ::handleBasePoint(int m)
More information about the scribus-commit
mailing list