r22659 by jghali - some refactoring for scripter code: remove lots of duplicate ScCore->primaryMainWindow() calls
scribus-commit
scribus-commit at lists.scribus.net
Mon Aug 27 22:04:22 UTC 2018
Author: jghali
Date: Mon Aug 27 22:04:22 2018
New Revision: 22659
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22659
Log:
some refactoring for scripter code: remove lots of duplicate ScCore->primaryMainWindow() calls
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/cmdcolor.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdpage.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdcolor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdcolor.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdcolor.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdcolor.cpp Mon Aug 27 22:04:22 2018
@@ -560,9 +560,10 @@
QString rep = QString::fromUtf8(Repl);
if (ScCore->primaryMainWindow()->HaveDoc)
{
- if (ScCore->primaryMainWindow()->doc->PageColors.contains(col) && (ScCore->primaryMainWindow()->doc->PageColors.contains(rep) || (rep == CommonStrings::None)))
- {
- ScCore->primaryMainWindow()->doc->PageColors.remove(col);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ if (currentDoc->PageColors.contains(col) && (currentDoc->PageColors.contains(rep) || (rep == CommonStrings::None)))
+ {
+ currentDoc->PageColors.remove(col);
ReplaceColor(col, rep);
}
else
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmddoc.cpp Mon Aug 27 22:04:22 2018
@@ -120,11 +120,14 @@
if (!checkHaveDocument())
return nullptr;
MarginStruct margins(ValueToPoint(tpr), ValueToPoint(lr), ValueToPoint(btr), ValueToPoint(rr));
- ScCore->primaryMainWindow()->doc->resetPage(ScCore->primaryMainWindow()->doc->pagePositioning(), &margins);
- ScCore->primaryMainWindow()->view->reformPages();
- ScCore->primaryMainWindow()->doc->setModified(true);
- ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber());
- ScCore->primaryMainWindow()->view->DrawNew();
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ currentDoc->resetPage(currentDoc->pagePositioning(), &margins);
+ currentView->reformPages();
+ currentDoc->setModified(true);
+ currentView->GotoPage(currentDoc->currentPageNumber());
+ currentView->DrawNew();
Py_RETURN_NONE;
}
@@ -136,12 +139,15 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
- ScCore->primaryMainWindow()->doc->guidesPrefs().valueBaselineGrid = ValueToPoint(grid);
- ScCore->primaryMainWindow()->doc->guidesPrefs().offsetBaselineGrid = ValueToPoint(offset);
- //ScCore->primaryMainWindow()->view->reformPages();
- ScCore->primaryMainWindow()->doc->setModified(true);
- //ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber());
- ScCore->primaryMainWindow()->view->DrawNew();
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ currentDoc->guidesPrefs().valueBaselineGrid = ValueToPoint(grid);
+ currentDoc->guidesPrefs().offsetBaselineGrid = ValueToPoint(offset);
+ //currentView->reformPages();
+ currentDoc->setModified(true);
+ //currentView->GotoPage(currentDoc->currentPageNumber());
+ currentView->DrawNew();
Py_RETURN_NONE;
}
@@ -228,9 +234,11 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
- ScCore->primaryMainWindow()->doc->documentInfo().setAuthor(QString::fromUtf8(Author));
- ScCore->primaryMainWindow()->doc->documentInfo().setTitle(QString::fromUtf8(Title));
- ScCore->primaryMainWindow()->doc->documentInfo().setComments(QString::fromUtf8(Desc));
+
+ DocumentInformation& docInfo = ScCore->primaryMainWindow()->doc->documentInfo();
+ docInfo.setAuthor(QString::fromUtf8(Author));
+ docInfo.setTitle(QString::fromUtf8(Title));
+ docInfo.setComments(QString::fromUtf8(Desc));
ScCore->primaryMainWindow()->slotDocCh();
Py_RETURN_NONE;
@@ -279,11 +287,15 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
- if (ScCore->primaryMainWindow()->doc->pagePositioning() == fp)
- ScCore->primaryMainWindow()->doc->setPageSetFirstPage(ScCore->primaryMainWindow()->doc->pagePositioning(), fsl);
- ScCore->primaryMainWindow()->view->reformPages();
- ScCore->primaryMainWindow()->view->GotoPage(ScCore->primaryMainWindow()->doc->currentPageNumber()); // is this needed?
- ScCore->primaryMainWindow()->view->DrawNew(); // is this needed?
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+
+ if (currentDoc->pagePositioning() == fp)
+ currentDoc->setPageSetFirstPage(currentDoc->pagePositioning(), fsl);
+ currentView->reformPages();
+ currentView->GotoPage(currentDoc->currentPageNumber()); // is this needed?
+ currentView->DrawNew(); // is this needed?
//CB TODO ScCore->primaryMainWindow()->pagePalette->RebuildPage(); // is this needed?
ScCore->primaryMainWindow()->slotDocCh();
@@ -303,9 +315,11 @@
{
if (!checkHaveDocument())
return nullptr;
- PyObject* names = PyList_New(ScCore->primaryMainWindow()->doc->MasterPages.count());
- QMap<QString,int>::const_iterator it(ScCore->primaryMainWindow()->doc->MasterNames.constBegin());
- QMap<QString,int>::const_iterator itEnd(ScCore->primaryMainWindow()->doc->MasterNames.constEnd());
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
+ PyObject* names = PyList_New(currentDoc->MasterPages.count());
+ QMap<QString,int>::const_iterator it(currentDoc->MasterNames.constBegin());
+ QMap<QString,int>::const_iterator itEnd(currentDoc->MasterNames.constEnd());
int n = 0;
for ( ; it != itEnd; ++it )
{
@@ -342,12 +356,14 @@
if (!checkHaveDocument())
return nullptr;
const QString masterPageName(name);
- if (ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName))
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ if (currentDoc->MasterNames.contains(masterPageName))
{
PyErr_SetString(PyExc_ValueError, "Master page already exists");
return nullptr;
}
- ScCore->primaryMainWindow()->doc->addMasterPage(ScCore->primaryMainWindow()->doc->MasterPages.count(), masterPageName);
+ currentDoc->addMasterPage(currentDoc->MasterPages.count(), masterPageName);
Py_RETURN_NONE;
}
@@ -360,7 +376,9 @@
if (!checkHaveDocument())
return nullptr;
const QString masterPageName(name);
- if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName))
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ if (!currentDoc->MasterNames.contains(masterPageName))
{
PyErr_SetString(PyExc_ValueError, "Master page does not exist");
return nullptr;
@@ -370,10 +388,10 @@
PyErr_SetString(PyExc_ValueError, "Can not delete the Normal master page");
return nullptr;
}
- bool oldMode = ScCore->primaryMainWindow()->doc->masterPageMode();
- ScCore->primaryMainWindow()->doc->setMasterPageMode(true);
- ScCore->primaryMainWindow()->deletePage2(ScCore->primaryMainWindow()->doc->MasterNames[masterPageName]);
- ScCore->primaryMainWindow()->doc->setMasterPageMode(oldMode);
+ bool oldMode = currentDoc->masterPageMode();
+ currentDoc->setMasterPageMode(true);
+ ScCore->primaryMainWindow()->deletePage2(currentDoc->MasterNames[masterPageName]);
+ currentDoc->setMasterPageMode(oldMode);
Py_RETURN_NONE;
}
@@ -386,12 +404,14 @@
if (!checkHaveDocument())
return nullptr;
e--;
- if ((e < 0) || (e > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())-1))
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ if ((e < 0) || (e > static_cast<int>(currentDoc->Pages->count())-1))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range: '%1'.","python error").arg(e+1).toLocal8Bit().constData());
return nullptr;
}
- return PyString_FromString(ScCore->primaryMainWindow()->doc->DocPages.at(e)->MPageNam.toUtf8());
+ return PyString_FromString(currentDoc->DocPages.at(e)->MPageNam.toUtf8());
}
PyObject* scribus_applymasterpage(PyObject* /* self */, PyObject* args)
@@ -403,18 +423,20 @@
if (!checkHaveDocument())
return nullptr;
const QString masterPageName(name);
- if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName))
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ if (!currentDoc->MasterNames.contains(masterPageName))
{
PyErr_SetString(PyExc_ValueError, QObject::tr("Master page does not exist: '%1'","python error").arg(masterPageName).toLocal8Bit().constData());
return nullptr;
}
- if ((page < 1) || (page > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())))
+ if ((page < 1) || (page > static_cast<int>(currentDoc->Pages->count())))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range: %1.","python error").arg(page).toLocal8Bit().constData());
return nullptr;
}
- if (!ScCore->primaryMainWindow()->doc->applyMasterPage(masterPageName, page-1))
+ if (!currentDoc->applyMasterPage(masterPageName, page-1))
{
PyErr_SetString(ScribusException, QObject::tr("Failed to apply masterpage '%1' on page: %2","python error").arg(masterPageName).arg(page).toLocal8Bit().constData());
return nullptr;
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp Mon Aug 27 22:04:22 2018
@@ -295,14 +295,16 @@
int typ = -1;
uint counter = 0;
uint counter2 = 0;
- int pageNr = ScCore->primaryMainWindow()->doc->currentPageNumber();
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ int pageNr = currentDoc->currentPageNumber();
char *kwlist[] = {const_cast<char*>(""), const_cast<char*>("page"), nullptr};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|ii", kwlist, &typ, &pageNr))
return nullptr;
- int numpages = ScCore->primaryMainWindow()->doc->Pages->count();
+ int numpages = currentDoc->Pages->count();
if (pageNr < 0 || pageNr >= numpages) {
PyErr_SetString(PyExc_RuntimeError, QObject::tr("page number is invalid.","python error").toLocal8Bit().constData());
return nullptr;
@@ -314,37 +316,37 @@
// have doc already
if (typ != -1)
{
- for (int lam2 = 0; lam2 < ScCore->primaryMainWindow()->doc->Items->count(); ++lam2)
+ for (int lam2 = 0; lam2 < currentDoc->Items->count(); ++lam2)
{
- if ((ScCore->primaryMainWindow()->doc->Items->at(lam2)->itemType() == typ) && (pageNr == static_cast<uint>(ScCore->primaryMainWindow()->doc->Items->at(lam2)->OwnPage)))
+ if ((currentDoc->Items->at(lam2)->itemType() == typ) && (pageNr == static_cast<uint>(currentDoc->Items->at(lam2)->OwnPage)))
counter++;
}
}
else
{
- for (int lam2 = 0; lam2 < ScCore->primaryMainWindow()->doc->Items->count(); ++lam2)
+ for (int lam2 = 0; lam2 < currentDoc->Items->count(); ++lam2)
{
- if (pageNr == static_cast<uint>(ScCore->primaryMainWindow()->doc->Items->at(lam2)->OwnPage))
+ if (pageNr == static_cast<uint>(currentDoc->Items->at(lam2)->OwnPage))
counter++;
}
}
l = PyList_New(counter);
- for (int lam=0; lam < ScCore->primaryMainWindow()->doc->Items->count(); ++lam)
- {
- if (pageNr == static_cast<uint>(ScCore->primaryMainWindow()->doc->Items->at(lam)->OwnPage))
+ for (int lam=0; lam < currentDoc->Items->count(); ++lam)
+ {
+ if (pageNr == static_cast<uint>(currentDoc->Items->at(lam)->OwnPage))
{
if (typ != -1)
{
- if (ScCore->primaryMainWindow()->doc->Items->at(lam)->itemType() == typ)
+ if (currentDoc->Items->at(lam)->itemType() == typ)
{
- PyList_SetItem(l, counter2, PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(lam)->itemName().toUtf8()));
+ PyList_SetItem(l, counter2, PyString_FromString(currentDoc->Items->at(lam)->itemName().toUtf8()));
counter2++;
}
}
else
{
- PyList_SetItem(l, counter2, PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(lam)->itemName().toUtf8()));
+ PyList_SetItem(l, counter2, PyString_FromString(currentDoc->Items->at(lam)->itemName().toUtf8()));
counter2++;
}
}
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdmani.cpp Mon Aug 27 22:04:22 2018
@@ -54,24 +54,26 @@
}
// Grab the old selection - but use it only where is there any
- Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ Selection tempSelection(*currentDoc->m_Selection);
bool hadOrigSelection = (tempSelection.count() != 0);
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ currentDoc->m_Selection->clear();
// Clear the selection
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
// Select the item, which will also select its group if
// there is one.
- ScCore->primaryMainWindow()->view->SelectItem(item);
+ currentView->SelectItem(item);
// scale
- ScCore->primaryMainWindow()->doc->itemSelection_SetImageScale(x, y); //CB why when this is done above?
- ScCore->primaryMainWindow()->doc->updatePic();
+ currentDoc->itemSelection_SetImageScale(x, y); //CB why when this is done above?
+ currentDoc->updatePic();
// Now restore the selection.
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
if (hadOrigSelection)
- *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+ *currentDoc->m_Selection=tempSelection;
Py_RETURN_NONE;
}
@@ -94,26 +96,28 @@
}
// Grab the old selection - but use it only where is there any
- Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ Selection tempSelection(*currentDoc->m_Selection);
bool hadOrigSelection = (tempSelection.count() != 0);
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ currentDoc->m_Selection->clear();
// Clear the selection
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
// Select the item, which will also select its group if
// there is one.
- ScCore->primaryMainWindow()->view->SelectItem(item);
+ currentView->SelectItem(item);
// scale
double newScaleX = x / item->pixm.imgInfo.xres * 72.0;
double newScaleY = y / item->pixm.imgInfo.yres * 72.0;
- ScCore->primaryMainWindow()->doc->itemSelection_SetImageScale(newScaleX, newScaleY); //CB why when this is done above?
- ScCore->primaryMainWindow()->doc->updatePic();
+ currentDoc->itemSelection_SetImageScale(newScaleX, newScaleY); //CB why when this is done above?
+ currentDoc->updatePic();
// Now restore the selection.
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
if (hadOrigSelection)
- *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+ *currentDoc->m_Selection=tempSelection;
Py_RETURN_NONE;
}
@@ -135,26 +139,28 @@
}
// Grab the old selection - but use it only where is there any
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
bool hadOrigSelection = (tempSelection.count() != 0);
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ currentDoc->m_Selection->clear();
// Clear the selection
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
// Select the item, which will also select its group if
// there is one.
- ScCore->primaryMainWindow()->view->SelectItem(item);
+ currentView->SelectItem(item);
// offset
double newOffsetX = x / ((item->imageXScale() != 0.0) ? item->imageXScale() : 1);
double newOffsetY = y / ((item->imageYScale() != 0.0) ? item->imageYScale() : 1);
- ScCore->primaryMainWindow()->doc->itemSelection_SetImageOffset(newOffsetX, newOffsetY); //CB why when this is done above?
- ScCore->primaryMainWindow()->doc->updatePic();
+ currentDoc->itemSelection_SetImageOffset(newOffsetX, newOffsetY); //CB why when this is done above?
+ currentDoc->updatePic();
// Now restore the selection.
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
if (hadOrigSelection)
- *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+ *currentDoc->m_Selection=tempSelection;
Py_RETURN_NONE;
}
@@ -225,30 +231,33 @@
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item==nullptr)
return nullptr;
+
// Grab the old selection - but use it only where is there any
- Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ Selection tempSelection(*currentDoc->m_Selection);
bool hadOrigSelection = (tempSelection.count() != 0);
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ currentDoc->m_Selection->clear();
// Clear the selection
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
// Select the item, which will also select its group if
// there is one.
- ScCore->primaryMainWindow()->view->SelectItem(item);
+ currentView->SelectItem(item);
// Move the item, or items
- if (ScCore->primaryMainWindow()->doc->m_Selection->count() > 1)
- {
- ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Move, "", Um::IMove);
- ScCore->primaryMainWindow()->doc->moveGroup(ValueToPoint(x), ValueToPoint(y));
- ScCore->primaryMainWindow()->view->endGroupTransaction();
+ if (currentDoc->m_Selection->count() > 1)
+ {
+ currentView->startGroupTransaction(Um::Move, "", Um::IMove);
+ currentDoc->moveGroup(ValueToPoint(x), ValueToPoint(y));
+ currentView->endGroupTransaction();
}
else {
- ScCore->primaryMainWindow()->doc->moveItem(ValueToPoint(x), ValueToPoint(y), item);
+ currentDoc->moveItem(ValueToPoint(x), ValueToPoint(y), item);
}
// Now restore the selection.
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
if (hadOrigSelection)
- *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+ *currentDoc->m_Selection=tempSelection;
Py_RETURN_NONE;
}
@@ -263,30 +272,33 @@
PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
if (item == nullptr)
return nullptr;
+
// Grab the old selection - but use it only where is there any
- Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ Selection tempSelection(*currentDoc->m_Selection);
bool hadOrigSelection = (tempSelection.count() != 0);
// Clear the selection
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
// Select the item, which will also select its group if
// there is one.
- ScCore->primaryMainWindow()->view->SelectItem(item);
+ currentView->SelectItem(item);
// Move the item, or items
- if (ScCore->primaryMainWindow()->doc->m_Selection->count() > 1)
- {
- ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Move, "", Um::IMove);
+ if (currentDoc->m_Selection->count() > 1)
+ {
+ currentView->startGroupTransaction(Um::Move, "", Um::IMove);
double x2, y2, w, h;
- ScCore->primaryMainWindow()->doc->m_Selection->getGroupRect(&x2, &y2, &w, &h);
- ScCore->primaryMainWindow()->doc->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2);
- ScCore->primaryMainWindow()->view->endGroupTransaction();
+ currentDoc->m_Selection->getGroupRect(&x2, &y2, &w, &h);
+ currentDoc->moveGroup(pageUnitXToDocX(x) - x2, pageUnitYToDocY(y) - y2);
+ currentView->endGroupTransaction();
}
else
- ScCore->primaryMainWindow()->doc->moveItem(pageUnitXToDocX(x) - item->xPos(), pageUnitYToDocY(y) - item->yPos(), item);
+ currentDoc->moveItem(pageUnitXToDocX(x) - item->xPos(), pageUnitYToDocY(y) - item->yPos(), item);
// Now restore the selection.
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
if (hadOrigSelection)
- *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+ *currentDoc->m_Selection=tempSelection;
Py_RETURN_NONE;
}
@@ -401,9 +413,12 @@
PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
if (i == nullptr)
return nullptr;
- ScCore->primaryMainWindow()->view->Deselect();
- ScCore->primaryMainWindow()->view->SelectItem(i);
- ScCore->primaryMainWindow()->UnGroupObj();
+
+ ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
+ currentWin->view->Deselect();
+ currentWin->view->SelectItem(i);
+ currentWin->UnGroupObj();
+
Py_RETURN_NONE;
}
@@ -423,14 +438,18 @@
PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
if (i == nullptr)
return nullptr;
- ScCore->primaryMainWindow()->view->Deselect();
- ScCore->primaryMainWindow()->view->SelectItem(i);
-// int h = ScCore->primaryMainWindow()->view->frameResizeHandle;
-// ScCore->primaryMainWindow()->view->frameResizeHandle = 1;
- ScCore->primaryMainWindow()->view->startGroupTransaction(Um::Resize, "", Um::IResize);
- ScCore->primaryMainWindow()->doc->scaleGroup(sc, sc);
- ScCore->primaryMainWindow()->view->endGroupTransaction();
-// ScCore->primaryMainWindow()->view->frameResizeHandle = h;
+
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+
+ currentView->Deselect();
+ currentView->SelectItem(i);
+// int h = currentView->frameResizeHandle;
+// currentView->frameResizeHandle = 1;
+ currentView->startGroupTransaction(Um::Resize, "", Um::IResize);
+ currentDoc->scaleGroup(sc, sc);
+ currentView->endGroupTransaction();
+// currentView->frameResizeHandle = h;
Py_RETURN_NONE;
}
@@ -581,27 +600,27 @@
return nullptr;
// Grab the old selection - but use it only where is there any
- Selection tempSelection(*ScCore->primaryMainWindow()->doc->m_Selection);
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+ Selection tempSelection(*currentDoc->m_Selection);
bool hadOrigSelection = (tempSelection.count() != 0);
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
+ currentDoc->m_Selection->clear();
// Clear the selection
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
// Select the item, which will also select its group if
// there is one.
- ScCore->primaryMainWindow()->view->SelectItem(item);
+ currentView->SelectItem(item);
// flip
- if (h == 1) {
- ScCore->primaryMainWindow()->doc->itemSelection_FlipH();
- }
- if (v == 1) {
- ScCore->primaryMainWindow()->doc->itemSelection_FlipV();
- }
+ if (h == 1)
+ currentDoc->itemSelection_FlipH();
+ if (v == 1)
+ currentDoc->itemSelection_FlipV();
// Now restore the selection.
- ScCore->primaryMainWindow()->view->Deselect();
+ currentView->Deselect();
if (hadOrigSelection)
- *ScCore->primaryMainWindow()->doc->m_Selection=tempSelection;
+ *currentDoc->m_Selection = tempSelection;
Py_RETURN_NONE;
}
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp Mon Aug 27 22:04:22 2018
@@ -825,23 +825,24 @@
PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args)
{
char* name = const_cast<char*>("");
- if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) {
- return nullptr;
- }
- if (!checkHaveDocument()) {
- return nullptr;
- }
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
+
// Is there a special name given? Yes -> add this to selection
+ ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
+ ScribusDoc* currentDoc = currentWin->doc;
+
PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i != nullptr) {
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- }
- else
- return nullptr;
+ if (i == nullptr)
+ return nullptr;
+ currentDoc->m_Selection->clear();
+ currentDoc->m_Selection->addItem(i);
+
// do the duplicate
- ScCore->primaryMainWindow()->slotEditCopy();
- ScCore->primaryMainWindow()->slotEditPaste();
+ currentWin->slotEditCopy();
+ currentWin->slotEditPaste();
Py_RETURN_NONE;
}
@@ -849,22 +850,23 @@
PyObject *scribus_copyobject(PyObject * /* self */, PyObject *args)
{
char* name = const_cast<char*>("");
- if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) {
- return nullptr;
- }
- if (!checkHaveDocument()) {
- return nullptr;
- }
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
+
// Is there a special name given? Yes -> add this to selection
+ ScribusMainWindow* currentWin = ScCore->primaryMainWindow();
+ ScribusDoc* currentDoc = currentWin->doc;
+
PageItem *i = GetUniqueItem(QString::fromUtf8(name));
- if (i != nullptr) {
- ScCore->primaryMainWindow()->doc->m_Selection->clear();
- ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
- }
- else
- return nullptr;
+ if (i == nullptr)
+ return nullptr;
+ currentDoc->m_Selection->clear();
+ currentDoc->m_Selection->addItem(i);
+
// do the copy
- ScCore->primaryMainWindow()->slotEditCopy();
+ currentWin->slotEditCopy();
Py_RETURN_NONE;
}
@@ -872,12 +874,10 @@
PyObject *scribus_pasteobject(PyObject * /* self */, PyObject *args)
{
char* name = const_cast<char*>("");
- if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) {
- return nullptr;
- }
- if (!checkHaveDocument()) {
- return nullptr;
- }
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
// do the paste
ScCore->primaryMainWindow()->slotEditPaste();
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdpage.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdpage.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdpage.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdpage.cpp Mon Aug 27 22:04:22 2018
@@ -119,10 +119,13 @@
if (!checkHaveDocument())
return nullptr;
- int loc = (e > -1) ? e : ScCore->primaryMainWindow()->doc->Pages->count();
- if (ScCore->primaryMainWindow()->doc->pageSets()[ScCore->primaryMainWindow()->doc->pagePositioning()].Columns != 1)
- {
- switch (ScCore->primaryMainWindow()->doc->locationOfPage(loc))
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ ScribusView* currentView = ScCore->primaryMainWindow()->view;
+
+ int loc = (e > -1) ? e : currentDoc->Pages->count();
+ if (currentDoc->pageSets()[currentDoc->pagePositioning()].Columns != 1)
+ {
+ switch (currentDoc->locationOfPage(loc))
{
case LeftPage:
qName = CommonStrings::trMasterPageNormalLeft;
@@ -138,7 +141,7 @@
if (QString(name).length() != 0)
qName = QString::fromUtf8(name);
- if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(qName))
+ if (!currentDoc->MasterNames.contains(qName))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Given master page name does not match any existing.","python error").toLocal8Bit().constData());
return nullptr;
@@ -171,11 +174,13 @@
{
if (!checkHaveDocument())
return nullptr;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
PyObject *t;
t = Py_BuildValue(
"(dd)",
- PointToValue(ScCore->primaryMainWindow()->doc->pageWidth()), // it's just view scale... * ScCore->primaryMainWindow()->doc->Scale),
- PointToValue(ScCore->primaryMainWindow()->doc->pageHeight()) // * ScCore->primaryMainWindow()->doc->Scale)
+ PointToValue(currentDoc->pageWidth()), // it's just view scale... * ScCore->primaryMainWindow()->doc->Scale),
+ PointToValue(currentDoc->pageHeight()) // * ScCore->primaryMainWindow()->doc->Scale)
);
return t;
}
@@ -187,8 +192,10 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
e--;
- if ((e < 0) || (e > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())-1))
+ if ((e < 0) || (e > static_cast<int>(currentDoc->Pages->count())-1))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData());
return nullptr;
@@ -196,8 +203,8 @@
PyObject *t;
t = Py_BuildValue(
"(dd)",
- PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->width()),
- PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->height())
+ PointToValue(currentDoc->Pages->at(e)->width()),
+ PointToValue(currentDoc->Pages->at(e)->height())
);
return t;
}
@@ -209,17 +216,19 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
e--;
- if ((e < 0) || (e > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())-1))
+ if ((e < 0) || (e > static_cast<int>(currentDoc->Pages->count())-1))
{
PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range.","python error").toLocal8Bit().constData());
return nullptr;
}
PyObject *margins = nullptr;
- margins = Py_BuildValue("ffff", PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.top()),
- PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.left()),
- PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.right()),
- PointToValue(ScCore->primaryMainWindow()->doc->Pages->at(e)->Margins.bottom()));
+ margins = Py_BuildValue("ffff", PointToValue(currentDoc->Pages->at(e)->Margins.top()),
+ PointToValue(currentDoc->Pages->at(e)->Margins.left()),
+ PointToValue(currentDoc->Pages->at(e)->Margins.right()),
+ PointToValue(currentDoc->Pages->at(e)->Margins.bottom()));
return margins;
}
@@ -227,26 +236,28 @@
{
if (!checkHaveDocument())
return nullptr;
- if (ScCore->primaryMainWindow()->doc->Items->count() == 0)
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
+ if (currentDoc->Items->count() == 0)
return Py_BuildValue((char*)"[]");
uint counter = 0;
- int pageNr = ScCore->primaryMainWindow()->doc->currentPageNumber();
- for (int lam2 = 0; lam2 < ScCore->primaryMainWindow()->doc->Items->count(); ++lam2)
- {
- if (pageNr == ScCore->primaryMainWindow()->doc->Items->at(lam2)->OwnPage)
+ int pageNr = currentDoc->currentPageNumber();
+ for (int lam2 = 0; lam2 < currentDoc->Items->count(); ++lam2)
+ {
+ if (pageNr == currentDoc->Items->at(lam2)->OwnPage)
counter++;
}
PyObject *l = PyList_New(counter);
PyObject *row;
counter = 0;
- for (int i = 0; i<ScCore->primaryMainWindow()->doc->Items->count(); ++i)
- {
- if (pageNr == ScCore->primaryMainWindow()->doc->Items->at(i)->OwnPage)
+ for (int i = 0; i<currentDoc->Items->count(); ++i)
+ {
+ if (pageNr == currentDoc->Items->at(i)->OwnPage)
{
row = Py_BuildValue((char*)"(sii)",
- ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().toUtf8().constData(),
- ScCore->primaryMainWindow()->doc->Items->at(i)->itemType(),
- ScCore->primaryMainWindow()->doc->Items->at(i)->uniqueNr
+ currentDoc->Items->at(i)->itemName().toUtf8().constData(),
+ currentDoc->Items->at(i)->itemType(),
+ currentDoc->Items->at(i)->uniqueNr
);
PyList_SetItem(l, counter, row);
counter++;
@@ -283,6 +294,8 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
if (!PyList_Check(l))
{
PyErr_SetString(PyExc_TypeError, QObject::tr("argument is not list: must be list of float values.","python error").toLocal8Bit().constData());
@@ -291,7 +304,7 @@
int i, n;
n = PyList_Size(l);
double guide;
- ScCore->primaryMainWindow()->doc->currentPage()->guides.clearHorizontals(GuideManagerCore::Standard);
+ currentDoc->currentPage()->guides.clearHorizontals(GuideManagerCore::Standard);
for (i=0; i<n; i++)
{
if (!PyArg_Parse(PyList_GetItem(l, i), "d", &guide))
@@ -299,7 +312,7 @@
PyErr_SetString(PyExc_TypeError, QObject::tr("argument contains non-numeric values: must be list of float values.","python error").toLocal8Bit().constData());
return nullptr;
}
- ScCore->primaryMainWindow()->doc->currentPage()->guides.addHorizontal(ValueToPoint(guide), GuideManagerCore::Standard);
+ currentDoc->currentPage()->guides.addHorizontal(ValueToPoint(guide), GuideManagerCore::Standard);
}
Py_INCREF(Py_None);
return Py_None;
@@ -334,6 +347,8 @@
return nullptr;
if (!checkHaveDocument())
return nullptr;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
if (!PyList_Check(l))
{
PyErr_SetString(PyExc_TypeError, QObject::tr("argument is not list: must be list of float values.","python error").toLocal8Bit().constData());
@@ -342,7 +357,7 @@
int i, n;
n = PyList_Size(l);
double guide;
- ScCore->primaryMainWindow()->doc->currentPage()->guides.clearVerticals(GuideManagerCore::Standard);
+ currentDoc->currentPage()->guides.clearVerticals(GuideManagerCore::Standard);
for (i=0; i<n; i++)
{
if (!PyArg_Parse(PyList_GetItem(l, i), "d", &guide))
@@ -350,7 +365,7 @@
PyErr_SetString(PyExc_TypeError, QObject::tr("argument contains no-numeric values: must be list of float values.","python error").toLocal8Bit().constData());
return nullptr;
}
- ScCore->primaryMainWindow()->doc->currentPage()->guides.addVertical(ValueToPoint(guide), GuideManagerCore::Standard);
+ currentDoc->currentPage()->guides.addVertical(ValueToPoint(guide), GuideManagerCore::Standard);
}
// Py_INCREF(Py_None);
// return Py_None;
@@ -362,10 +377,12 @@
PyObject *margins = nullptr;
if (!checkHaveDocument())
return nullptr;
- margins = Py_BuildValue("ffff", PointToValue(ScCore->primaryMainWindow()->doc->margins()->top()),
- PointToValue(ScCore->primaryMainWindow()->doc->margins()->left()),
- PointToValue(ScCore->primaryMainWindow()->doc->margins()->right()),
- PointToValue(ScCore->primaryMainWindow()->doc->margins()->bottom()));
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
+ margins = Py_BuildValue("ffff", PointToValue(currentDoc->margins()->top()),
+ PointToValue(currentDoc->margins()->left()),
+ PointToValue(currentDoc->margins()->right()),
+ PointToValue(currentDoc->margins()->bottom()));
return margins;
}
@@ -378,20 +395,23 @@
\retval void
*/
// This function is used by scribus_importpage() to add new pages
-void import_addpages(int total, int pos) {
+void import_addpages(int total, int pos)
+{
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+
for (int i=0; i<total; i++)
{
int locreal = pos + i;
int loc = pos + i + 1;
- if (loc > ScCore->primaryMainWindow()->doc->Pages->count())
- loc = ScCore->primaryMainWindow()->doc->Pages->count();
+ if (loc > currentDoc->Pages->count())
+ loc = currentDoc->Pages->count();
QString qName(CommonStrings::trMasterPageNormal);
- if (ScCore->primaryMainWindow()->doc->pageSets()[ScCore->primaryMainWindow()->doc->pagePositioning()].Columns != 1) {
- ScCore->primaryMainWindow()->doc->locationOfPage(loc);
- switch (ScCore->primaryMainWindow()->doc->locationOfPage(loc))
+ if (currentDoc->pageSets()[currentDoc->pagePositioning()].Columns != 1) {
+ currentDoc->locationOfPage(loc);
+ switch (currentDoc->locationOfPage(loc))
{
case LeftPage:
qName = CommonStrings::trMasterPageNormalLeft;
@@ -457,7 +477,8 @@
int startPage=0, nrToImport=pageNs.size();
bool doIt = true;
- if (ScCore->primaryMainWindow()->doc->masterPageMode())
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
+ if (currentDoc->masterPageMode())
{
if (nrToImport > 1)
ScCore->primaryMainWindow()->loadPage(fromDoc, pageNs[0] - 1, false);
@@ -470,17 +491,17 @@
else if (importWhere == 1) //After page
startPage = importWherePage + 1;
else //at end
- startPage = ScCore->primaryMainWindow()->doc->DocPages.count();// + 1;
+ startPage = currentDoc->DocPages.count();// + 1;
import_addpages(nrToImport, startPage);
}
else
{
- startPage = ScCore->primaryMainWindow()->doc->currentPage()->pageNr() + 1;
- if (nrToImport > (ScCore->primaryMainWindow()->doc->DocPages.count() - ScCore->primaryMainWindow()->doc->currentPage()->pageNr()))
- {
- int tmp=nrToImport - (ScCore->primaryMainWindow()->doc->DocPages.count() - ScCore->primaryMainWindow()->doc->currentPage()->pageNr());
- import_addpages(tmp, ScCore->primaryMainWindow()->doc->DocPages.count());
+ startPage = currentDoc->currentPage()->pageNr() + 1;
+ if (nrToImport > (currentDoc->DocPages.count() - currentDoc->currentPage()->pageNr()))
+ {
+ int tmp=nrToImport - (currentDoc->DocPages.count() - currentDoc->currentPage()->pageNr());
+ import_addpages(tmp, currentDoc->DocPages.count());
}
}
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22659&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp Mon Aug 27 22:04:22 2018
@@ -376,11 +376,12 @@
PageItem *currItem = GetUniqueItem(QString::fromUtf8(Name));
if (currItem == nullptr)
return nullptr;
+ ScribusDoc* currentDoc = ScCore->primaryMainWindow()->doc;
// apply rounding
currItem->setCornerRadius(w);
currItem->SetFrameRound();
- ScCore->primaryMainWindow()->doc->setRedrawBounding(currItem);
- ScCore->primaryMainWindow()->doc->setFrameRounded();
+ currentDoc->setRedrawBounding(currItem);
+ currentDoc->setFrameRounded();
Py_RETURN_NONE;
}
More information about the scribus-commit
mailing list