r24231 by jghali - #16315: duplicateObject(s)() should not affect the clipboard
scribus-commit
scribus-commit at lists.scribus.net
Thu Nov 12 20:52:25 UTC 2020
Author: jghali
Date: Thu Nov 12 20:52:24 2020
New Revision: 24231
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24231
Log:
#16315: duplicateObject(s)() should not affect the clipboard
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdobj.cpp
trunk/Scribus/scribus/scribus.cpp
trunk/Scribus/scribus/scribusdoc.cpp
trunk/Scribus/scribus/scribusdoc.h
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24231&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp Thu Nov 12 20:52:24 2020
@@ -835,15 +835,14 @@
ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
ScribusDoc* currentDoc = currentWin->doc;
- PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i == nullptr)
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == nullptr)
return nullptr;
currentDoc->m_Selection->clear();
- currentDoc->m_Selection->addItem(i);
+ currentDoc->m_Selection->addItem(item);
// do the duplicate
- currentWin->slotEditCopy();
- currentWin->slotEditPaste();
+ currentDoc->itemSelection_Duplicate(0.0, 0.0);
return PyUnicode_FromString(currentDoc->m_Selection->itemAt(0)->itemName().toUtf8());
}
@@ -921,8 +920,7 @@
}
// do the duplicate
- currentWin->slotEditCopy();
- currentWin->slotEditPaste();
+ currentDoc->itemSelection_Duplicate(0.0, 0.0);
PyObject* pyList = PyList_New(currentDoc->m_Selection->count());
for (int i = 0; i < currentDoc->m_Selection->count(); ++i)
Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdobj.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24231&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdobj.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdobj.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdobj.cpp Thu Nov 12 20:52:24 2020
@@ -835,15 +835,14 @@
ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
ScribusDoc* currentDoc = currentWin->doc;
- PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i == nullptr)
+ PageItem *item = GetUniqueItem(QString::fromUtf8(name));
+ if (item == nullptr)
return nullptr;
currentDoc->m_Selection->clear();
- currentDoc->m_Selection->addItem(i);
+ currentDoc->m_Selection->addItem(item);
// do the duplicate
- currentWin->slotEditCopy();
- currentWin->slotEditPaste();
+ currentDoc->itemSelection_Duplicate(0.0, 0.0);
return PyString_FromString(currentDoc->m_Selection->itemAt(0)->itemName().toUtf8());
}
@@ -921,8 +920,7 @@
}
// do the duplicate
- currentWin->slotEditCopy();
- currentWin->slotEditPaste();
+ currentDoc->itemSelection_Duplicate(0.0, 0.0);
PyObject* pyList = PyList_New(currentDoc->m_Selection->count());
for (int i = 0; i < currentDoc->m_Selection->count(); ++i)
Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24231&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Thu Nov 12 20:52:24 2020
@@ -6281,44 +6281,16 @@
void ScribusMainWindow::duplicateItem()
{
slotSelect();
- bool savedAlignGrid = doc->SnapGrid;
- bool savedAlignGuides = doc->SnapGuides;
- bool savedAlignElement = doc->SnapElement;
+
+ double shiftGapH = doc->opToolPrefs().dispX * doc->unitRatio();
+ double shiftGapV = doc->opToolPrefs().dispY * doc->unitRatio();
+
internalCopy = true;
- doc->SnapGrid = false;
- doc->SnapGuides = false;
- doc->SnapElement = false;
-
- UndoTransaction trans;
- if (UndoManager::undoEnabled())
- trans = m_undoManager->beginTransaction(Um::Selection, Um::IPolygon, Um::Duplicate, QString(), Um::IMultipleDuplicate);
-
- ItemMultipleDuplicateData mdData;
- mdData.type = 0;
- mdData.copyCount = 1;
- mdData.copyShiftOrGap = 0;
- mdData.copyShiftGapH = doc->opToolPrefs().dispX * doc->unitRatio();
- mdData.copyShiftGapV = doc->opToolPrefs().dispY * doc->unitRatio();
-
- int oldItemCount = doc->Items->count();
- doc->m_Selection->delaySignalsOn();
- doc->itemSelection_MultipleDuplicate(mdData);
- view->deselectItems(true);
- for (int i = oldItemCount; i < doc->Items->count(); ++i)
- {
- PageItem* item = doc->Items->at(i);
- doc->m_Selection->addItem(item);
- }
- doc->m_Selection->delaySignalsOff();
-
- if (trans)
- trans.commit();
- doc->SnapGrid = savedAlignGrid;
- doc->SnapGuides = savedAlignGuides;
- doc->SnapElement = savedAlignElement;
+
+ doc->itemSelection_Duplicate(shiftGapH, shiftGapV);
+
internalCopy = false;
internalCopyBuffer.clear();
- view->DrawNew();
}
void ScribusMainWindow::duplicateItemMulti()
Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24231&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Thu Nov 12 20:52:24 2020
@@ -13218,30 +13218,77 @@
return nr;
}
-void ScribusDoc::itemSelection_MultipleDuplicate(const ItemMultipleDuplicateData& mdData)
+void ScribusDoc::itemSelection_Duplicate(double shiftX, double shiftY, Selection* customSelection)
+{
+ Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+ assert(itemSelection != nullptr);
+
+ bool savedAlignGrid = this->SnapGrid;
+ bool savedAlignGuides = this->SnapGuides;
+ bool savedAlignElement = this->SnapElement;
+ this->SnapGrid = false;
+ this->SnapGuides = false;
+ this->SnapElement = false;
+
+ UndoTransaction trans;
+ if (UndoManager::undoEnabled())
+ trans = m_undoManager->beginTransaction(Um::Selection, Um::IPolygon, Um::Duplicate, QString(), Um::IMultipleDuplicate);
+
+ ItemMultipleDuplicateData mdData;
+ mdData.type = 0;
+ mdData.copyCount = 1;
+ mdData.copyShiftOrGap = 0;
+ mdData.copyShiftGapH = shiftX;
+ mdData.copyShiftGapV = shiftY;
+
+ int oldItemCount = Items->count();
+ m_Selection->delaySignalsOn();
+ itemSelection_MultipleDuplicate(mdData, itemSelection);
+ m_Selection->clear();
+ for (int i = oldItemCount; i < Items->count(); ++i)
+ {
+ PageItem* item = Items->at(i);
+ m_Selection->addItem(item);
+ }
+ m_Selection->delaySignalsOff();
+
+ if (trans)
+ trans.commit();
+
+ this->SnapGrid = savedAlignGrid;
+ this->SnapGuides = savedAlignGuides;
+ this->SnapElement = savedAlignElement;
+
+ regionsChanged()->update(QRectF());
+}
+
+void ScribusDoc::itemSelection_MultipleDuplicate(const ItemMultipleDuplicateData& mdData, Selection* customSelection)
{
if ((mdData.type == 0 && mdData.copyCount < 1) || (mdData.type == 1 && (mdData.gridRows == 1 && mdData.gridCols == 1)))
return;
if ((mdData.type == 2) && (Pages->count() == 1))
return;
+
+ Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+ assert(itemSelection != nullptr);
QString tooltip;
UndoTransaction activeTransaction;
if (UndoManager::undoEnabled())
{ // Make multiple duplicate a single action in the action history
- if (m_Selection->count() > 1)
+ if (itemSelection->count() > 1)
activeTransaction = m_undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::MultipleDuplicate, "", Um::IMultipleDuplicate);
else
{
- PageItem* item=m_Selection->itemAt(0);
+ PageItem* item = itemSelection->itemAt(0);
activeTransaction = m_undoManager->beginTransaction(item->getUName(), item->getUPixmap(), Um::MultipleDuplicate, "", Um::IMultipleDuplicate);
}
}
DoDrawing = false;
view()->updatesOn(false);
- QList<PageItem*> selectedItems = m_Selection->items();
+ QList<PageItem*> selectedItems = itemSelection->items();
std::stable_sort(selectedItems.begin(), selectedItems.end(), compareItemLevel);
Selection selection(this, false);
@@ -13269,12 +13316,12 @@
m_View->deselectItems(true);
for (int i = 0; i < mdData.copyCount; ++i)
{
- uint ac = Items->count();
+ int oldItemCount = Items->count();
ss.readElem(BufferS, this, m_currentPage->xOffset(), m_currentPage->yOffset(), false, true);
m_Selection->delaySignalsOn();
- for (int as = ac; as < Items->count(); ++as)
- {
- PageItem* bItem = Items->at(as);
+ for (int j = oldItemCount; j < Items->count(); ++j)
+ {
+ PageItem* bItem = Items->at(j);
bItem->setLocked(false);
bItem->moveBy(dH2, dV2, true);
if (bItem->isGroup())
@@ -13302,11 +13349,6 @@
dV2 += m_Selection->height();
}
dR2 += dR;
- if (m_Selection->count() > 0)
- {
- m_Selection->itemAt(0)->connectToGUI();
- m_Selection->itemAt(0)->emitAllToGUI();
- }
m_Selection->clear();
}
QString unitSuffix = unitGetStrFromIndex(this->unitIndex());
@@ -13363,7 +13405,8 @@
view()->updatesOn(true);
//FIXME: stop using m_View
m_View->deselectItems(true);
- view()->DrawNew();
+
+ regionsChanged()->update(QRectF());
changed();
}
Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24231&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Thu Nov 12 20:52:24 2020
@@ -1554,7 +1554,8 @@
void itemSelection_DistributeTop();
void itemSelection_SwapLeft();
void itemSelection_SwapRight();
- void itemSelection_MultipleDuplicate(const ItemMultipleDuplicateData&);
+ void itemSelection_Duplicate(double shiftX, double shiftY, Selection* customSelection = nullptr);
+ void itemSelection_MultipleDuplicate(const ItemMultipleDuplicateData&, Selection* customSelection = nullptr);
void itemSelection_UniteItems(Selection* customSelection = nullptr);
void itemSelection_SplitItems(Selection* customSelection = nullptr);
/**
More information about the scribus-commit
mailing list