r16693 by jghali - #10065: changing a group item level causes havoc
scribus-commit
scribus-commit at lists.scribus.net
Sat Jun 25 13:49:01 UTC 2011
Author: jghali
Date: Sat Jun 25 13:49:01 2011
New Revision: 16693
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16693
Log:
#10065: changing a group item level causes havoc
Modified:
branches/Version135/Scribus/scribus/scribusdoc.cpp
branches/Version135/Scribus/scribus/scribusview.cpp
branches/Version135/Scribus/scribus/selection.cpp
branches/Version135/Scribus/scribus/selection.h
Modified: branches/Version135/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16693&path=/branches/Version135/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/scribusdoc.cpp (original)
+++ branches/Version135/Scribus/scribus/scribusdoc.cpp Sat Jun 25 13:49:01 2011
@@ -5381,7 +5381,7 @@
for (uint c = 0; c < docSelectionCount; ++c)
{
currItem = m_Selection->itemAt(c);
- if (((currItem->isSingleSel) && (currItem->isGroupControl)) || ((currItem->isSingleSel) && (currItem->isTableItem)))
+ if ((currItem->isSingleSel) && ((currItem->Groups.count() > 0) || (currItem->isTableItem)))
return false;
ObjOrder.insert(currItem->ItemNr, c);
int d = Items->indexOf(currItem);
@@ -5410,7 +5410,7 @@
for (uint c = 0; c < docSelectionCount; ++c)
{
currItem = m_Selection->itemAt(c);
- if (((currItem->isSingleSel) && (currItem->isGroupControl)) || ((currItem->isSingleSel) && (currItem->isTableItem)))
+ if ((currItem->isSingleSel) && ((currItem->Groups.count() > 0) || (currItem->isTableItem)))
return false;
ObjOrder.insert(currItem->ItemNr, c);
int d = Items->indexOf(currItem);
Modified: branches/Version135/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16693&path=/branches/Version135/Scribus/scribus/scribusview.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/scribusview.cpp (original)
+++ branches/Version135/Scribus/scribus/scribusview.cpp Sat Jun 25 13:49:01 2011
@@ -1851,30 +1851,23 @@
{
if (currItem->Groups.count() != 0)
{
- if (Doc->m_Selection->count() != 0)
+ if (Doc->m_Selection->findItem(currItem) == -1)
+ Doc->m_Selection->addItem(currItem);
+
+ for (int ga=0; ga < Doc->Items->count(); ++ga)
{
- if (Doc->m_Selection->findItem(currItem) == -1)
- Doc->m_Selection->addItem(currItem);
- }
- else
- Doc->m_Selection->addItem(currItem);
-
- for (int ga=0; ga<Doc->Items->count(); ++ga)
- {
- if (Doc->Items->at(ga)->Groups.count() != 0)
+ if (Doc->Items->at(ga)->Groups.count() <= 0)
+ continue;
+ if (Doc->Items->at(ga)->Groups.top() != currItem->Groups.top())
+ continue;
+ if (Doc->Items->at(ga)->ItemNr != currItem->ItemNr)
{
- if (Doc->Items->at(ga)->Groups.top() == currItem->Groups.top())
- {
- if (Doc->Items->at(ga)->ItemNr != currItem->ItemNr)
- {
- if (Doc->m_Selection->findItem(Doc->Items->at(ga)) == -1)
- Doc->m_Selection->addItem(Doc->Items->at(ga));
- }
- if (draw)
- {
- updateContents(currItem->getRedrawBounding(m_canvas->scale()));
- }
- }
+ if (Doc->m_Selection->findItem(Doc->Items->at(ga)) == -1)
+ Doc->m_Selection->addItem(Doc->Items->at(ga));
+ }
+ if (draw)
+ {
+ updateContents(currItem->getRedrawBounding(m_canvas->scale()));
}
}
}
@@ -2095,7 +2088,7 @@
int d;
QMap<int, uint> ObjOrder;
PageItem *currItem;
- PageItem *b2;
+ PageItem *item2;
uint docSelectionCount=Doc->m_Selection->count();
if ((Doc->Items->count() > 1) && (docSelectionCount != 0))
{
@@ -2109,20 +2102,39 @@
}
if (low == 0)
return;
- /*bool wasGUISelection=Doc->m_Selection->isGUISelection();
- if (wasGUISelection)
- {
- Doc->m_Selection->setIsGUISelection(false);
- Doc->m_Selection->disconnectAllItemsFromGUI();
- }*/
bool wasSignalDelayed = !Doc->m_Selection->signalsDelayed();
Doc->m_Selection->delaySignalsOn();
if (!wasSignalDelayed)
Doc->m_Selection->disconnectAllItemsFromGUI();
Selection tempSelection(*Doc->m_Selection);
- b2 = Doc->Items->at(high);
+ if (Doc->Items->at(high)->Groups.count() != 0)
+ {
+ int groupID = Doc->Items->at(high)->Groups.top();
+ while ((high + 1) < Doc->Items->count())
+ {
+ if (Doc->Items->at(high + 1)->Groups.count() == 0)
+ break;
+ if (Doc->Items->at(high + 1)->Groups.count() != groupID)
+ break;
+ high += 1;
+ }
+ }
+ item2 = Doc->Items->at(high);
Doc->m_Selection->clear();
- SelectItemNr(low-1, false);
+ if (Doc->Items->at(low)->Groups.count() != 0)
+ {
+ int groupID = Doc->Items->at(low)->Groups.top();
+ while (low > 0)
+ {
+ if (Doc->Items->at(low - 1)->Groups.count() == 0)
+ break;
+ if (Doc->Items->at(low - 1)->Groups.count() != groupID)
+ break;
+ low -= 1;
+ }
+ if (low == 0) return;
+ }
+ SelectItemNr(low - 1, false);
for (int c = 0; c < Doc->m_Selection->count(); ++c)
{
currItem = Doc->m_Selection->itemAt(c);
@@ -2130,7 +2142,7 @@
d = Doc->Items->indexOf(currItem);
Doc->Items->takeAt(d);
}
- d = Doc->Items->indexOf(b2);
+ d = Doc->Items->indexOf(item2);
QList<uint> Oindex = ObjOrder.values();
for (int c = static_cast<int>(Oindex.count()-1); c > -1; c--)
{
@@ -2158,7 +2170,7 @@
int d;
QMap<int, uint> ObjOrder;
PageItem *currItem;
- PageItem *b2;
+ PageItem *item2;
uint docSelectionCount=Doc->m_Selection->count();
if ((Doc->Items->count() > 1) && (docSelectionCount != 0))
{
@@ -2172,20 +2184,38 @@
}
if (high == static_cast<uint>(Doc->Items->count()-1))
return;
- /*bool wasGUISelection=Doc->m_Selection->isGUISelection();
- if (wasGUISelection)
- {
- Doc->m_Selection->setIsGUISelection(false);
- Doc->m_Selection->disconnectAllItemsFromGUI();
- }*/
bool wasSignalDelayed = !Doc->m_Selection->signalsDelayed();
Doc->m_Selection->delaySignalsOn();
if (!wasSignalDelayed)
Doc->m_Selection->disconnectAllItemsFromGUI();
Selection tempSelection(*Doc->m_Selection);
- b2 = Doc->Items->at(low);
+ if (Doc->Items->at(low)->Groups.count() != 0)
+ {
+ int groupID = Doc->Items->at(low)->Groups.top();
+ while (low > 0)
+ {
+ if (Doc->Items->at(low - 1)->Groups.count() == 0)
+ break;
+ if (Doc->Items->at(low - 1)->Groups.count() != groupID)
+ break;
+ low -= 1;
+ }
+ }
+ item2 = Doc->Items->at(low);
Doc->m_Selection->clear();
- SelectItemNr(high+1, false);
+ if (Doc->Items->at(high)->Groups.count() != 0)
+ {
+ int groupID = Doc->Items->at(high)->Groups.top();
+ while ((high + 1) < Doc->Items->count())
+ {
+ if (Doc->Items->at(high + 1)->Groups.count() == 0)
+ break;
+ if (Doc->Items->at(high + 1)->Groups.count() != groupID)
+ break;
+ high += 1;
+ }
+ }
+ SelectItemNr(high + 1, false);
for (int c = 0; c < Doc->m_Selection->count(); ++c)
{
currItem = Doc->m_Selection->itemAt(c);
@@ -2193,13 +2223,13 @@
d = Doc->Items->indexOf(currItem);
Doc->Items->takeAt(d);
}
+ d = Doc->Items->indexOf(item2);
+ if (d == -1)
+ d = 0;
QList<uint> Oindex = ObjOrder.values();
for (int c = 0; c <static_cast<int>(Oindex.count()); ++c)
{
- d = Doc->Items->indexOf(b2);
- if (d==-1)
- d=0;
- Doc->Items->insert(d, Doc->m_Selection->itemAt(Oindex[c]));
+ Doc->Items->insert(d + c, Doc->m_Selection->itemAt(Oindex[c]));
}
Doc->m_Selection->clear();
Doc->renumberItemsInListOrder();
Modified: branches/Version135/Scribus/scribus/selection.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16693&path=/branches/Version135/Scribus/scribus/selection.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/selection.cpp (original)
+++ branches/Version135/Scribus/scribus/selection.cpp Sat Jun 25 13:49:01 2011
@@ -21,6 +21,7 @@
#include "sclimits.h"
#include "scribusdoc.h"
#include "selection.h"
+#include "sclimits.h"
#include <QDebug>
Selection::Selection(QObject* parent)
@@ -200,10 +201,10 @@
{
if (item==NULL)
return false;
- bool listWasEmpty=m_SelList.isEmpty();
+ bool listWasEmpty = m_SelList.isEmpty();
if (listWasEmpty || !m_SelList.contains(item))
{
- m_SelList.append(item);
+ addItemInternal(item);
if (m_isGUISelection)
{
item->setSelected(true);
@@ -217,6 +218,43 @@
return false;
}
+void Selection::addItemInternal(PageItem* item)
+{
+ if (item->Groups.count() == 0 || m_SelList.count() == 0)
+ {
+ m_SelList.append(item);
+ return;
+ }
+
+ addGroupItem(item);
+}
+
+void Selection::addGroupItem(PageItem* item)
+{
+ assert (item->Groups.count() > 0);
+
+ PageItem* selItem;
+ int itemIndex = -1;
+ for (int i = 0; i < m_SelList.count(); ++i)
+ {
+ selItem = m_SelList.at(i);
+ if (selItem->ItemNr == item->ItemNr)
+ return;
+ if (selItem->Groups.count() == 0)
+ continue;
+ if (selItem->Groups.top() != item->Groups.top())
+ continue;
+ if (selItem->ItemNr < item->ItemNr)
+ itemIndex = qMax(0, qMax(itemIndex, i + 1));
+ if (selItem->ItemNr > item->ItemNr)
+ itemIndex = qMax(0, qMin(itemIndex, i));
+ }
+
+ if (itemIndex == -1)
+ itemIndex = m_SelList.count();
+ m_SelList.insert(itemIndex, item);
+}
+
bool Selection::prependItem(PageItem *item, bool doEmit)
{
if (item==NULL)
@@ -225,7 +263,7 @@
{
if (m_isGUISelection && !m_SelList.isEmpty())
m_SelList[0]->disconnectFromGUI();
- m_SelList.prepend(item);
+ prependItemInternal(item);
if (m_isGUISelection /*&& doEmit*/)
{
item->setSelected(true);
@@ -237,6 +275,17 @@
return true;
}
return false;
+}
+
+void Selection::prependItemInternal(PageItem* item)
+{
+ if (item->Groups.count() == 0 || m_SelList.count() == 0)
+ {
+ m_SelList.prepend(item);
+ return;
+ }
+
+ addGroupItem(item);
}
PageItem *Selection::itemAt_(int index)
@@ -360,6 +409,27 @@
for ( ; it!=itend ; ++it)
names.append((*it)->itemName());
return names;
+}
+
+void Selection::getItemRange(int& lowest, int & highest)
+{
+ if (m_SelList.isEmpty())
+ {
+ lowest = 0;
+ highest = -1;
+ return;
+ }
+
+ int itemNr;
+ lowest = std::numeric_limits<int>::max();
+ highest = std::numeric_limits<int>::min();
+
+ for (int i = 0; i < m_SelList.count(); ++i)
+ {
+ itemNr = m_SelList.at(i)->ItemNr;
+ lowest = qMin(itemNr, lowest);
+ highest = qMax(itemNr, highest);
+ }
}
double Selection::width() const
Modified: branches/Version135/Scribus/scribus/selection.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16693&path=/branches/Version135/Scribus/scribus/selection.h
==============================================================================
--- branches/Version135/Scribus/scribus/selection.h (original)
+++ branches/Version135/Scribus/scribus/selection.h Sat Jun 25 13:49:01 2011
@@ -134,9 +134,30 @@
* @param item PageItem reference
*/
bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
+ /**
+ * \brief Return item at specified index in the selection
+ * @param index index in selection
+ * @return Item
+ */
PageItem *itemAt(int index=0) { return itemAt_(index); }
+ /**
+ * \brief Return item at specified index in the selection
+ * @param index index in selection
+ * @return const Item
+ */
const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
+ /**
+ * \brief Get name of selected items
+ */
QStringList getSelectedItemsByName() const;
+ /**
+ * \brief Return range of selected items. If selection is empty, the lowest index returned
+ * will be strictly superior to the highest
+ * @param lowest index of the lowest item number in the selection
+ * @param highest indest of the higest item number in the selection
+ */
+ void getItemRange(int& lowest, int & highest);
+
bool isMultipleSelection() const { return m_hasGroupSelection; }
bool isGUISelection() const { return m_isGUISelection; }
double width() const;
@@ -177,6 +198,9 @@
bool m_sigSelectionChanged;
bool m_sigSelectionIsMultiple;
+ void addItemInternal(PageItem* item);
+ void prependItemInternal(PageItem* item);
+ void addGroupItem(PageItem* item);
void sendSignals(bool guiConnect = true);
signals:
More information about the scribus-commit
mailing list