View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002953 | Scribus | Internal | public | 2006-01-02 20:52 | 2006-01-05 04:54 |
Reporter | Assigned To | ||||
Priority | normal | Severity | tweak | Reproducibility | always |
Status | acknowledged | Resolution | open | ||
Product Version | 1.3.3cvs | ||||
Summary | 0002953: Reduce use of new/delete where automatic objects can be used, start using auto_ptr where appropriate. | ||||
Description | Scribus does a lot of manual memory management. It's not especially safe, and can lead to unpleasant leaks and bugs. It's also hard to maintain and can be hard to read. Given this, it'd be nice to start making use of more of the facilities provided by c++ for automatic memory management. The first step of this is to use stack-based automatic objects that are deleted when they go out of scope. These are (a) simpler, (b) faster, and (c) easier to understand than free-store based objects that are new()'d and delete()'d . Consider: int f() { SomeDialog * d = new SomeDialog(); Q_CHECK_PTR(d); bool result = d->exec(); delete d; return result; } vs int f() { SomeDialog d; return d->exec(); } or even int f() { return SomeDialog().exec(); } There are also cases where using stack based objects can gain us a little speed (in general) since stack allocations are extremely fast. Temporary copies of things like PageItem::ZZ structs are reasonable candidates. Note that this applies even to QObjects that can delete themselves when their parent is deleted. If their parent is 0 they can be leaked, and if it's ScMW or another long-lived object, they're effectively leaked until program exit anyway. The next stage, once that's done, is to start looking at places where we can make use of std::auto_ptr to make our object management safer. That's something to consider later. | ||||
Tags | No tags attached. | ||||
Patch | |||||
2006-01-02 20:52
|
scribus_delete_working2.diff (121,866 bytes)
? \ ? about_builddate.inc ? deletePage ? docitemattrprefsbase.cpp ? docitemattrprefsbase.h ? pageitemattributesbase.cpp ? pageitemattributesbase.h ? doc/en/2 ? doc/en/plugin_howto_temp.html ? doc/en/plugin_overview.html ? plugins/scriptplugin/scripter2.tar.gz ? plugins/scriptplugin/scripter2/.deps ? plugins/scriptplugin/scripter2/.libs ? plugins/scriptplugin/scripter2/Makefile ? plugins/scriptplugin/scripter2/Makefile.in ? plugins/scriptplugin/scripter2/libscripter2.la ? plugins/scriptplugin/scripter2/scripter2_base.lo ? plugins/scriptplugin/scripter2/scripter2_qtclass_qapplication.lo ? plugins/scriptplugin/scripter2/scripter2_qtclass_qframe.lo ? plugins/scriptplugin/scripter2/scripter2_qtclass_qmainwindow.lo ? plugins/scriptplugin/scripter2/scripter2_qtclass_qobject.lo ? plugins/scriptplugin/scripter2/scripter2_qtclass_qscrollview.lo ? plugins/scriptplugin/scripter2/scripter2_qtclass_qwidget.lo ? plugins/scriptplugin/scripter2/scripter2_qttype_qstring.lo ? plugins/scriptplugin/scripter2/scripter2_scribus_pageitem.lo ? plugins/scriptplugin/scripter2/scripter2_scribus_scribusdoc.lo ? plugins/scriptplugin/scripter2/scripter2_scribus_scribusmainwin.lo ? plugins/scriptplugin/scripter2/scripter2_scribus_scribusqapp.lo ? plugins/scriptplugin/scripter2/scripter2_scribus_scribusview.lo ? plugins/scriptplugin/scripter2/scripter2_scribus_scribuswin.lo ? plugins/scriptplugin/scripter2/scripter2_scribusstructs.lo ? plugins/scriptplugin/scripter2/scripter2_styles.lo Index: editformats.cpp =================================================================== RCS file: /cvs/Scribus/scribus/editformats.cpp,v retrieving revision 1.28.2.26 diff -p -u -r1.28.2.26 editformats.cpp --- editformats.cpp 10 Dec 2005 14:10:35 -0000 1.28.2.26 +++ editformats.cpp 2 Jan 2006 20:40:45 -0000 @@ -233,7 +233,7 @@ StilFormate::StilFormate( QWidget* paren void StilFormate::saveIt() { - emit saveStyle(this); + emit saveStyle(*this); } void StilFormate::selFormat(QListBoxItem *c) Index: editformats.h =================================================================== RCS file: /cvs/Scribus/scribus/editformats.h,v retrieving revision 1.9.2.8 diff -p -u -r1.9.2.8 editformats.h --- editformats.h 18 Oct 2005 06:34:37 -0000 1.9.2.8 +++ editformats.h 2 Jan 2006 20:40:45 -0000 @@ -93,7 +93,7 @@ public slots: void loadStyles(); signals: - void saveStyle(StilFormate *); + void saveStyle(StilFormate&); protected: QHBoxLayout* StilFormateLayout; Index: lineformats.cpp =================================================================== RCS file: /cvs/Scribus/scribus/lineformats.cpp,v retrieving revision 1.25.2.11 diff -p -u -r1.25.2.11 lineformats.cpp --- lineformats.cpp 10 Dec 2005 14:10:35 -0000 1.25.2.11 +++ lineformats.cpp 2 Jan 2006 20:40:45 -0000 @@ -87,7 +87,7 @@ LineFormate::LineFormate( QWidget* paren void LineFormate::saveIt() { - emit saveStyle(this); + emit saveStyle(*this); } void LineFormate::selFormat(QListBoxItem *c) Index: lineformats.h =================================================================== RCS file: /cvs/Scribus/scribus/lineformats.h,v retrieving revision 1.6.2.2 diff -p -u -r1.6.2.2 lineformats.h --- lineformats.h 10 Aug 2005 07:14:56 -0000 1.6.2.2 +++ lineformats.h 2 Jan 2006 20:40:45 -0000 @@ -47,7 +47,7 @@ public slots: void loadLStyles(); signals: - void saveStyle(LineFormate *); + void saveStyle(LineFormate&); protected: QHBoxLayout* StilFormateLayout; Index: pageitem_pathtext.cpp =================================================================== RCS file: /cvs/Scribus/scribus/Attic/pageitem_pathtext.cpp,v retrieving revision 1.1.2.2 diff -p -u -r1.1.2.2 pageitem_pathtext.cpp --- pageitem_pathtext.cpp 14 Dec 2005 13:00:05 -0000 1.1.2.2 +++ pageitem_pathtext.cpp 2 Jan 2006 20:40:45 -0000 @@ -63,7 +63,6 @@ void PageItem_PathText::DrawObj_Item(ScP double wide; QString chx, chx2, chx3; struct ScText *hl; - struct ZZ *Zli; double dx; double sp = 0; double oldSp = 0; @@ -181,8 +180,8 @@ void PageItem_PathText::DrawObj_Item(ScP p->save(); QWMatrix savWM = p->worldMatrix(); p->setWorldMatrix(trafo); - Zli = new ZZ; - Zli->Zeich = chx; + ZZ Zli; + Zli.Zeich = chx; if (hl->ccolor != "None") { QColor tmp; @@ -195,33 +194,32 @@ void PageItem_PathText::DrawObj_Item(ScP SetFarbe(&tmp, hl->cstroke, hl->cshade2); p->setPen(tmp, 1, SolidLine, FlatCap, MiterJoin); } - Zli->Farb = hl->ccolor; - Zli->Farb2 = hl->cstroke; - Zli->shade = hl->cshade; - Zli->shade2 = hl->cshade2; - Zli->xco = 0; - Zli->yco = BaseOffs; - Zli->Sele = hl->cselect; - Zli->Siz = chs; - Zli->realSiz = hl->csize; - Zli->Style = hl->cstyle; - Zli->ZFo = hl->cfont; - Zli->wide = wide; - Zli->kern = hl->csize * hl->cextra / 10000.0; - Zli->scale = hl->cscale; - Zli->scalev = hl->cscalev; - Zli->base = hl->cbase; - Zli->shadowX = hl->cshadowx; - Zli->shadowY = hl->cshadowx; - Zli->outline = hl->coutline; - Zli->underpos = hl->cunderpos; - Zli->underwidth = hl->cunderwidth; - Zli->strikepos = hl->cstrikepos; - Zli->strikewidth = hl->cstrikewidth; - Zli->embedded = 0; + Zli.Farb = hl->ccolor; + Zli.Farb2 = hl->cstroke; + Zli.shade = hl->cshade; + Zli.shade2 = hl->cshade2; + Zli.xco = 0; + Zli.yco = BaseOffs; + Zli.Sele = hl->cselect; + Zli.Siz = chs; + Zli.realSiz = hl->csize; + Zli.Style = hl->cstyle; + Zli.ZFo = hl->cfont; + Zli.wide = wide; + Zli.kern = hl->csize * hl->cextra / 10000.0; + Zli.scale = hl->cscale; + Zli.scalev = hl->cscalev; + Zli.base = hl->cbase; + Zli.shadowX = hl->cshadowx; + Zli.shadowY = hl->cshadowx; + Zli.outline = hl->coutline; + Zli.underpos = hl->cunderpos; + Zli.underwidth = hl->cunderwidth; + Zli.strikepos = hl->cstrikepos; + Zli.strikewidth = hl->cstrikewidth; + Zli.embedded = 0; if (!m_Doc->RePos) - DrawZeichenS(p, Zli); - delete Zli; + DrawZeichenS(p, &Zli); p->setWorldMatrix(savWM); p->restore(); p->setZoomFactor(sc); Index: pageitem_textframe.cpp =================================================================== RCS file: /cvs/Scribus/scribus/Attic/pageitem_textframe.cpp,v retrieving revision 1.1.2.19 diff -p -u -r1.1.2.19 pageitem_textframe.cpp --- pageitem_textframe.cpp 21 Dec 2005 23:59:29 -0000 1.1.2.19 +++ pageitem_textframe.cpp 2 Jan 2006 20:40:46 -0000 @@ -1525,38 +1525,37 @@ void PageItem_TextFrame::DrawObj_Item(Sc double wt = Cwidth(m_Doc, Zli2->ZFo, tabFillCharQStr, Zli2->Siz); int coun = static_cast<int>((Zli2->xco - tabDist) / wt); double sPos = Zli2->xco - (Zli2->xco - tabDist) + 1; - Zli = new ZZ; - Zli->Zeich = tabFillCharQStr; - Zli->Farb = Zli2->Farb; - Zli->Farb2 = Zli2->Farb2; - Zli->shade = Zli2->shade; - Zli->shade2 = Zli2->shade2; - Zli->yco = Zli2->yco; - Zli->Sele = Zli2->Sele; - Zli->Siz = Zli2->Siz; - Zli->realSiz = Zli2->realSiz; - Zli->Style = Zli2->Style; - Zli->ZFo = Zli2->ZFo; - Zli->wide = wt; - Zli->kern = 0; - Zli->scale = 1000; - Zli->scalev = 1000; - Zli->base = Zli2->base; - Zli->shadowX = Zli2->shadowX; - Zli->shadowY = Zli2->shadowY; - Zli->outline = Zli2->outline; - Zli->underpos = Zli2->underpos; - Zli->underwidth = Zli2->underwidth; - Zli->strikepos = Zli2->strikepos; - Zli->strikewidth = Zli2->strikewidth; - Zli->embedded = 0; + ZZ ZliTemp; + ZliTemp.Zeich = tabFillCharQStr; + ZliTemp.Farb = Zli2->Farb; + ZliTemp.Farb2 = Zli2->Farb2; + ZliTemp.shade = Zli2->shade; + ZliTemp.shade2 = Zli2->shade2; + ZliTemp.yco = Zli2->yco; + ZliTemp.Sele = Zli2->Sele; + ZliTemp.Siz = Zli2->Siz; + ZliTemp.realSiz = Zli2->realSiz; + ZliTemp.Style = Zli2->Style; + ZliTemp.ZFo = Zli2->ZFo; + ZliTemp.wide = wt; + ZliTemp.kern = 0; + ZliTemp.scale = 1000; + ZliTemp.scalev = 1000; + ZliTemp.base = Zli2->base; + ZliTemp.shadowX = Zli2->shadowX; + ZliTemp.shadowY = Zli2->shadowY; + ZliTemp.outline = Zli2->outline; + ZliTemp.underpos = Zli2->underpos; + ZliTemp.underwidth = Zli2->underwidth; + ZliTemp.strikepos = Zli2->strikepos; + ZliTemp.strikewidth = Zli2->strikewidth; + ZliTemp.embedded = 0; for (int cx = 0; cx < coun; ++cx) { - Zli->xco = sPos + wt * cx; - if (e2.intersects(pf2.xForm(QRect(qRound(Zli->xco),qRound(Zli->yco-asce), qRound(Zli->wide+1), qRound(asce+desc))))) - DrawZeichenS(p, Zli); + ZliTemp.xco = sPos + wt * cx; + if (e2.intersects(pf2.xForm(QRect(qRound(ZliTemp.xco),qRound(ZliTemp.yco-asce), qRound(ZliTemp.wide+1), qRound(asce+desc))))) + DrawZeichenS(p, &ZliTemp); } - delete Zli; } if (Zli2->Zeich == QChar(9)) tabCc++; @@ -1804,38 +1803,37 @@ void PageItem_TextFrame::DrawObj_Item(Sc double wt = Cwidth(m_Doc, Zli2->ZFo, tabFillCharQStr, Zli2->Siz); int coun = static_cast<int>((Zli2->xco - tabDist) / wt); double sPos = Zli2->xco - (Zli2->xco - tabDist) + 1; - Zli = new ZZ; - Zli->Zeich = tabFillCharQStr; - Zli->Farb = Zli2->Farb; - Zli->Farb2 = Zli2->Farb2; - Zli->shade = Zli2->shade; - Zli->shade2 = Zli2->shade2; - Zli->yco = Zli2->yco; - Zli->Sele = Zli2->Sele; - Zli->Siz = Zli2->Siz; - Zli->realSiz = Zli2->realSiz; - Zli->Style = Zli2->Style; - Zli->ZFo = Zli2->ZFo; - Zli->wide = wt; - Zli->kern = 0; - Zli->scale = 1000; - Zli->scalev = 1000; - Zli->base = Zli2->base; - Zli->shadowX = Zli2->shadowX; - Zli->shadowY = Zli2->shadowY; - Zli->outline = Zli2->outline; - Zli->underpos = Zli2->underpos; - Zli->underwidth = Zli2->underwidth; - Zli->strikepos = Zli2->strikepos; - Zli->strikewidth = Zli2->strikewidth; - Zli->embedded = 0; + ZZ ZliTemp; + ZliTemp.Zeich = tabFillCharQStr; + ZliTemp.Farb = Zli2->Farb; + ZliTemp.Farb2 = Zli2->Farb2; + ZliTemp.shade = Zli2->shade; + ZliTemp.shade2 = Zli2->shade2; + ZliTemp.yco = Zli2->yco; + ZliTemp.Sele = Zli2->Sele; + ZliTemp.Siz = Zli2->Siz; + ZliTemp.realSiz = Zli2->realSiz; + ZliTemp.Style = Zli2->Style; + ZliTemp.ZFo = Zli2->ZFo; + ZliTemp.wide = wt; + ZliTemp.kern = 0; + ZliTemp.scale = 1000; + ZliTemp.scalev = 1000; + ZliTemp.base = Zli2->base; + ZliTemp.shadowX = Zli2->shadowX; + ZliTemp.shadowY = Zli2->shadowY; + ZliTemp.outline = Zli2->outline; + ZliTemp.underpos = Zli2->underpos; + ZliTemp.underwidth = Zli2->underwidth; + ZliTemp.strikepos = Zli2->strikepos; + ZliTemp.strikewidth = Zli2->strikewidth; + ZliTemp.embedded = 0; for (int cx = 0; cx < coun; ++cx) { - Zli->xco = sPos + wt * cx; - if (e2.intersects(pf2.xForm(QRect(qRound(Zli->xco),qRound(Zli->yco-asce), qRound(Zli->wide+1), qRound(asce+desc))))) - DrawZeichenS(p, Zli); + ZliTemp.xco = sPos + wt * cx; + if (e2.intersects(pf2.xForm(QRect(qRound(ZliTemp.xco),qRound(ZliTemp.yco-asce), qRound(ZliTemp.wide+1), qRound(asce+desc))))) + DrawZeichenS(p, &ZliTemp); } - delete Zli; } if (Zli2->Zeich == QChar(9)) tabCc++; @@ -1929,12 +1927,11 @@ void PageItem_TextFrame::DrawObj_Item(Sc m_Doc->RePos = true; NextBox->Dirty = false; QPixmap pgPix(1, 1); - ScPainter *painter = new ScPainter(&pgPix, 1, 1); - painter->translate(0.5, 0.5); - NextBox->DrawObj(painter, QRect(0, 0, 1, 1)); + ScPainter painter(&pgPix, 1, 1); + painter.translate(0.5, 0.5); + NextBox->DrawObj(&painter, QRect(0, 0, 1, 1)); NextBox->Dirty = true; - painter->end(); - delete painter; + painter.end(); p->restore(); m_Doc->RePos = rep; }/* Index: scribus.cpp =================================================================== RCS file: /cvs/Scribus/scribus/scribus.cpp,v retrieving revision 1.228.2.660 diff -p -u -r1.228.2.660 scribus.cpp --- scribus.cpp 2 Jan 2006 17:27:00 -0000 1.228.2.660 +++ scribus.cpp 2 Jan 2006 20:40:48 -0000 @@ -1078,10 +1078,10 @@ void ScribusMainWindow::specialActionKey { if (doc->selection->count() == 1) { - struct ScText *hg = new ScText; PageItem *currItem = doc->selection->itemAt(0); if (unicodevalue!=-1) { + ScText *hg = new ScText; hg->ch = QString(QChar(unicodevalue)); doc->setScTextDefaultsFromDoc(hg); hg->cselect = false; @@ -1601,36 +1601,35 @@ bool ScribusMainWindow::arrowKeyDown() void ScribusMainWindow::startUpDialog() { PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false); - NewDoc* dia = new NewDoc(this, true); - if (dia->exec()) + NewDoc dia(this, true); + if (dia.exec()) { - if (dia->tabSelected == 0) + if (dia.tabSelected == 0) { - int facingPages = dia->choosenLayout; - int firstPage = dia->docLayout->firstPage->currentItem(); - double topMargin = dia->GroupRand->RandT; - double bottomMargin = dia->GroupRand->RandB; - double leftMargin = dia->GroupRand->RandL; - double rightMargin = dia->GroupRand->RandR; - double columnDistance = dia->Dist; - double pageWidth = dia->Pagebr; - double pageHeight = dia->Pageho; - double numberCols = dia->SpinBox10->value(); - bool autoframes = dia->AutoFrame->isChecked(); - int orientation = dia->Orient; - int pageCount=dia->PgNum->value(); - PageSize *ps2 = new PageSize(dia->ComboBox1->currentText()); - QString pagesize = ps2->getPageName(); - doFileNew(pageWidth, pageHeight, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, numberCols, autoframes, facingPages, dia->ComboBox3->currentItem(), firstPage, orientation, dia->PgNr->value(), pagesize, pageCount); + int facingPages = dia.choosenLayout; + int firstPage = dia.docLayout->firstPage->currentItem(); + double topMargin = dia.GroupRand->RandT; + double bottomMargin = dia.GroupRand->RandB; + double leftMargin = dia.GroupRand->RandL; + double rightMargin = dia.GroupRand->RandR; + double columnDistance = dia.Dist; + double pageWidth = dia.Pagebr; + double pageHeight = dia.Pageho; + double numberCols = dia.SpinBox10->value(); + bool autoframes = dia.AutoFrame->isChecked(); + int orientation = dia.Orient; + int pageCount=dia.PgNum->value(); + PageSize ps2(dia.ComboBox1->currentText()); + QString pagesize = ps2.getPageName(); + doFileNew(pageWidth, pageHeight, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, numberCols, autoframes, facingPages, dia.ComboBox3->currentItem(), firstPage, orientation, dia.PgNr->value(), pagesize, pageCount); doc->pageSets[facingPages].FirstPage = firstPage; - delete ps2; HaveNewDoc(); } else { - if (dia->tabSelected == 1) + if (dia.tabSelected == 1) { - QString fileName(dia->fileDialog->selectedFile()); + QString fileName(dia.fileDialog->selectedFile()); if (!fileName.isEmpty()) { docContext->set("docsopen", fileName.left(fileName.findRev("/"))); @@ -1639,47 +1638,44 @@ void ScribusMainWindow::startUpDialog() } else { - QString fileName(dia->recentDocList->currentText()); + QString fileName(dia.recentDocList->currentText()); if (!fileName.isEmpty()) loadRecent(fileName); } } } - prefsManager->setShowStartupDialog(!dia->startUpDialog->isChecked()); - delete dia; + prefsManager->setShowStartupDialog(!dia.startUpDialog->isChecked()); mainWindowStatusLabel->setText( tr("Ready")); } bool ScribusMainWindow::slotFileNew() { bool retVal; - NewDoc* dia = new NewDoc(this); - if (dia->exec()) + NewDoc dia(this); + if (dia.exec()) { - int facingPages = dia->choosenLayout; - int firstPage = dia->docLayout->firstPage->currentItem(); - double topMargin = dia->GroupRand->RandT; - double bottomMargin = dia->GroupRand->RandB; - double leftMargin = dia->GroupRand->RandL; - double rightMargin = dia->GroupRand->RandR; - double columnDistance = dia->Dist; - double pageWidth = dia->Pagebr; - double pageHeight = dia->Pageho; - double numberCols = dia->SpinBox10->value(); - bool autoframes = dia->AutoFrame->isChecked(); - int orientation = dia->Orient; - int pageCount=dia->PgNum->value(); - PageSize *ps2 = new PageSize(dia->ComboBox1->currentText()); - QString pagesize = ps2->getPageName(); - retVal = doFileNew(pageWidth, pageHeight, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, numberCols, autoframes, facingPages, dia->ComboBox3->currentItem(), firstPage, orientation, dia->PgNr->value(), pagesize, pageCount); + int facingPages = dia.choosenLayout; + int firstPage = dia.docLayout->firstPage->currentItem(); + double topMargin = dia.GroupRand->RandT; + double bottomMargin = dia.GroupRand->RandB; + double leftMargin = dia.GroupRand->RandL; + double rightMargin = dia.GroupRand->RandR; + double columnDistance = dia.Dist; + double pageWidth = dia.Pagebr; + double pageHeight = dia.Pageho; + double numberCols = dia.SpinBox10->value(); + bool autoframes = dia.AutoFrame->isChecked(); + int orientation = dia.Orient; + int pageCount=dia.PgNum->value(); + PageSize ps2(dia.ComboBox1->currentText()); + QString pagesize = ps2.getPageName(); + retVal = doFileNew(pageWidth, pageHeight, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, numberCols, autoframes, facingPages, dia.ComboBox3->currentItem(), firstPage, orientation, dia.PgNr->value(), pagesize, pageCount); doc->pageSets[facingPages].FirstPage = firstPage; mainWindowStatusLabel->setText( tr("Ready")); - delete ps2; HaveNewDoc(); } else retVal = false; - delete dia; return retVal; } @@ -1908,13 +1904,12 @@ void ScribusMainWindow::windowsMenuActiv bool ScribusMainWindow::slotDocSetup() { bool ret = false; - ReformDoc* dia = new ReformDoc(this, doc); - Q_CHECK_PTR(dia); - if (dia->exec()) - { - slotChangeUnit(dia->getSelectedUnit(), false); - dia->updateDocumentSettings(); - if (dia->imageResolutionChanged()) + ReformDoc dia(this, doc); + if (dia.exec()) + { + slotChangeUnit(dia.getSelectedUnit(), false); + dia.updateDocumentSettings(); + if (dia.imageResolutionChanged()) view->RecalcPicturesRes(); FontSub->RebuildList(doc); propertiesPalette->Fonts->RebuildList(doc); @@ -1935,7 +1930,6 @@ bool ScribusMainWindow::slotDocSetup() slotDocCh(); ret = true; } - delete dia; return ret; } @@ -2811,31 +2805,31 @@ bool ScribusMainWindow::slotPageImport() { Q_ASSERT(!doc->masterPageMode()); bool ret = false; - MergeDoc *dia = new MergeDoc(this, false, doc->DocPages.count(), doc->currentPage->pageNr() + 1); - if (dia->exec()) + MergeDoc dia(this, false, doc->DocPages.count(), doc->currentPage->pageNr() + 1); + if (dia.exec()) { mainWindowStatusLabel->setText( tr("Importing Pages...")); qApp->setOverrideCursor(QCursor(waitCursor), true); std::vector<int> pageNs; - parsePagesString(dia->getPageNumbers(), &pageNs, dia->getPageCounter()); + parsePagesString(dia.getPageNumbers(), &pageNs, dia.getPageCounter()); int startPage, nrToImport; bool doIt = true; if (doc->masterPageMode()) { if (pageNs.size() > 1) - loadPage(dia->getFromDoc(), pageNs[0] - 1, false); + loadPage(dia.getFromDoc(), pageNs[0] - 1, false); doIt = false; } - else if (dia->getCreatePageChecked()) + else if (dia.getCreatePageChecked()) { - int importWhere=dia->getImportWhere(); + int importWhere=dia.getImportWhere(); if (importWhere == 0) - startPage = dia->getImportWherePage(); + startPage = dia.getImportWherePage(); else if (importWhere == 1) - startPage = dia->getImportWherePage() + 1; + startPage = dia.getImportWherePage() + 1; else startPage = doc->DocPages.count() + 1; - addNewPages(dia->getImportWherePage(), importWhere, pageNs.size(), doc->pageHeight, doc->pageWidth, doc->PageOri, doc->PageSize, true); + addNewPages(dia.getImportWherePage(), importWhere, pageNs.size(), doc->pageHeight, doc->pageWidth, doc->PageOri, doc->PageSize, true); nrToImport = pageNs.size(); } else @@ -2880,7 +2874,7 @@ bool ScribusMainWindow::slotPageImport() for (int i = 0; i < nrToImport; ++i) { view->GotoPa(counter); - loadPage(dia->getFromDoc(), pageNs[i] - 1, false); + loadPage(dia.getFromDoc(), pageNs[i] - 1, false); counter++; mainWindowProgressBar->setProgress(i + 1); } @@ -2897,7 +2891,6 @@ bool ScribusMainWindow::slotPageImport() qApp->setOverrideCursor(QCursor(arrowCursor), true); ret = doIt; } - delete dia; return ret; } @@ -2908,21 +2901,18 @@ bool ScribusMainWindow::loadPage(QString { if (!Mpa) doc->OpenNodes = outlinePalette->buildReopenVals(); - FileLoader *fl = new FileLoader(fileName); - if (fl->TestFile() == -1) + FileLoader fl(fileName); + if (fl.TestFile() == -1) { - delete fl; return false; } doc->setLoading(true); uint oldItemsCount = doc->Items->count(); - if(!fl->LoadPage(Nr, Mpa)) + if(!fl.LoadPage(Nr, Mpa)) { - delete fl; doc->setLoading(false); return false; } - delete fl; if (CMSavail && doc->CMSSettings.CMSinUse) { recalcColors(); @@ -3002,16 +2992,15 @@ bool ScribusMainWindow::loadDoc(QString if( !DPath.endsWith("/") ) DPath += "/"; QDir::setCurrent(DPath); - FileLoader *fileLoader = new FileLoader(FName); - if (fileLoader->TestFile() == -1) + FileLoader fileLoader(FName); + if (fileLoader.TestFile() == -1) { - delete fileLoader; qApp->setOverrideCursor(QCursor(arrowCursor), true); QMessageBox::critical(this, tr("Fatal Error"), "<qt>"+tr("File %1 is not in an acceptable format").arg(FName)+"</qt>", CommonStrings::tr_OK); return false; } bool is12doc=false; - if (fileLoader->TestFile() == 0) + if (fileLoader.TestFile() == 0) { qApp->setOverrideCursor(QCursor(arrowCursor), true); //Scribus 1.3.x warning, remove at a later stage @@ -3046,18 +3035,20 @@ bool ScribusMainWindow::loadDoc(QString CMSuse = false; #endif ScMW->ScriptRunning = true; - bool loadSuccess=fileLoader->LoadFile(); + bool loadSuccess=fileLoader.LoadFile(); //Do the font replacement check from here, when we have a GUI. TODO do this also somehow without the GUI //This also gives the user the opportunity to cancel the load when finding theres a replacement required. if (loadSuccess && ScQApp->usingGUI()) - loadSuccess=fileLoader->postLoad(is12doc); + loadSuccess=fileLoader.postLoad(is12doc); if(!loadSuccess) { view->close(); - delete fileLoader; delete view; + view = 0; delete doc; + doc = 0; delete w; + w = 0; ScMW->ScriptRunning = false; mainWindowStatusLabel->setText(""); mainWindowProgressBar->reset(); @@ -3066,7 +3057,7 @@ bool ScribusMainWindow::loadDoc(QString newActWin(ActWinOld); return false; } - fileLoader->informReplacementFonts(); + fileLoader.informReplacementFonts(); view->unitSwitcher->setCurrentText(unitGetStrFromIndex(doc->unitIndex())); view->unitChange(); ScMW->ScriptRunning = false; @@ -3228,7 +3219,7 @@ bool ScribusMainWindow::loadDoc(QString } propertiesPalette->updateColorList(); propertiesPalette->Cpal->ChooseGrad(0); - if (fileLoader->FileType > 1) + if (fileLoader.FileType > 1) { doc->setName(FName+tr("(converted)")); QFileInfo fi(doc->DocName); @@ -3253,7 +3244,7 @@ bool ScribusMainWindow::loadDoc(QString doc->RePos = true; QPixmap pgPix(10, 10); QRect rd = QRect(0,0,9,9); - ScPainter *painter = new ScPainter(&pgPix, pgPix.width(), pgPix.height()); + ScPainter painter(&pgPix, pgPix.width(), pgPix.height()); doc->setMasterPageMode(true); for (uint azz=0; azz<doc->MasterItems.count(); ++azz) { @@ -3283,7 +3274,7 @@ bool ScribusMainWindow::loadDoc(QString ite = nextItem; } } - ite->DrawObj(painter, rd); + ite->DrawObj(&painter, rd); } } // RestoreBookMarks(); @@ -3306,7 +3297,7 @@ bool ScribusMainWindow::loadDoc(QString { ite->Frame = true; ite->UpdatePolyClip(); - ite->DrawObj(painter, rd); + ite->DrawObj(&painter, rd); } else { @@ -3321,10 +3312,10 @@ bool ScribusMainWindow::loadDoc(QString break; } ite = nextItem; - ite->DrawObj(painter, rd); + ite->DrawObj(&painter, rd); } else - ite->DrawObj(painter, rd); + ite->DrawObj(&painter, rd); } } /* if (doc->OldBM) @@ -3348,10 +3339,9 @@ bool ScribusMainWindow::loadDoc(QString ite->Frame = true; ite->UpdatePolyClip(); } - ite->DrawObj(painter, rd); + ite->DrawObj(&painter, rd); } } - delete painter; // if (doc->OldBM) // StoreBookmarks(); doc->RePos = false; @@ -3363,12 +3353,11 @@ bool ScribusMainWindow::loadDoc(QString { Apply_MasterPage(doc->DocPages.at(p)->MPageNam, p, false); } - if (fileLoader->FileType > 1) + if (fileLoader.FileType > 1) { doc->hasName = false; slotFileSaveAs(); } - delete fileLoader; view->setUpdatesEnabled(true); w->setUpdatesEnabled(true); disconnect(wsp, SIGNAL(windowActivated(QWidget *)), this, SLOT(newActWin(QWidget *))); @@ -3490,9 +3479,7 @@ void ScribusMainWindow::slotGetContent() } if (currItem->asTextFrame()) { - gtGetText* gt = new gtGetText(); - gt->run(false); - delete gt; + gtGetText().run(false); if (doc->docHyphenator->AutoCheck) doc->docHyphenator->slotHyphenate(currItem); for (uint a = 0; a < doc->Items->count(); ++a) @@ -3520,9 +3507,7 @@ void ScribusMainWindow::slotFileAppend() { if (doc->selection->count() != 0) { - gtGetText* gt = new gtGetText(); - gt->run(true); - delete gt; + gtGetText().run(true); if (doc->docHyphenator->AutoCheck) doc->docHyphenator->slotHyphenate(doc->selection->itemAt(0)); view->DrawNew(); @@ -3692,8 +3677,8 @@ bool ScribusMainWindow::DoFileClose() view->close(); delete view; view = NULL; - doc = NULL; - ActWin = NULL; + doc = NULL; // TODO: is this truthful? + ActWin = NULL; // TODO: is this truthful? return true; } undoManager->removeStack(doc->DocName); @@ -3794,13 +3779,13 @@ bool ScribusMainWindow::DoFileClose() } view->close(); delete view; + view = 0; doc->setLoading(true); layerPalette->ClearInhalt(); docCheckerPalette->buildErrorList(0); HaveDoc--; - view = NULL; delete doc; - doc = NULL; + doc = 0; ActWin = NULL; tocGenerator->setDoc(doc); return true; @@ -3872,47 +3857,47 @@ void ScribusMainWindow::slotReallyPrint( ColorList usedSpots; doc->getUsedColors(usedSpots, true); QStringList spots = usedSpots.keys(); - Druck *printer = new Druck(this, options.filename, options.printer, PDef.Command, prefsManager->appPrefs.GCRMode, spots); - printer->setMinMax(1, doc->Pages->count(), doc->currentPage->pageNr()+1); + Druck printer(this, options.filename, options.printer, PDef.Command, prefsManager->appPrefs.GCRMode, spots); + printer.setMinMax(1, doc->Pages->count(), doc->currentPage->pageNr()+1); printDinUse = true; - connect(printer, SIGNAL(doPreview()), this, SLOT(doPrintPreview())); - if (printer->exec()) + connect(&printer, SIGNAL(doPreview()), this, SLOT(doPrintPreview())); + if (printer.exec()) { ReOrderText(doc, view); qApp->setOverrideCursor(QCursor(waitCursor), true); - options.printer = printer->printerName(); - options.filename = printer->outputFileName(); - options.toFile = printer->outputToFile(); - if (printer->CurrentPage->isChecked()) + options.printer = printer.printerName(); + options.filename = printer.outputFileName(); + options.toFile = printer.outputToFile(); + if (printer.CurrentPage->isChecked()) options.pageNumbers.push_back(doc->currentPage->pageNr()+1); else { - if (printer->RadioButton1->isChecked()) + if (printer.RadioButton1->isChecked()) parsePagesString("*", &options.pageNumbers, doc->DocPages.count()); else - parsePagesString(printer->PageNr->text(), &options.pageNumbers, doc->DocPages.count()); + parsePagesString(printer.PageNr->text(), &options.pageNumbers, doc->DocPages.count()); } - options.copies = printer->numCopies(); - options.outputSeparations = printer->outputSeparations(); - options.separationName = printer->separationName(); - options.allSeparations = printer->allSeparations(); + options.copies = printer.numCopies(); + options.outputSeparations = printer.outputSeparations(); + options.separationName = printer.separationName(); + options.allSeparations = printer.allSeparations(); if (options.outputSeparations) options.useSpotColors = true; else - options.useSpotColors = printer->doSpot(); - options.useColor = printer->color(); - options.mirrorH = printer->mirrorHorizontal(); - options.mirrorV = printer->mirrorVertical(); - options.useICC = printer->ICCinUse(); - options.doGCR = printer->doGCR(); - options.PSLevel = printer->PSLevel(); - options.setDevParam = printer->doDev(); + options.useSpotColors = printer.doSpot(); + options.useColor = printer.color(); + options.mirrorH = printer.mirrorHorizontal(); + options.mirrorV = printer.mirrorVertical(); + options.useICC = printer.ICCinUse(); + options.doGCR = printer.doGCR(); + options.PSLevel = printer.PSLevel(); + options.setDevParam = printer.doDev(); PDef.Pname = options.printer; PDef.Dname = options.filename; - if (printer->OtherCom->isChecked()) + if (printer.OtherCom->isChecked()) { - PDef.Command = printer->Command->text(); - options.printerCommand = printer->Command->text(); + PDef.Command = printer.Command->text(); + options.printerCommand = printer.Command->text(); options.useAltPrintCommand = true; } else @@ -3920,7 +3905,7 @@ void ScribusMainWindow::slotReallyPrint( options.useAltPrintCommand = false; } #ifdef HAVE_CUPS - options.printerOptions = printer->PrinterOpts; + options.printerOptions = printer.PrinterOpts; #endif #ifndef HAVE_CUPS options.printerOptions = QString(""); @@ -3934,8 +3919,7 @@ void ScribusMainWindow::slotReallyPrint( qApp->setOverrideCursor(QCursor(arrowCursor), true); } printDinUse = false; - disconnect(printer, SIGNAL(doPreview()), this, SLOT(doPrintPreview())); - delete printer; + disconnect(&printer, SIGNAL(doPreview()), this, SLOT(doPrintPreview())); mainWindowStatusLabel->setText( tr("Ready")); } @@ -3959,76 +3943,71 @@ bool ScribusMainWindow::doPrint(PrintOpt doc->getUsedColors(usedColors); fileWatcher->forceScan(); fileWatcher->stop(); - PSLib *dd = new PSLib(true, prefsManager->appPrefs.AvailFonts, ReallyUsed, usedColors, false, options->useSpotColors); - if (dd != NULL) + PSLib dd(true, prefsManager->appPrefs.AvailFonts, ReallyUsed, usedColors, false, options->useSpotColors); + if (!options->toFile) + filename = PrefsPfad+"/tmp.ps"; + else { - if (!options->toFile) - filename = PrefsPfad+"/tmp.ps"; - else + qApp->setOverrideCursor(QCursor(arrowCursor), true); + if (!overwrite(this, filename)) { - qApp->setOverrideCursor(QCursor(arrowCursor), true); - if (!overwrite(this, filename)) - { - delete dd; - fileWatcher->start(); + fileWatcher->start(); + return true; + } + qApp->setOverrideCursor(QCursor(waitCursor), true); + } + bool PSfile = dd.PS_set_file(filename); + filename = QDir::convertSeparators(filename); + if (PSfile) + { + // Write the PS to a file + ScColor::UseProf = options->useICC; + int psCreationRetVal=dd.CreatePS(doc, options->pageNumbers, options->outputSeparations, options->separationName, options->allSeparations, + options->useColor, options->mirrorH, options->mirrorV, options->useICC, options->doGCR, options->setDevParam); + if (psCreationRetVal!=0) + { + unlink(filename); + if (psCreationRetVal==2) return true; - } - qApp->setOverrideCursor(QCursor(waitCursor), true); + else + return false; } - bool PSfile = dd->PS_set_file(filename); - filename = QDir::convertSeparators(filename); - if (PSfile) - { - // Write the PS to a file - ScColor::UseProf = options->useICC; - int psCreationRetVal=dd->CreatePS(doc, options->pageNumbers, options->outputSeparations, options->separationName, options->allSeparations, - options->useColor, options->mirrorH, options->mirrorV, options->useICC, options->doGCR, options->setDevParam); - if (psCreationRetVal!=0) - { - unlink(filename); - if (psCreationRetVal==2) - return true; - else - return false; + ScColor::UseProf = true; + if (options->PSLevel != 3) + { + // use gs to convert our PS to a lower version + QString tmp; + QStringList opts; + opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc->pageWidth)) ); + opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc->pageHeight)) ); + convertPS2PS(filename, filename + ".tmp", opts, options->PSLevel); + moveFile( filename + ".tmp", filename ); + } + if (!options->toFile) + { + // print and delete the PS file + QString cmd; + if (options->useAltPrintCommand) + { + cmd = options->printerCommand + " "+filename; + system(cmd); } - ScColor::UseProf = true; - if (options->PSLevel != 3) + else { - // use gs to convert our PS to a lower version - QString tmp; - QStringList opts; - opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc->pageWidth)) ); - opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc->pageHeight)) ); - convertPS2PS(filename, filename + ".tmp", opts, options->PSLevel); - moveFile( filename + ".tmp", filename ); - } - if (!options->toFile) - { - // print and delete the PS file - QString cmd; - if (options->useAltPrintCommand) - { - cmd = options->printerCommand + " "+filename; - system(cmd); - } - else - { - QString cc; - cmd = "lpr -P" + options->printer; - if (options->copies > 1) - cmd += " -#" + cc.setNum(options->copies); - cmd += options->printerOptions; - cmd += " "+filename; - system(cmd); - } - unlink(filename); + QString cc; + cmd = "lpr -P" + options->printer; + if (options->copies > 1) + cmd += " -#" + cc.setNum(options->copies); + cmd += options->printerOptions; + cmd += " "+filename; + system(cmd); } - retw = true; + unlink(filename); } - else - retw = false; - delete dd; + retw = true; } + else + retw = false; fileWatcher->start(); return retw; } @@ -4134,9 +4113,7 @@ void ScribusMainWindow::slotEditCut() { if (currItem->isTableItem && currItem->isSingleSel) return; - ScriXmlDoc *ss = new ScriXmlDoc(); - BufferI = ss->WriteElem(doc, view, doc->selection); - Buffer2 = BufferI; + Buffer2 = BufferI = ScriXmlDoc().WriteElem(doc, view, doc->selection); view->DeleteItem(); } slotDocCh(); @@ -4218,10 +4195,7 @@ void ScribusMainWindow::slotEditCopy() { if (currItem->isTableItem && currItem->isSingleSel) return; - ScriXmlDoc *ss = new ScriXmlDoc(); - BufferI = ss->WriteElem(doc, view, doc->selection); - Buffer2 = BufferI; - delete ss; + Buffer2 = BufferI = ScriXmlDoc().WriteElem(doc, view, doc->selection); } BuFromApp = true; ClipB->setText(BufferI); @@ -4311,7 +4285,7 @@ void ScribusMainWindow::slotEditPaste() hg->cstrikepos = it == NULL ? -1 : (*it).toInt(); it++; hg->cstrikewidth = it == NULL ? -1 : (*it).toInt(); - currItem->itemText.insert(currItem->CPos, hg); + currItem->itemText.insert(currItem->CPos, hg); // takes ownership of `hg' currItem->CPos += 1; hg->PRot = 0; hg->PtransX = 0; @@ -4387,19 +4361,18 @@ void ScribusMainWindow::slotEditPaste() hg->PtransY = 0; hg->cextra = 0; hg->cembedded = currItem3; - currItem->itemText.insert(currItem->CPos, hg); + currItem->itemText.insert(currItem->CPos, hg); // takes ownership of `hg' currItem->CPos += 1; } else { - Serializer *ss = new Serializer(""); - ss->Objekt = Buffer2; + Serializer ss(""); + ss.Objekt = Buffer2; int st = doc->currentParaStyle; if (st > 5) - ss->GetText(currItem, st, doc->docParagraphStyles[st].Font, doc->docParagraphStyles[st].FontSize, true); + ss.GetText(currItem, st, doc->docParagraphStyles[st].Font, doc->docParagraphStyles[st].FontSize, true); else - ss->GetText(currItem, st, currItem->font(), currItem->fontSize(), true); - delete ss; + ss.GetText(currItem, st, currItem->font(), currItem->fontSize(), true); } view->RefreshItem(currItem); } @@ -4539,16 +4512,12 @@ void ScribusMainWindow::DisableTxEdit() void ScribusMainWindow::slotHelpAbout() { - About* dia = new About(this); - dia->exec(); - delete dia; + About(this).exec(); } void ScribusMainWindow::slotHelpAboutPlugins() { - AboutPlugins* dia = new AboutPlugins(this); - dia->exec(); - delete dia; + AboutPlugins(this).exec(); } void ScribusMainWindow::slotHelpAboutQt() @@ -4558,6 +4527,9 @@ void ScribusMainWindow::slotHelpAboutQt( void ScribusMainWindow::slotOnlineHelp() { + // FIXME: LEAK: it looks like we probably leak helpbrowser here, unless + // it's deleted from somewhere else. It doesn't appear to delete its self + // on close. HelpBrowser *dia = new HelpBrowser(0, tr("Scribus Manual"), ScMW->guiLanguage); dia->show(); } @@ -4581,10 +4553,9 @@ void ScribusMainWindow::SaveText() if (!fn.isEmpty()) { dirs->set("save_text", fn.left(fn.findRev("/"))); - Serializer *se = new Serializer(fn); - se->PutText(doc->selection->itemAt(0)); - se->Write(LoadEnc); - delete se; + Serializer se(fn); + se.PutText(doc->selection->itemAt(0)); + se.Write(LoadEnc); } } @@ -4612,22 +4583,21 @@ void ScribusMainWindow::slotNewPageM() NoFrameEdit(); view->Deselect(true); QStringList base; - InsPage *dia = new InsPage(this, doc, doc->currentPage->pageNr(), doc->Pages->count()); - if (dia->exec()) + InsPage dia(this, doc, doc->currentPage->pageNr(), doc->Pages->count()); + if (dia.exec()) { - base = dia->getMasterPages(); - addNewPages(dia->getWherePage(), - dia->getWhere(), - dia->getCount(), - dia->heightMSpinBox->value() / doc->unitRatio(), - dia->widthMSpinBox->value() / doc->unitRatio(), - dia->orientationQComboBox->currentItem(), - dia->prefsPageSizeName, - dia->moveObjects->isChecked(), + base = dia.getMasterPages(); + addNewPages(dia.getWherePage(), + dia.getWhere(), + dia.getCount(), + dia.heightMSpinBox->value() / doc->unitRatio(), + dia.widthMSpinBox->value() / doc->unitRatio(), + dia.orientationQComboBox->currentItem(), + dia.prefsPageSizeName, + dia.moveObjects->isChecked(), &base ); } - delete dia; } void ScribusMainWindow::addNewPages(int wo, int where, int numPages, double height, double width, int orient, QString siz, bool mov, QStringList* basedOn) @@ -4722,34 +4692,32 @@ void ScribusMainWindow::slotNewPage(int void ScribusMainWindow::duplicateToMasterPage() { - NewTm *dia = new NewTm(this, tr("Name:"), tr("Convert Page to Master Page"), doc); - dia->Answer->setText( tr("New Master Page")); - dia->Answer->selectAll(); + NewTm dia(this, tr("Name:"), tr("Convert Page to Master Page"), doc); + dia.Answer->setText( tr("New Master Page")); + dia.Answer->selectAll(); view->Deselect(true); - if (dia->exec()) + if (dia.exec()) { int diaLinksCurrItem=0; int diaLinksCount=0; if (doc->currentPageLayout != singlePage) { - diaLinksCurrItem=dia->Links->currentItem(); - diaLinksCount=static_cast<int>(dia->Links->count()); + diaLinksCurrItem=dia.Links->currentItem(); + diaLinksCount=static_cast<int>(dia.Links->count()); } - QString masterPageName = dia->Answer->text(); + QString masterPageName = dia.Answer->text(); while (doc->MasterNames.contains(masterPageName) || (masterPageName == "Normal")) { - if (!dia->exec()) + if (!dia.exec()) { - delete dia; return; } - masterPageName = dia->Answer->text(); + masterPageName = dia.Answer->text(); } int currentPageNumber=doc->currentPage->pageNr(); bool ok=doc->copyPageToMasterPage(currentPageNumber, diaLinksCurrItem, diaLinksCount, masterPageName); Q_ASSERT(ok); //TODO get a return value in case the copy was not possible } - delete dia; } /*! @@ -5530,10 +5498,9 @@ void ScribusMainWindow::DeletePage() { NoFrameEdit(); view->Deselect(true); - DelPages *dia = new DelPages(this, doc->currentPage->pageNr()+1, doc->Pages->count()); - if (dia->exec()) - DeletePage(dia->getFromPage(), dia->getToPage()); - delete dia; + DelPages dia(this, doc->currentPage->pageNr()+1, doc->Pages->count()); + if (dia.exec()) + DeletePage(dia.getFromPage(), dia.getToPage()); } void ScribusMainWindow::DeletePage(int from, int to) @@ -5605,14 +5572,14 @@ void ScribusMainWindow::DeletePage(int f void ScribusMainWindow::MovePage() { NoFrameEdit(); - MovePages *dia = new MovePages(this, doc->currentPage->pageNr()+1, doc->Pages->count(), true); - if (dia->exec()) + MovePages dia(this, doc->currentPage->pageNr()+1, doc->Pages->count(), true); + if (dia.exec()) { // doc->OpenNodes = outlinePalette->buildReopenVals(); - int from = dia->getFromPage(); - int to = dia->getToPage(); - int wie = dia->getWhere(); - int wo = dia->getWherePage(); + int from = dia.getFromPage(); + int to = dia.getToPage(); + int wie = dia.getWhere(); + int wo = dia.getWherePage(); if ((from != wo) || (wie == 2)) { doc->movePage(from-1, to, wo-1, wie); @@ -5625,19 +5592,18 @@ void ScribusMainWindow::MovePage() outlinePalette->BuildTree(); outlinePalette->reopenTree(doc->OpenNodes); } - delete dia; } void ScribusMainWindow::CopyPage() { NoFrameEdit(); - MovePages *dia = new MovePages(this, doc->currentPage->pageNr()+1, doc->Pages->count(), false); - if (dia->exec()) + MovePages dia(this, doc->currentPage->pageNr()+1, doc->Pages->count(), false); + if (dia.exec()) { - int pageNumberToCopy=dia->getFromPage()-1; - int whereToInsert=dia->getWhere(); - int copyCount=dia->getCopyCount(); - int wo = dia->getWherePage(); + int pageNumberToCopy=dia.getFromPage()-1; + int whereToInsert=dia.getWhere(); + int copyCount=dia.getCopyCount(); + int wo = dia.getWherePage(); doc->copyPage(pageNumberToCopy, wo, whereToInsert, copyCount); view->Deselect(true); view->DrawNew(); @@ -5646,37 +5612,35 @@ void ScribusMainWindow::CopyPage() outlinePalette->BuildTree(); AdjustBM(); } - delete dia; } void ScribusMainWindow::changePageMargins() { int lp; NoFrameEdit(); - MarginDialog *dia = new MarginDialog(this, doc); - if (dia->exec()) + MarginDialog dia(this, doc); + if (dia.exec()) { if (doc->masterPageMode()) { if (doc->currentPageLayout != singlePage) { - lp = dia->Links->currentItem(); + lp = dia.Links->currentItem(); if (lp == 0) lp = 1; - else if (lp == static_cast<int>(dia->Links->count()-1)) + else if (lp == static_cast<int>(dia.Links->count()-1)) lp = 0; else lp++; } - doc->changePageMargins(dia->GroupRand->RandT, dia->GroupRand->RandB, dia->GroupRand->RandL, dia->GroupRand->RandR, dia->pageHeight, dia->pageWidth, dia->pageHeight, dia->pageWidth, dia->orientationQComboBox->currentItem(), dia->prefsPageSizeName, doc->currentPage->pageNr(), lp); + doc->changePageMargins(dia.GroupRand->RandT, dia.GroupRand->RandB, dia.GroupRand->RandL, dia.GroupRand->RandR, dia.pageHeight, dia.pageWidth, dia.pageHeight, dia.pageWidth, dia.orientationQComboBox->currentItem(), dia.prefsPageSizeName, doc->currentPage->pageNr(), lp); } else - doc->changePageMargins(dia->GroupRand->RandT, dia->GroupRand->RandB, dia->GroupRand->RandL, dia->GroupRand->RandR, dia->pageHeight, dia->pageWidth, dia->pageHeight, dia->pageWidth, dia->orientationQComboBox->currentItem(), dia->prefsPageSizeName, doc->currentPage->pageNr()); - view->reformPages(dia->moveObjects->isChecked()); + doc->changePageMargins(dia.GroupRand->RandT, dia.GroupRand->RandB, dia.GroupRand->RandL, dia.GroupRand->RandR, dia.pageHeight, dia.pageWidth, dia.pageHeight, dia.pageWidth, dia.orientationQComboBox->currentItem(), dia.prefsPageSizeName, doc->currentPage->pageNr()); + view->reformPages(dia.moveObjects->isChecked()); view->DrawNew(); slotDocCh(); } - delete dia; } void ScribusMainWindow::setItemFont2(int id) @@ -5747,13 +5711,12 @@ void ScribusMainWindow::setItemFSize(int else { bool ok = false; - Query* dia = new Query(this, "New", 1, 0, tr("&Size:"), tr("Size")); - if (dia->exec()) + Query dia(this, "New", 1, 0, tr("&Size:"), tr("Size")); + if (dia.exec()) { - c = qRound(dia->getEditText().toDouble(&ok)); + c = qRound(dia.getEditText().toDouble(&ok)); if ((ok) && (c < 1025) && (c > 0)) view->chFSize(c*10); - delete dia; } } propertiesPalette->setSize(c*10); @@ -5796,10 +5759,10 @@ void ScribusMainWindow::setItemShade(int } else { - Query* dia = new Query(this, "New", 1, 0, tr("&Shade:"), tr("Shade")); - if (dia->exec()) + Query dia(this, "New", 1, 0, tr("&Shade:"), tr("Shade")); + if (dia.exec()) { - c = dia->getEditText().toInt(&ok); + c = dia.getEditText().toInt(&ok); if (ok) { if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText)) @@ -5807,7 +5770,6 @@ void ScribusMainWindow::setItemShade(int else view->ItemBrushShade(c); } - delete dia; } } } @@ -5862,26 +5824,25 @@ void ScribusMainWindow::slotEditLineStyl { if (HaveDoc) { - LineFormate *dia = new LineFormate(this, doc); - connect(dia, SIGNAL(saveStyle(LineFormate *)), this, SLOT(saveLStyles(LineFormate *))); - if (dia->exec()) + LineFormate dia(this, doc); + connect(&dia, SIGNAL(saveStyle(LineFormate&)), this, SLOT(saveLStyles(LineFormate&))); + if (dia.exec()) saveLStyles(dia); - disconnect(dia, SIGNAL(saveStyle(LineFormate *)), this, SLOT(saveLStyles(LineFormate *))); - delete dia; + disconnect(&dia, SIGNAL(saveStyle(LineFormate&)), this, SLOT(saveLStyles(LineFormate&))); } } -void ScribusMainWindow::saveLStyles(LineFormate *dia) +void ScribusMainWindow::saveLStyles(LineFormate & dia) { PageItem* ite; - doc->MLineStyles = dia->TempStyles; + doc->MLineStyles = dia.TempStyles; for (uint d = 0; d < doc->DocItems.count(); ++d) { ite = doc->DocItems.at(d); if (!ite->NamedLStyle.isEmpty()) { if (!doc->MLineStyles.contains(ite->NamedLStyle)) - ite->NamedLStyle = dia->Replacement[ite->NamedLStyle]; + ite->NamedLStyle = dia.Replacement[ite->NamedLStyle]; } } for (uint d1 = 0; d1 < doc->MasterItems.count(); ++d1) @@ -5890,7 +5851,7 @@ void ScribusMainWindow::saveLStyles(Line if (!ite->NamedLStyle.isEmpty()) { if (!doc->MLineStyles.contains(ite->NamedLStyle)) - ite->NamedLStyle = dia->Replacement[ite->NamedLStyle]; + ite->NamedLStyle = dia.Replacement[ite->NamedLStyle]; } } for (uint d1 = 0; d1 < doc->FrameItems.count(); ++d1) @@ -5899,7 +5860,7 @@ void ScribusMainWindow::saveLStyles(Line if (!ite->NamedLStyle.isEmpty()) { if (!doc->MLineStyles.contains(ite->NamedLStyle)) - ite->NamedLStyle = dia->Replacement[ite->NamedLStyle]; + ite->NamedLStyle = dia.Replacement[ite->NamedLStyle]; } } propertiesPalette->SetLineFormats(doc); @@ -5910,16 +5871,15 @@ void ScribusMainWindow::slotEditStyles() { if (HaveDoc) { - StilFormate *dia = new StilFormate(this, doc); - connect(dia, SIGNAL(saveStyle(StilFormate *)), this, SLOT(saveStyles(StilFormate *))); - if (dia->exec()) + StilFormate dia(this, doc); + connect(&dia, SIGNAL(saveStyle(StilFormate&)), this, SLOT(saveStyles(StilFormate&))); + if (dia.exec()) saveStyles(dia); - disconnect(dia, SIGNAL(saveStyle(StilFormate *)), this, SLOT(saveStyles(StilFormate *))); - delete dia; + disconnect(&dia, SIGNAL(saveStyle(StilFormate&)), this, SLOT(saveStyles(StilFormate&))); } } -void ScribusMainWindow::saveStyles(StilFormate *dia) +void ScribusMainWindow::saveStyles(StilFormate & dia) { QValueList<uint> ers; QString nn; @@ -5937,9 +5897,9 @@ void ScribusMainWindow::saveStyles(StilF { ff = false; nn = doc->docParagraphStyles[a].Vname; - for (uint b=0; b<dia->TempVorl.count(); ++b) + for (uint b=0; b<dia.TempVorl.count(); ++b) { - if (nn == dia->TempVorl[b].Vname) + if (nn == dia.TempVorl[b].Vname) { nr = b; ff = true; @@ -5950,19 +5910,19 @@ void ScribusMainWindow::saveStyles(StilF ers.append(nr); else { - for (uint b=0; b<dia->TempVorl.count(); ++b) + for (uint b=0; b<dia.TempVorl.count(); ++b) { struct PageItem::TabRecord tb; tabEQ = false; - if ((doc->docParagraphStyles[a].TabValues.count() == 0) && (dia->TempVorl[b].TabValues.count() == 0)) + if ((doc->docParagraphStyles[a].TabValues.count() == 0) && (dia.TempVorl[b].TabValues.count() == 0)) tabEQ = true; else { - for (uint t1 = 0; t1 < dia->TempVorl[b].TabValues.count(); t1++) + for (uint t1 = 0; t1 < dia.TempVorl[b].TabValues.count(); t1++) { - tb.tabPosition = dia->TempVorl[b].TabValues[t1].tabPosition; - tb.tabType = dia->TempVorl[b].TabValues[t1].tabType; - tb.tabFillChar = dia->TempVorl[b].TabValues[t1].tabFillChar; + tb.tabPosition = dia.TempVorl[b].TabValues[t1].tabPosition; + tb.tabType = dia.TempVorl[b].TabValues[t1].tabType; + tb.tabFillChar = dia.TempVorl[b].TabValues[t1].tabFillChar; for (uint t2 = 0; t2 < doc->docParagraphStyles[a].TabValues.count(); t2++) { struct PageItem::TabRecord tb2; @@ -5979,35 +5939,35 @@ void ScribusMainWindow::saveStyles(StilF break; } } - if ((doc->docParagraphStyles[a].LineSpa == dia->TempVorl[b].LineSpa) && - (doc->docParagraphStyles[a].LineSpaMode == dia->TempVorl[b].LineSpaMode) && - (doc->docParagraphStyles[a].Indent == dia->TempVorl[b].Indent) && - (doc->docParagraphStyles[a].First == dia->TempVorl[b].First) && - (doc->docParagraphStyles[a].textAlignment == dia->TempVorl[b].textAlignment) && - (doc->docParagraphStyles[a].gapBefore == dia->TempVorl[b].gapBefore) && - (doc->docParagraphStyles[a].gapAfter == dia->TempVorl[b].gapAfter) && - (doc->docParagraphStyles[a].Font == dia->TempVorl[b].Font) && - (tabEQ) && (doc->docParagraphStyles[a].DropDist == dia->TempVorl[b].DropDist) && - (doc->docParagraphStyles[a].Drop == dia->TempVorl[b].Drop) && - (doc->docParagraphStyles[a].DropLin == dia->TempVorl[b].DropLin) && - (doc->docParagraphStyles[a].FontEffect == dia->TempVorl[b].FontEffect) && - (doc->docParagraphStyles[a].FColor == dia->TempVorl[b].FColor) && - (doc->docParagraphStyles[a].FShade == dia->TempVorl[b].FShade) && - (doc->docParagraphStyles[a].SColor == dia->TempVorl[b].SColor) && - (doc->docParagraphStyles[a].SShade == dia->TempVorl[b].SShade) && - (doc->docParagraphStyles[a].BaseAdj == dia->TempVorl[b].BaseAdj) && - (doc->docParagraphStyles[a].txtShadowX == dia->TempVorl[b].txtShadowX) && - (doc->docParagraphStyles[a].txtShadowY == dia->TempVorl[b].txtShadowY) && - (doc->docParagraphStyles[a].txtOutline == dia->TempVorl[b].txtOutline) && - (doc->docParagraphStyles[a].txtUnderPos == dia->TempVorl[b].txtUnderPos) && - (doc->docParagraphStyles[a].txtUnderWidth == dia->TempVorl[b].txtUnderWidth) && - (doc->docParagraphStyles[a].txtStrikePos == dia->TempVorl[b].txtStrikePos) && - (doc->docParagraphStyles[a].txtStrikeWidth == dia->TempVorl[b].txtStrikeWidth) && - (doc->docParagraphStyles[a].scaleH == dia->TempVorl[b].scaleH) && - (doc->docParagraphStyles[a].scaleV == dia->TempVorl[b].scaleV) && - (doc->docParagraphStyles[a].baseOff == dia->TempVorl[b].baseOff) && - (doc->docParagraphStyles[a].kernVal == dia->TempVorl[b].kernVal) && - (doc->docParagraphStyles[a].FontSize == dia->TempVorl[b].FontSize)) + if ((doc->docParagraphStyles[a].LineSpa == dia.TempVorl[b].LineSpa) && + (doc->docParagraphStyles[a].LineSpaMode == dia.TempVorl[b].LineSpaMode) && + (doc->docParagraphStyles[a].Indent == dia.TempVorl[b].Indent) && + (doc->docParagraphStyles[a].First == dia.TempVorl[b].First) && + (doc->docParagraphStyles[a].textAlignment == dia.TempVorl[b].textAlignment) && + (doc->docParagraphStyles[a].gapBefore == dia.TempVorl[b].gapBefore) && + (doc->docParagraphStyles[a].gapAfter == dia.TempVorl[b].gapAfter) && + (doc->docParagraphStyles[a].Font == dia.TempVorl[b].Font) && + (tabEQ) && (doc->docParagraphStyles[a].DropDist == dia.TempVorl[b].DropDist) && + (doc->docParagraphStyles[a].Drop == dia.TempVorl[b].Drop) && + (doc->docParagraphStyles[a].DropLin == dia.TempVorl[b].DropLin) && + (doc->docParagraphStyles[a].FontEffect == dia.TempVorl[b].FontEffect) && + (doc->docParagraphStyles[a].FColor == dia.TempVorl[b].FColor) && + (doc->docParagraphStyles[a].FShade == dia.TempVorl[b].FShade) && + (doc->docParagraphStyles[a].SColor == dia.TempVorl[b].SColor) && + (doc->docParagraphStyles[a].SShade == dia.TempVorl[b].SShade) && + (doc->docParagraphStyles[a].BaseAdj == dia.TempVorl[b].BaseAdj) && + (doc->docParagraphStyles[a].txtShadowX == dia.TempVorl[b].txtShadowX) && + (doc->docParagraphStyles[a].txtShadowY == dia.TempVorl[b].txtShadowY) && + (doc->docParagraphStyles[a].txtOutline == dia.TempVorl[b].txtOutline) && + (doc->docParagraphStyles[a].txtUnderPos == dia.TempVorl[b].txtUnderPos) && + (doc->docParagraphStyles[a].txtUnderWidth == dia.TempVorl[b].txtUnderWidth) && + (doc->docParagraphStyles[a].txtStrikePos == dia.TempVorl[b].txtStrikePos) && + (doc->docParagraphStyles[a].txtStrikeWidth == dia.TempVorl[b].txtStrikeWidth) && + (doc->docParagraphStyles[a].scaleH == dia.TempVorl[b].scaleH) && + (doc->docParagraphStyles[a].scaleV == dia.TempVorl[b].scaleV) && + (doc->docParagraphStyles[a].baseOff == dia.TempVorl[b].baseOff) && + (doc->docParagraphStyles[a].kernVal == dia.TempVorl[b].kernVal) && + (doc->docParagraphStyles[a].FontSize == dia.TempVorl[b].FontSize)) { nr = b; ff = true; @@ -6018,16 +5978,16 @@ void ScribusMainWindow::saveStyles(StilF ers.append(nr); else { - if (dia->ReplaceList.count() != 0) + if (dia.ReplaceList.count() != 0) { - QString ne = dia->ReplaceList[nn]; + QString ne = dia.ReplaceList[nn]; if (ne == tr("No Style")) ers.append(0); else { - for (uint b=0; b<dia->TempVorl.count(); ++b) + for (uint b=0; b<dia.TempVorl.count(); ++b) { - if (ne == dia->TempVorl[b].Vname) + if (ne == dia.TempVorl[b].Vname) { nr = b; ff = true; @@ -6085,44 +6045,44 @@ void ScribusMainWindow::saveStyles(StilF if (cabneu > 0) { if (ite->itemText.at(e)->cfont == (*doc->AllFonts)[doc->docParagraphStyles[cabori].Font]) - ite->itemText.at(e)->cfont = (*doc->AllFonts)[dia->TempVorl[cabneu].Font]; + ite->itemText.at(e)->cfont = (*doc->AllFonts)[dia.TempVorl[cabneu].Font]; if (ite->itemText.at(e)->csize == doc->docParagraphStyles[cabori].FontSize) - ite->itemText.at(e)->csize = dia->TempVorl[cabneu].FontSize; + ite->itemText.at(e)->csize = dia.TempVorl[cabneu].FontSize; if ((ite->itemText.at(e)->cstyle & 1919 ) == doc->docParagraphStyles[cabori].FontEffect) { ite->itemText.at(e)->cstyle &= ~1919; - ite->itemText.at(e)->cstyle |= dia->TempVorl[cabneu].FontEffect; + ite->itemText.at(e)->cstyle |= dia.TempVorl[cabneu].FontEffect; } if (ite->itemText.at(e)->ccolor == doc->docParagraphStyles[cabori].FColor) - ite->itemText.at(e)->ccolor = dia->TempVorl[cabneu].FColor; + ite->itemText.at(e)->ccolor = dia.TempVorl[cabneu].FColor; if (ite->itemText.at(e)->cshade == doc->docParagraphStyles[cabori].FShade) - ite->itemText.at(e)->cshade = dia->TempVorl[cabneu].FShade; + ite->itemText.at(e)->cshade = dia.TempVorl[cabneu].FShade; if (ite->itemText.at(e)->cstroke == doc->docParagraphStyles[cabori].SColor) - ite->itemText.at(e)->cstroke = dia->TempVorl[cabneu].SColor; + ite->itemText.at(e)->cstroke = dia.TempVorl[cabneu].SColor; if (ite->itemText.at(e)->cshade2 == doc->docParagraphStyles[cabori].SShade) - ite->itemText.at(e)->cshade2 = dia->TempVorl[cabneu].SShade; + ite->itemText.at(e)->cshade2 = dia.TempVorl[cabneu].SShade; if (ite->itemText.at(e)->cshadowx == doc->docParagraphStyles[cabori].txtShadowX) - ite->itemText.at(e)->cshadowx = dia->TempVorl[cabneu].txtShadowX; + ite->itemText.at(e)->cshadowx = dia.TempVorl[cabneu].txtShadowX; if (ite->itemText.at(e)->cshadowy == doc->docParagraphStyles[cabori].txtShadowY) - ite->itemText.at(e)->cshadowy = dia->TempVorl[cabneu].txtShadowY; + ite->itemText.at(e)->cshadowy = dia.TempVorl[cabneu].txtShadowY; if (ite->itemText.at(e)->coutline == doc->docParagraphStyles[cabori].txtOutline) - ite->itemText.at(e)->coutline = dia->TempVorl[cabneu].txtOutline; + ite->itemText.at(e)->coutline = dia.TempVorl[cabneu].txtOutline; if (ite->itemText.at(e)->cunderpos == doc->docParagraphStyles[cabori].txtUnderPos) - ite->itemText.at(e)->cunderpos = dia->TempVorl[cabneu].txtUnderPos; + ite->itemText.at(e)->cunderpos = dia.TempVorl[cabneu].txtUnderPos; if (ite->itemText.at(e)->cunderwidth == doc->docParagraphStyles[cabori].txtUnderWidth) - ite->itemText.at(e)->cunderwidth = dia->TempVorl[cabneu].txtUnderWidth; + ite->itemText.at(e)->cunderwidth = dia.TempVorl[cabneu].txtUnderWidth; if (ite->itemText.at(e)->cstrikepos == doc->docParagraphStyles[cabori].txtStrikePos) - ite->itemText.at(e)->cstrikepos = dia->TempVorl[cabneu].txtStrikePos; + ite->itemText.at(e)->cstrikepos = dia.TempVorl[cabneu].txtStrikePos; if (ite->itemText.at(e)->cstrikewidth == doc->docParagraphStyles[cabori].txtStrikeWidth) - ite->itemText.at(e)->cstrikewidth = dia->TempVorl[cabneu].txtStrikeWidth; + ite->itemText.at(e)->cstrikewidth = dia.TempVorl[cabneu].txtStrikeWidth; if (ite->itemText.at(e)->cscale == doc->docParagraphStyles[cabori].scaleH) - ite->itemText.at(e)->cscale = dia->TempVorl[cabneu].scaleH; + ite->itemText.at(e)->cscale = dia.TempVorl[cabneu].scaleH; if (ite->itemText.at(e)->cscalev == doc->docParagraphStyles[cabori].scaleV) - ite->itemText.at(e)->cscalev = dia->TempVorl[cabneu].scaleV; + ite->itemText.at(e)->cscalev = dia.TempVorl[cabneu].scaleV; if (ite->itemText.at(e)->cbase == doc->docParagraphStyles[cabori].baseOff) - ite->itemText.at(e)->cbase = dia->TempVorl[cabneu].baseOff; + ite->itemText.at(e)->cbase = dia.TempVorl[cabneu].baseOff; if (ite->itemText.at(e)->cextra == doc->docParagraphStyles[cabori].kernVal) - ite->itemText.at(e)->cextra = dia->TempVorl[cabneu].kernVal; + ite->itemText.at(e)->cextra = dia.TempVorl[cabneu].kernVal; } else { @@ -6170,44 +6130,44 @@ void ScribusMainWindow::saveStyles(StilF if (cabneu > 0) { if (chars->at(e)->cfont == doc->docParagraphStyles[cabori].Font) - chars->at(e)->cfont = dia->TempVorl[cabneu].Font; + chars->at(e)->cfont = dia.TempVorl[cabneu].Font; if (chars->at(e)->csize == doc->docParagraphStyles[cabori].FontSize) - chars->at(e)->csize = dia->TempVorl[cabneu].FontSize; + chars->at(e)->csize = dia.TempVorl[cabneu].FontSize; if ((chars->at(e)->cstyle & 1919 ) == doc->docParagraphStyles[cabori].FontEffect) { chars->at(e)->cstyle &= ~1919; - chars->at(e)->cstyle |= dia->TempVorl[cabneu].FontEffect; + chars->at(e)->cstyle |= dia.TempVorl[cabneu].FontEffect; } if (chars->at(e)->ccolor == doc->docParagraphStyles[cabori].FColor) - chars->at(e)->ccolor = dia->TempVorl[cabneu].FColor; + chars->at(e)->ccolor = dia.TempVorl[cabneu].FColor; if (chars->at(e)->cshade == doc->docParagraphStyles[cabori].FShade) - chars->at(e)->cshade = dia->TempVorl[cabneu].FShade; + chars->at(e)->cshade = dia.TempVorl[cabneu].FShade; if (chars->at(e)->cstroke == doc->docParagraphStyles[cabori].SColor) - chars->at(e)->cstroke = dia->TempVorl[cabneu].SColor; + chars->at(e)->cstroke = dia.TempVorl[cabneu].SColor; if (chars->at(e)->cshade2 == doc->docParagraphStyles[cabori].SShade) - chars->at(e)->cshade2 = dia->TempVorl[cabneu].SShade; + chars->at(e)->cshade2 = dia.TempVorl[cabneu].SShade; if (chars->at(e)->cshadowx == doc->docParagraphStyles[cabori].txtShadowX) - chars->at(e)->cshadowx = dia->TempVorl[cabneu].txtShadowX; + chars->at(e)->cshadowx = dia.TempVorl[cabneu].txtShadowX; if (chars->at(e)->cshadowy == doc->docParagraphStyles[cabori].txtShadowY) - chars->at(e)->cshadowy = dia->TempVorl[cabneu].txtShadowY; + chars->at(e)->cshadowy = dia.TempVorl[cabneu].txtShadowY; if (chars->at(e)->coutline == doc->docParagraphStyles[cabori].txtOutline) - chars->at(e)->coutline = dia->TempVorl[cabneu].txtOutline; + chars->at(e)->coutline = dia.TempVorl[cabneu].txtOutline; if (chars->at(e)->cunderpos == doc->docParagraphStyles[cabori].txtUnderPos) - chars->at(e)->cunderpos = dia->TempVorl[cabneu].txtUnderPos; + chars->at(e)->cunderpos = dia.TempVorl[cabneu].txtUnderPos; if (chars->at(e)->cunderwidth == doc->docParagraphStyles[cabori].txtUnderWidth) - chars->at(e)->cunderwidth = dia->TempVorl[cabneu].txtUnderWidth; + chars->at(e)->cunderwidth = dia.TempVorl[cabneu].txtUnderWidth; if (chars->at(e)->cstrikepos == doc->docParagraphStyles[cabori].txtStrikePos) - chars->at(e)->cstrikepos = dia->TempVorl[cabneu].txtStrikePos; + chars->at(e)->cstrikepos = dia.TempVorl[cabneu].txtStrikePos; if (chars->at(e)->cstrikewidth == doc->docParagraphStyles[cabori].txtStrikeWidth) - chars->at(e)->cstrikewidth = dia->TempVorl[cabneu].txtStrikeWidth; + chars->at(e)->cstrikewidth = dia.TempVorl[cabneu].txtStrikeWidth; if (chars->at(e)->cscale == doc->docParagraphStyles[cabori].scaleH) - chars->at(e)->cscale = dia->TempVorl[cabneu].scaleH; + chars->at(e)->cscale = dia.TempVorl[cabneu].scaleH; if (chars->at(e)->cscalev == doc->docParagraphStyles[cabori].scaleV) - chars->at(e)->cscalev = dia->TempVorl[cabneu].scaleV; + chars->at(e)->cscalev = dia.TempVorl[cabneu].scaleV; if (chars->at(e)->cbase == doc->docParagraphStyles[cabori].baseOff) - chars->at(e)->cbase = dia->TempVorl[cabneu].baseOff; + chars->at(e)->cbase = dia.TempVorl[cabneu].baseOff; if (chars->at(e)->cextra == doc->docParagraphStyles[cabori].kernVal) - chars->at(e)->cextra = dia->TempVorl[cabneu].kernVal; + chars->at(e)->cextra = dia.TempVorl[cabneu].kernVal; } else { @@ -6237,7 +6197,7 @@ void ScribusMainWindow::saveStyles(StilF CurrStED->Editor->currentParaStyle = ers[CurrStED->Editor->currentParaStyle]; } } - doc->docParagraphStyles = dia->TempVorl; + doc->docParagraphStyles = dia.TempVorl; if (CurrStED != NULL) { if (CurrStED->Editor->StyledText.count() != 0) @@ -6304,8 +6264,8 @@ void ScribusMainWindow::slotEditColors() edc = doc->PageColors; else edc = prefsManager->colorSet(); - Farbmanager* dia = new Farbmanager(this, edc, HaveDoc, prefsManager->colorSetName(), prefsManager->appPrefs.CustomColorSets); - if (dia->exec()) + Farbmanager dia(this, edc, HaveDoc, prefsManager->colorSetName(), prefsManager->appPrefs.CustomColorSets); + if (dia.exec()) { if (HaveDoc) { @@ -6314,11 +6274,11 @@ void ScribusMainWindow::slotEditColors() PageItem *ite; QColor tmpc; slotDocCh(); - doc->PageColors = dia->EditColors; + doc->PageColors = dia.EditColors; propertiesPalette->updateColorList(); propertiesPalette->updateCList(); updateColorMenu(); - ers = dia->Ersatzliste; + ers = dia.Ersatzliste; if (!ers.isEmpty()) { QMap<QString,QString>::Iterator it; @@ -6481,14 +6441,13 @@ void ScribusMainWindow::slotEditColors() } else { - prefsManager->setColorSet(dia->EditColors); - prefsManager->setColorSetName(dia->LoadColSet->text()); + prefsManager->setColorSet(dia.EditColors); + prefsManager->setColorSetName(dia.LoadColSet->text()); propertiesPalette->Cpal->SetColors(prefsManager->colorSet()); } } if (!HaveDoc) - prefsManager->appPrefs.CustomColorSets = dia->CColSet; - delete dia; + prefsManager->appPrefs.CustomColorSets = dia.CColSet; } void ScribusMainWindow::setPenFarbe(QString farbe) @@ -6619,16 +6578,16 @@ void ScribusMainWindow::ObjektDupM() { slotSelect(); NoFrameEdit(); - Mdup *dia = new Mdup(this, DispX * doc->unitRatio(), DispY * doc->unitRatio(), doc->unitIndex()); - if (dia->exec()) + Mdup dia(this, DispX * doc->unitRatio(), DispY * doc->unitRatio(), doc->unitIndex()); + if (dia.exec()) { bool savedAlignGrid = doc->useRaster; bool savedAlignGuides = doc->SnapGuides; doc->useRaster = false; doc->SnapGuides = false; - int anz = dia->Ncopies->value(); - double dH = dia->ShiftH->value() / doc->unitRatio(); - double dV = dia->ShiftV->value() / doc->unitRatio(); + int anz = dia.Ncopies->value(); + double dH = dia.ShiftH->value() / doc->unitRatio(); + double dV = dia.ShiftV->value() / doc->unitRatio(); double dH2 = dH; double dV2 = dV; int a; @@ -6656,7 +6615,6 @@ void ScribusMainWindow::ObjektDupM() doc->useRaster = savedAlignGrid; doc->SnapGuides = savedAlignGuides; } - delete dia; } void ScribusMainWindow::selectItemsFromOutlines(int Page, int Item, bool single) @@ -6719,7 +6677,7 @@ void ScribusMainWindow::buildFontMenu() int a; QString b = " "; SCFontsIterator it(prefsManager->appPrefs.AvailFonts); - FontSub = new FontCombo(0); + FontSub = new FontCombo(0); // TODO: LEAK? Where is this deleted? FontMenu->insertItem(FontSub); connect(FontSub, SIGNAL(activated(int)), this, SLOT(setItemFont2(int))); FontMenu->insertSeparator(); @@ -6752,10 +6710,10 @@ void ScribusMainWindow::slotPrefsOrg() int oldGUIFontSize=prefsManager->guiFontSize(); //double oldDisplayScale=prefsManager->displayScale(); setAppMode(modeNormal); - Preferences *dia = new Preferences(this); - if (dia->exec()) + Preferences dia(this); + if (dia.exec()) { - dia->updatePreferences(); + dia.updatePreferences(); prefsManager->SavePrefs(); DocDir = prefsManager->documentDir(); scrapbookPalette->rebuildView(); @@ -6786,7 +6744,6 @@ void ScribusMainWindow::slotPrefsOrg() SetShortCut(); emit prefsChanged(); } - delete dia; } void ScribusMainWindow::ShowSubs() @@ -6830,33 +6787,32 @@ void ScribusMainWindow::doPrintPreview() } if (HaveDoc) { - PPreview *dia = new PPreview(this, view, doc, HavePngAlpha, HaveTiffSep); + PPreview dia(this, view, doc, HavePngAlpha, HaveTiffSep); previewDinUse = true; - connect(dia, SIGNAL(doPrint()), this, SLOT(slotReallyPrint())); - dia->exec(); + connect(&dia, SIGNAL(doPrint()), this, SLOT(slotReallyPrint())); + dia.exec(); PrefsManager *prefsManager=PrefsManager::instance(); - prefsManager->appPrefs.PrPr_Mode = dia->EnableCMYK->isChecked(); - prefsManager->appPrefs.PrPr_AlphaText = dia->AliasText->isChecked(); - prefsManager->appPrefs.PrPr_AlphaGraphics = dia->AliasGr->isChecked(); - prefsManager->appPrefs.PrPr_Transparency = dia->AliasTr->isChecked(); + prefsManager->appPrefs.PrPr_Mode = dia.EnableCMYK->isChecked(); + prefsManager->appPrefs.PrPr_AlphaText = dia.AliasText->isChecked(); + prefsManager->appPrefs.PrPr_AlphaGraphics = dia.AliasGr->isChecked(); + prefsManager->appPrefs.PrPr_Transparency = dia.AliasTr->isChecked(); if (HaveTiffSep != 0) { - prefsManager->appPrefs.PrPr_C = dia->EnableCMYK_C->isChecked(); - prefsManager->appPrefs.PrPr_M = dia->EnableCMYK_M->isChecked(); - prefsManager->appPrefs.PrPr_Y = dia->EnableCMYK_Y->isChecked(); - prefsManager->appPrefs.PrPr_K = dia->EnableCMYK_K->isChecked(); + prefsManager->appPrefs.PrPr_C = dia.EnableCMYK_C->isChecked(); + prefsManager->appPrefs.PrPr_M = dia.EnableCMYK_M->isChecked(); + prefsManager->appPrefs.PrPr_Y = dia.EnableCMYK_Y->isChecked(); + prefsManager->appPrefs.PrPr_K = dia.EnableCMYK_K->isChecked(); } else { - prefsManager->appPrefs.PrPr_C = dia->flagsVisible["Cyan"]->isChecked(); - prefsManager->appPrefs.PrPr_M = dia->flagsVisible["Magenta"]->isChecked(); - prefsManager->appPrefs.PrPr_Y = dia->flagsVisible["Yellow"]->isChecked(); - prefsManager->appPrefs.PrPr_K = dia->flagsVisible["Black"]->isChecked(); + prefsManager->appPrefs.PrPr_C = dia.flagsVisible["Cyan"]->isChecked(); + prefsManager->appPrefs.PrPr_M = dia.flagsVisible["Magenta"]->isChecked(); + prefsManager->appPrefs.PrPr_Y = dia.flagsVisible["Yellow"]->isChecked(); + prefsManager->appPrefs.PrPr_K = dia.flagsVisible["Black"]->isChecked(); } - prefsManager->appPrefs.Gcr_Mode = dia->EnableGCR->isChecked(); - disconnect(dia, SIGNAL(doPrint()), this, SLOT(slotReallyPrint())); + prefsManager->appPrefs.Gcr_Mode = dia.EnableGCR->isChecked(); + disconnect(&dia, SIGNAL(doPrint()), this, SLOT(slotReallyPrint())); previewDinUse = false; - delete dia; QFile::remove(PrefsPfad+"/tmp.ps"); QFile::remove(PrefsPfad+"/sc.png"); QDir d(PrefsPfad+"/", "sc.tif*", QDir::Name, QDir::Files | QDir::NoSymLinks); @@ -6915,16 +6871,12 @@ bool ScribusMainWindow::DoSaveAsEps(QStr doc->getUsedColors(usedColors); fileWatcher->forceScan(); fileWatcher->stop(); - PSLib *dd = new PSLib(false, prefsManager->appPrefs.AvailFonts, ReallyUsed, usedColors, false, true); - if (dd != NULL) - { - if (dd->PS_set_file(fn)) - dd->CreatePS(doc, /*view, */pageNs, false, tr("All"), spots, true, false, false, true, prefsManager->appPrefs.GCRMode, false); - else - return_value = false; - delete dd; - qApp->setOverrideCursor(QCursor(arrowCursor), true); - } + PSLib dd(false, prefsManager->appPrefs.AvailFonts, ReallyUsed, usedColors, false, true); + if (dd.PS_set_file(fn)) + dd.CreatePS(doc, /*view, */pageNs, false, tr("All"), spots, true, false, false, true, prefsManager->appPrefs.GCRMode, false); + else + return_value = false; + qApp->setOverrideCursor(QCursor(arrowCursor), true); fileWatcher->start(); return return_value; } @@ -7003,12 +6955,11 @@ void ScribusMainWindow::reallySaveAsEps( bool ScribusMainWindow::getPDFDriver(QString fn, QString nam, int Components, std::vector<int> &pageNs, QMap<int,QPixmap> thumbs) { bool ret = false; - PDFlib *dia = new PDFlib(doc); + PDFlib dia(doc); fileWatcher->forceScan(); fileWatcher->stop(); - ret = dia->doExport(fn, nam, Components, pageNs, thumbs); + ret = dia.doExport(fn, nam, Components, pageNs, thumbs); fileWatcher->start(); - delete dia; return ret; } @@ -7080,18 +7031,18 @@ void ScribusMainWindow::doSaveAsPDF() } doc->PDF_Options.SubsetList = tmpEm; } - PDF_Opts *dia = new PDF_Opts(this, doc->DocName, ReallyUsed, view, &doc->PDF_Options, doc->PDF_Options.PresentVals, &PDFXProfiles, prefsManager->appPrefs.AvailFonts, doc->unitRatio(), &ScMW->PrinterProfiles); - if (dia->exec()) + PDF_Opts dia(this, doc->DocName, ReallyUsed, view, &doc->PDF_Options, doc->PDF_Options.PresentVals, &PDFXProfiles, prefsManager->appPrefs.AvailFonts, doc->unitRatio(), &ScMW->PrinterProfiles); + if (dia.exec()) { qApp->setOverrideCursor(QCursor(waitCursor), true); - dia->updateDocOptions(); + dia.updateDocOptions(); ReOrderText(doc, view); - QString pageString(dia->getPagesString()); + QString pageString(dia.getPagesString()); std::vector<int> pageNs; uint pageNumbersSize; QMap<int,QPixmap> thumbs; - int components=dia->colorSpaceComponents(); - QString nam(dia->cmsDescriptor()); + int components=dia.colorSpaceComponents(); + QString nam(dia.cmsDescriptor()); QString fileName = doc->PDF_Options.Datei; parsePagesString(pageString, &pageNs, doc->DocPages.count()); if (doc->PDF_Options.doMultiFile) @@ -7119,7 +7070,6 @@ void ScribusMainWindow::doSaveAsPDF() { qApp->setOverrideCursor(QCursor(arrowCursor), true); QMessageBox::warning(this, CommonStrings::trWarning, tr("Cannot write the file: \n%1").arg(doc->PDF_Options.Datei), CommonStrings::tr_OK); - delete dia; return; } aa++; @@ -7143,7 +7093,6 @@ void ScribusMainWindow::doSaveAsPDF() } qApp->setOverrideCursor(QCursor(arrowCursor), true); } - delete dia; } void ScribusMainWindow::AddBookMark(PageItem *ite) @@ -7181,6 +7130,7 @@ void ScribusMainWindow::RestoreBookMarks BookMItem* ip; BookMItem* ip2 = NULL; BookMItem* ip3 = NULL; + // TODO: LEAK? How do these get cleaned up? BookMItem *ite = new BookMItem(bookmarkPalette->BView, &(*it2)); bookmarkPalette->BView->NrItems++; ++it2; @@ -7259,8 +7209,8 @@ void ScribusMainWindow::slotElemRead(QSt { if (doc == docc) NoFrameEdit(); - ScriXmlDoc *ss = new ScriXmlDoc(); - if(ss->ReadElem(Name, prefsManager->appPrefs.AvailFonts, docc, x, y, art, loca, prefsManager->appPrefs.GFontSub, vie)) + ScriXmlDoc ss; + if(ss.ReadElem(Name, prefsManager->appPrefs.AvailFonts, docc, x, y, art, loca, prefsManager->appPrefs.GFontSub, vie)) { vie->DrawNew(); if (doc == docc) @@ -7276,7 +7226,6 @@ void ScribusMainWindow::slotElemRead(QSt slotDocCh(); } } - delete ss; } void ScribusMainWindow::slotChangeUnit(int unitIndex, bool draw) @@ -7291,11 +7240,10 @@ void ScribusMainWindow::slotChangeUnit(i void ScribusMainWindow::ManageJava() { - JavaDocs *dia = new JavaDocs(this, doc, view); - connect(dia, SIGNAL(docChanged(bool)), this, SLOT(slotDocCh(bool ))); - dia->exec(); - disconnect(dia, SIGNAL(docChanged(bool)), this, SLOT(slotDocCh(bool ))); - delete dia; + JavaDocs dia(this, doc, view); + connect(&dia, SIGNAL(docChanged(bool)), this, SLOT(slotDocCh(bool ))); + dia.exec(); + disconnect(&dia, SIGNAL(docChanged(bool)), this, SLOT(slotDocCh(bool ))); } void ScribusMainWindow::manageMasterPages(QString temp) @@ -7310,7 +7258,7 @@ void ScribusMainWindow::manageMasterPage } else { - MasterPagesPalette *dia = new MasterPagesPalette(this, doc, view, temp); + MasterPagesPalette *dia = new MasterPagesPalette(this, doc, view, temp); // FIXME: LEAK? Where's this deleted? //connect(dia, SIGNAL(createNew(int)), this, SLOT(slotNewMasterPage(int))); connect(dia, SIGNAL(removePage(int )), this, SLOT(DeletePage2(int ))); connect(dia, SIGNAL(loadPage(QString, int, bool)), this, SLOT(loadPage(QString, int, bool))); @@ -7387,21 +7335,21 @@ void ScribusMainWindow::manageMasterPage void ScribusMainWindow::ApplyMasterPage() { Q_ASSERT(!doc->masterPageMode()); - ApplyMasterPageDialog *dia = new ApplyMasterPageDialog(this); - dia->setup(doc, doc->currentPage->MPageNam); - if (dia->exec()) + ApplyMasterPageDialog dia(this); + dia.setup(doc, doc->currentPage->MPageNam); + if (dia.exec()) { - QString masterPageName = dia->getMasterPageName(); - int pageSelection = dia->getPageSelection(); //0=current, 1=even, 2=odd, 3=all + QString masterPageName = dia.getMasterPageName(); + int pageSelection = dia.getPageSelection(); //0=current, 1=even, 2=odd, 3=all if (pageSelection==0) //current page only Apply_MasterPage(masterPageName, doc->currentPage->pageNr(), false); else { int startPage, endPage; - if (dia->usingRange()) + if (dia.usingRange()) { - startPage=dia->getFromPage()-1; //Pages start from 0, not 1 - endPage=dia->getToPage(); + startPage=dia.getFromPage()-1; //Pages start from 0, not 1 + endPage=dia.getToPage(); } else { @@ -7426,7 +7374,6 @@ void ScribusMainWindow::ApplyMasterPage( view->DrawNew(); slotDocCh(); pagePalette->Rebuild(); - delete dia; } void ScribusMainWindow::Apply_MasterPage(QString in, int Snr, bool reb) @@ -7682,11 +7629,10 @@ void ScribusMainWindow::StatusPic() { if (HaveDoc) { - PicStatus *dia = new PicStatus(this, doc, view); - connect(dia, SIGNAL(selectPage(int)), this, SLOT(selectPagesFromOutlines(int))); - connect(dia, SIGNAL(selectMasterPage(QString)), this, SLOT(manageMasterPages(QString))); - dia->exec(); - delete dia; + PicStatus dia(this, doc, view); + connect(&dia, SIGNAL(selectPage(int)), this, SLOT(selectPagesFromOutlines(int))); + connect(&dia, SIGNAL(selectMasterPage(QString)), this, SLOT(manageMasterPages(QString))); + dia.exec(); } } @@ -7695,34 +7641,33 @@ QString ScribusMainWindow::CFileDialog(Q bool *docom, bool *doFont) { QString retval = ""; - CustomFDialog *dia = new CustomFDialog(this, wDir, caption, filter, Pre, mod, comp, cod, onlyDirs); + CustomFDialog dia(this, wDir, caption, filter, Pre, mod, comp, cod, onlyDirs); if (!defNa.isEmpty()) { QFileInfo f(defNa); - dia->setExtension(f.extension(true)); - dia->setZipExtension(f.extension(true) + ".gz"); - dia->setSelection(defNa); + dia.setExtension(f.extension(true)); + dia.setZipExtension(f.extension(true) + ".gz"); + dia.setSelection(defNa); } if (onlyDirs) { - dia->SaveZip->setChecked(*docom); - dia->WFonts->setChecked(*doFont); + dia.SaveZip->setChecked(*docom); + dia.WFonts->setChecked(*doFont); } - if (dia->exec() == QDialog::Accepted) + if (dia.exec() == QDialog::Accepted) { LoadEnc = ""; if (!onlyDirs) - LoadEnc = cod ? dia->TxCodeM->currentText() : QString(""); + LoadEnc = cod ? dia.TxCodeM->currentText() : QString(""); else { - *docom = dia->SaveZip->isChecked(); - *doFont = dia->WFonts->isChecked(); + *docom = dia.SaveZip->isChecked(); + *doFont = dia.WFonts->isChecked(); } this->repaint(); qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput); - retval = dia->selectedFile(); + retval = dia.selectedFile(); } - delete dia; return retval; } @@ -7890,8 +7835,8 @@ void ScribusMainWindow::ModifyAnnot() int AnActType = currItem->annotation().ActionType(); QString AnAction = currItem->annotation().Action(); QString An_Extern = currItem->annotation().Extern(); - Annota *dia = new Annota(this, currItem, doc->DocPages.count(), static_cast<int>(doc->pageWidth), static_cast<int>(doc->pageHeight), view); - if (dia->exec()) + Annota dia(this, currItem, doc->DocPages.count(), static_cast<int>(doc->pageWidth), static_cast<int>(doc->pageHeight), view); + if (dia.exec()) slotDocCh(); else { @@ -7900,14 +7845,12 @@ void ScribusMainWindow::ModifyAnnot() currItem->annotation().setAction(AnAction); currItem->annotation().setExtern(An_Extern); } - delete dia; } else { - Annot *dia = new Annot(this, currItem, doc->DocPages.count(), static_cast<int>(doc->pageWidth), static_cast<int>(doc->pageHeight), doc->PageColors, view); - if (dia->exec()) + Annot dia(this, currItem, doc->DocPages.count(), static_cast<int>(doc->pageWidth), static_cast<int>(doc->pageHeight), doc->PageColors, view); + if (dia.exec()) slotDocCh(); - delete dia; } } } @@ -7924,10 +7867,9 @@ void ScribusMainWindow::SetShortCut() void ScribusMainWindow::PutScrap() { - ScriXmlDoc *ss = new ScriXmlDoc(); - QString objectString = ss->WriteElem(doc, view, doc->selection); + ScriXmlDoc ss; + QString objectString = ss.WriteElem(doc, view, doc->selection); scrapbookPalette->ObjFromMenu(objectString); - delete ss; } void ScribusMainWindow::changeLayer(int ) @@ -8026,18 +7968,17 @@ void ScribusMainWindow::initHyphenator() QString ext = fi.extension(false).lower(); if (ext == "qm") { - QTranslator *trans = new QTranslator(0); - trans->load(pfad + d2[dc]); + QTranslator trans(0); + trans.load(pfad + d2[dc]); QString translatedLang; for (QMap<QString, QStringList>::Iterator it=InstLang.begin(); it!=InstLang.end(); ++it) { translatedLang=""; - translatedLang = trans->findMessage("ScribusMainWindow", it.key(), "").translation(); + translatedLang = trans.findMessage("ScribusMainWindow", it.key(), "").translation(); if (!translatedLang.isEmpty()) it.data().append(translatedLang); } - delete trans; } } } @@ -8125,9 +8066,7 @@ void ScribusMainWindow::ManageGuides() { if (HaveDoc) { - GuideManager *dia = new GuideManager(this); - dia->exec(); - delete dia; + GuideManager(this).exec(); } } @@ -8175,13 +8114,12 @@ void ScribusMainWindow::ImageEffects() if (docSelectionCount != 0) { PageItem *currItem = doc->selection->itemAt(0); - EffectsDialog* dia = new EffectsDialog(this, currItem, doc); - if (dia->exec()) + EffectsDialog dia(this, currItem, doc); + if (dia.exec()) { - currItem->effectsInUse = dia->effectsList; + currItem->effectsInUse = dia.effectsList; view->UpdatePic(); } - delete dia; slotDocCh(); } } @@ -8189,12 +8127,7 @@ void ScribusMainWindow::ImageEffects() QString ScribusMainWindow::Collect(bool compress, bool withFonts, const QString& ) { - CollectForOutput *c = new CollectForOutput(withFonts, compress); - Q_CHECK_PTR(c); - QString ret = c->collect(); - delete c; - c=NULL; - return ret; + return CollectForOutput(withFonts, compress).collect(); } void ScribusMainWindow::ReorgFonts() @@ -8293,15 +8226,14 @@ void ScribusMainWindow::emergencySave() std::cout << "Saving: " << doc->DocName+".emergency" << std::endl; doc->autoSaveTimer->stop(); //disconnect(ActWin, SIGNAL(Schliessen()), ScMW, SLOT(DoFileClose())); - ScriXmlDoc *ss = new ScriXmlDoc(); - ss->WriteDoc(doc->DocName+".emergency", doc, 0); - delete ss; + ScriXmlDoc().WriteDoc(doc->DocName+".emergency", doc, 0); } view->close(); uint numPages=doc->Pages->count(); for (uint a=0; a<numPages; ++a) delete doc->Pages->at(a); delete doc; + doc = 0; ActWin->close(); } } @@ -8314,14 +8246,13 @@ void ScribusMainWindow::EditTabs() if (doc->selection->count() != 0) { PageItem *currItem = doc->selection->itemAt(0); - TabManager *dia = new TabManager(this, doc->unitIndex(), currItem->TabValues, currItem->width()); - if (dia->exec()) + TabManager dia(this, doc->unitIndex(), currItem->TabValues, currItem->width()); + if (dia.exec()) { - currItem->TabValues = dia->tmpTab; + currItem->TabValues = dia.tmpTab; view->RefreshItem(currItem); slotDocCh(); } - delete dia; } } } @@ -8331,13 +8262,12 @@ void ScribusMainWindow::SearchText() PageItem *currItem = doc->selection->itemAt(0); setAppMode(modeEdit); currItem->CPos = 0; - SearchReplace* dia = new SearchReplace(this, doc, currItem); - connect(dia, SIGNAL(NewFont(const QString&)), this, SLOT(SetNewFont(const QString&))); - connect(dia, SIGNAL(NewAbs(int)), this, SLOT(setAbsValue(int))); - dia->exec(); - disconnect(dia, SIGNAL(NewFont(const QString&)), this, SLOT(SetNewFont(const QString&))); - disconnect(dia, SIGNAL(NewAbs(int)), this, SLOT(setAbsValue(int))); - delete dia; + SearchReplace dia(this, doc, currItem); + connect(&dia, SIGNAL(NewFont(const QString&)), this, SLOT(SetNewFont(const QString&))); + connect(&dia, SIGNAL(NewAbs(int)), this, SLOT(setAbsValue(int))); + dia.exec(); + disconnect(&dia, SIGNAL(NewFont(const QString&)), this, SLOT(SetNewFont(const QString&))); + disconnect(&dia, SIGNAL(NewAbs(int)), this, SLOT(setAbsValue(int))); slotSelect(); } @@ -8389,9 +8319,7 @@ void ScribusMainWindow::slotCharSelect() PageItem *currItem = doc->selection->itemAt(0); if ((currItem->asTextFrame()) && (doc->appMode == modeEdit)) { - CharSelect *dia = new CharSelect(this, currItem); - dia->exec(); - delete dia; + CharSelect(this, currItem).exec(); } } } @@ -8436,9 +8364,7 @@ void ScribusMainWindow::getImageInfo() { if (pageItem->itemType() == PageItem::ImageFrame) { - ImageInfoDialog *dia = new ImageInfoDialog(this, &pageItem->pixm.imgInfo); - dia->exec(); - delete dia; + ImageInfoDialog(this, &pageItem->pixm.imgInfo).exec(); } } } @@ -8451,12 +8377,11 @@ void ScribusMainWindow::objectAttributes PageItem *pageItem = doc->selection->itemAt(0); if (pageItem!=NULL) { - PageItemAttributes *pageItemAttrs = new PageItemAttributes( this ); - pageItemAttrs->setup(pageItem->getObjectAttributes(), &doc->docItemAttributes); + PageItemAttributes pageItemAttrs( this ); + pageItemAttrs.setup(pageItem->getObjectAttributes(), &doc->docItemAttributes); //CB TODO Probably want this non modal in the future - if (pageItemAttrs->exec()==QDialog::Accepted) - pageItem->setObjectAttributes(pageItemAttrs->getNewAttributes()); - delete pageItemAttrs; + if (pageItemAttrs.exec()==QDialog::Accepted) + pageItem->setObjectAttributes(pageItemAttrs.getNewAttributes()); } } } @@ -8548,13 +8473,11 @@ void ScribusMainWindow::mouseReleaseEven void ScribusMainWindow::insertSampleText() { - LoremManager *m = new LoremManager(this, "m", true, 0); + LoremManager m(this, "m", true, 0); if (prefsManager->appPrefs.useStandardLI) - m->insertLoremIpsum("loremipsum.xml", prefsManager->appPrefs.paragraphsLI); + m.insertLoremIpsum("loremipsum.xml", prefsManager->appPrefs.paragraphsLI); else - m->exec(); - delete(m); - m=NULL; + m.exec(); } void ScribusMainWindow::languageChange() Index: scribus.h =================================================================== RCS file: /cvs/Scribus/scribus/scribus.h,v retrieving revision 1.60.2.170 diff -p -u -r1.60.2.170 scribus.h --- scribus.h 2 Jan 2006 17:15:26 -0000 1.60.2.170 +++ scribus.h 2 Jan 2006 20:40:48 -0000 @@ -442,9 +442,9 @@ public slots: void buildFontMenu(); void slotPrefsOrg(); void slotEditStyles(); - void saveStyles(StilFormate *dia); + void saveStyles(StilFormate & dia); void slotEditLineStyles(); - void saveLStyles(LineFormate *dia); + void saveLStyles(LineFormate & dia); void setNewAbStyle(int a); void setAbsValue(int a); void selectItemsFromOutlines(int Page, int Item, bool single = false); Index: scribusview.cpp =================================================================== RCS file: /cvs/Scribus/scribus/scribusview.cpp,v retrieving revision 1.76.2.425 diff -p -u -r1.76.2.425 scribusview.cpp --- scribusview.cpp 31 Dec 2005 11:30:40 -0000 1.76.2.425 +++ scribusview.cpp 2 Jan 2006 20:40:51 -0000 @@ -250,14 +250,14 @@ void ScribusView::drawContents(QPainter if ((clipw > 0) && (cliph > 0)) { QPoint vr = contentsToViewport(QPoint(clipx, clipy)); - ScPainter *painter = new ScPainter(viewport(), clipw, cliph, vr.x(), vr.y()); - painter->clear(paletteBackgroundColor()); - painter->translate(-Doc->minCanvasCoordinate.x()*Scale, -Doc->minCanvasCoordinate.y()*Scale); - painter->translate(-clipx, -clipy); - painter->setLineWidth(1); - painter->setFillMode(ScPainter::Solid); -// painter->translate(0.5, 0.5); - painter->setZoomFactor(1.0); + ScPainter painter(viewport(), clipw, cliph, vr.x(), vr.y()); + painter.clear(paletteBackgroundColor()); + painter.translate(-Doc->minCanvasCoordinate.x()*Scale, -Doc->minCanvasCoordinate.y()*Scale); + painter.translate(-clipx, -clipy); + painter.setLineWidth(1); + painter.setFillMode(ScPainter::Solid); +// painter.translate(0.5, 0.5); + painter.setZoomFactor(1.0); /* Draw Page Outlines */ if (!Doc->masterPageMode()) { @@ -272,16 +272,16 @@ void ScribusView::drawContents(QPainter drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale)); if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph))) { - painter->setFillMode(ScPainter::Solid); - painter->setPen(black, 1, SolidLine, FlatCap, MiterJoin); - painter->setBrush(QColor(128,128,128)); - painter->drawRect(x+5, y+5, w, h); + painter.setFillMode(ScPainter::Solid); + painter.setPen(black, 1, SolidLine, FlatCap, MiterJoin); + painter.setBrush(QColor(128,128,128)); + painter.drawRect(x+5, y+5, w, h); if (a == Doc->currentPageNumber()) - painter->setPen(red, 2, SolidLine, FlatCap, MiterJoin); + painter.setPen(red, 2, SolidLine, FlatCap, MiterJoin); else - painter->setPen(black, 1, SolidLine, FlatCap, MiterJoin); - painter->setBrush(Doc->papColor); - painter->drawRect(x, y, w, h); + painter.setPen(black, 1, SolidLine, FlatCap, MiterJoin); + painter.setBrush(Doc->papColor); + painter.drawRect(x, y, w, h); if (Doc->guidesSettings.before) DrawPageMarks(painter, Doc->Pages->at(a), QRect(clipx, clipy, clipw, cliph)); } @@ -313,12 +313,12 @@ void ScribusView::drawContents(QPainter drawRect.moveBy(qRound(-Doc->minCanvasCoordinate.x() * Scale), qRound(-Doc->minCanvasCoordinate.y() * Scale)); if (drawRect.intersects(QRect(clipx, clipy, clipw, cliph))) { - painter->setFillMode(ScPainter::Solid); - painter->setPen(black, 1, SolidLine, FlatCap, MiterJoin); - painter->setBrush(QColor(128,128,128)); - painter->drawRect(x+5, y+5, w, h); - painter->setBrush(Doc->papColor); - painter->drawRect(x, y, w, h); + painter.setFillMode(ScPainter::Solid); + painter.setPen(black, 1, SolidLine, FlatCap, MiterJoin); + painter.setBrush(QColor(128,128,128)); + painter.drawRect(x+5, y+5, w, h); + painter.setBrush(Doc->papColor); + painter.drawRect(x, y, w, h); if (Doc->guidesSettings.before) DrawPageMarks(painter, Doc->currentPage, QRect(clipx, clipy, clipw, cliph)); } @@ -328,9 +328,9 @@ void ScribusView::drawContents(QPainter } if ((Doc->selection->count() != 0) || (linkedFramesToShow.count() != 0)) { - double z = painter->zoomFactor(); - painter->setZoomFactor(Scale); - painter->save(); + double z = painter.zoomFactor(); + painter.setZoomFactor(Scale); + painter.save(); PageItem *currItem; if ((Doc->guidesSettings.linkShown) && (linkedFramesToShow.count() != 0)) currItem = linkedFramesToShow.at(0); @@ -448,14 +448,12 @@ void ScribusView::drawContents(QPainter } } } - painter->setLineWidth(1); - painter->setPenOpacity(1.0); - painter->restore(); - painter->setZoomFactor(z); + painter.setLineWidth(1); + painter.setPenOpacity(1.0); + painter.restore(); + painter.setZoomFactor(z); } - painter->end(); - delete painter; - painter=NULL; + painter.end(); } if (Doc->selection->count() != 0) { @@ -496,9 +494,9 @@ void ScribusView::drawContents(QPainter // qDebug( "Time elapsed: %d ms", tim.elapsed() ); } -void ScribusView::DrawMasterItems(ScPainter *painter, Page *page, QRect clip) +void ScribusView::DrawMasterItems(ScPainter & painter, Page *page, QRect clip) { - double z = painter->zoomFactor(); + double z = painter.zoomFactor(); if (!page->MPageNam.isEmpty()) { Page* Mp = Doc->MasterPages.at(Doc->MasterNames[page->MPageNam]); @@ -546,7 +544,7 @@ void ScribusView::DrawMasterItems(ScPain currItem->Dirty = true; QRect oldR(currItem->getRedrawBounding(Scale)); if (clip.intersects(oldR)) - currItem->DrawObj(painter, clip); + currItem->DrawObj(&painter, clip); currItem->OwnPage = savedOwnPage; if (!currItem->ChangedMasterItem) { @@ -577,28 +575,28 @@ void ScribusView::DrawMasterItems(ScPain QRect oldR(currItem->getRedrawBounding(Scale)); if (clip.intersects(oldR)) { - painter->setZoomFactor(Scale); - painter->save(); - painter->translate(currItem->xPos()*Scale, currItem->yPos()*Scale); - painter->rotate(currItem->rotation()); + painter.setZoomFactor(Scale); + painter.save(); + painter.translate(currItem->xPos()*Scale, currItem->yPos()*Scale); + painter.rotate(currItem->rotation()); if (currItem->lineColor() != "None") { QColor tmp; currItem->SetFarbe(&tmp, currItem->lineColor(), currItem->lineShade()); if ((currItem->TopLine) || (currItem->RightLine) || (currItem->BottomLine) || (currItem->LeftLine)) { - painter->setPen(tmp, currItem->Pwidth, currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin); + painter.setPen(tmp, currItem->Pwidth, currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin); if (currItem->TopLine) - painter->drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0)); + painter.drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0)); if (currItem->RightLine) - painter->drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height())); + painter.drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height())); if (currItem->BottomLine) - painter->drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height())); + painter.drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height())); if (currItem->LeftLine) - painter->drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0)); + painter.drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0)); } } - painter->restore(); + painter.restore(); } if (!currItem->ChangedMasterItem) { @@ -612,13 +610,13 @@ void ScribusView::DrawMasterItems(ScPain } } } - painter->setZoomFactor(z); + painter.setZoomFactor(z); } -void ScribusView::DrawPageItems(ScPainter *painter, QRect clip) +void ScribusView::DrawPageItems(ScPainter & painter, QRect clip) { linkedFramesToShow.clear(); - double z = painter->zoomFactor(); + double z = painter.zoomFactor(); if (Doc->Items->count() != 0) { QPainter p; @@ -660,7 +658,7 @@ void ScribusView::DrawPageItems(ScPainte if (forceRedraw) currItem->Dirty = false; // if ((!Mpressed) || (Doc->EditClip)) - currItem->DrawObj(painter, clip); + currItem->DrawObj(&painter, clip); currItem->Redrawn = true; if ((currItem->asTextFrame()) && ((currItem->NextBox != 0) || (currItem->BackBox != 0))) { @@ -716,71 +714,71 @@ void ScribusView::DrawPageItems(ScPainte QRect oldR(currItem->getRedrawBounding(Scale)); if (clip.intersects(oldR)) { - painter->setZoomFactor(Scale); - painter->save(); - painter->translate(currItem->xPos()*Scale, currItem->yPos()*Scale); - painter->rotate(currItem->rotation()); + painter.setZoomFactor(Scale); + painter.save(); + painter.translate(currItem->xPos()*Scale, currItem->yPos()*Scale); + painter.rotate(currItem->rotation()); if (currItem->lineColor() != "None") { QColor tmp; currItem->SetFarbe(&tmp, currItem->lineColor(), currItem->lineShade()); if ((currItem->TopLine) || (currItem->RightLine) || (currItem->BottomLine) || (currItem->LeftLine)) { - painter->setPen(tmp, currItem->Pwidth, currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin); + painter.setPen(tmp, currItem->Pwidth, currItem->PLineArt, Qt::SquareCap, currItem->PLineJoin); if (currItem->TopLine) - painter->drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0)); + painter.drawLine(FPoint(0.0, 0.0), FPoint(currItem->width(), 0.0)); if (currItem->RightLine) - painter->drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height())); + painter.drawLine(FPoint(currItem->width(), 0.0), FPoint(currItem->width(), currItem->height())); if (currItem->BottomLine) - painter->drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height())); + painter.drawLine(FPoint(currItem->width(), currItem->height()), FPoint(0.0, currItem->height())); if (currItem->LeftLine) - painter->drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0)); + painter.drawLine(FPoint(0.0, currItem->height()), FPoint(0.0, 0.0)); } } - painter->restore(); + painter.restore(); } } } Lnr++; } } - painter->setZoomFactor(z); + painter.setZoomFactor(z); } -void ScribusView::DrawPageMarks(ScPainter *p, Page *page, QRect) +void ScribusView::DrawPageMarks(ScPainter & painter, Page *page, QRect) { double lw = 0.5 / Scale; - double z = p->zoomFactor(); - p->save(); - p->setZoomFactor(Scale); - p->translate(page->xOffset() * Scale, page->yOffset() * Scale); - p->setLineWidth(lw); + double z = painter.zoomFactor(); + painter.save(); + painter.setZoomFactor(Scale); + painter.translate(page->xOffset() * Scale, page->yOffset() * Scale); + painter.setLineWidth(lw); double pageHeight=page->height(); double pageWidth=page->width(); //Draw the margins if (Doc->guidesSettings.marginsShown) { - p->setPen(Doc->guidesSettings.margColor); + painter.setPen(Doc->guidesSettings.margColor); if (Doc->marginColored) { - p->setBrush(Doc->guidesSettings.margColor); - p->drawRect(0, 0, pageWidth, page->Margins.Top); - p->drawRect(0, page->Margins.Top, page->Margins.Left, pageHeight - page->Margins.Top); - p->drawRect(page->Margins.Left, pageHeight - page->Margins.Bottom, pageWidth - page->Margins.Right - page->Margins.Left, page->Margins.Bottom); - p->drawRect(pageWidth - page->Margins.Right, page->Margins.Top, page->Margins.Right, pageHeight-page->Margins.Top); - } - p->setPen(Doc->guidesSettings.margColor); - p->drawLine(FPoint(0, page->Margins.Top), FPoint(pageWidth, page->Margins.Top)); - p->drawLine(FPoint(0, pageHeight - page->Margins.Bottom), FPoint(pageWidth, pageHeight - page->Margins.Bottom)); - p->drawLine(FPoint(page->Margins.Left, 0), FPoint(page->Margins.Left, pageHeight)); - p->drawLine(FPoint(pageWidth - page->Margins.Right, 0), FPoint(pageWidth - page->Margins.Right, pageHeight)); + painter.setBrush(Doc->guidesSettings.margColor); + painter.drawRect(0, 0, pageWidth, page->Margins.Top); + painter.drawRect(0, page->Margins.Top, page->Margins.Left, pageHeight - page->Margins.Top); + painter.drawRect(page->Margins.Left, pageHeight - page->Margins.Bottom, pageWidth - page->Margins.Right - page->Margins.Left, page->Margins.Bottom); + painter.drawRect(pageWidth - page->Margins.Right, page->Margins.Top, page->Margins.Right, pageHeight-page->Margins.Top); + } + painter.setPen(Doc->guidesSettings.margColor); + painter.drawLine(FPoint(0, page->Margins.Top), FPoint(pageWidth, page->Margins.Top)); + painter.drawLine(FPoint(0, pageHeight - page->Margins.Bottom), FPoint(pageWidth, pageHeight - page->Margins.Bottom)); + painter.drawLine(FPoint(page->Margins.Left, 0), FPoint(page->Margins.Left, pageHeight)); + painter.drawLine(FPoint(pageWidth - page->Margins.Right, 0), FPoint(pageWidth - page->Margins.Right, pageHeight)); } //Draw the baseline grid if (Doc->guidesSettings.baseShown) { - p->setPen(Doc->guidesSettings.baseColor, lw, SolidLine, FlatCap, MiterJoin); + painter.setPen(Doc->guidesSettings.baseColor, lw, SolidLine, FlatCap, MiterJoin); for (double yg = Doc->typographicSettings.offsetBaseGrid; yg < pageHeight; yg += Doc->typographicSettings.valueBaseGrid) - p->drawLine(FPoint(0, yg), FPoint(pageWidth, yg)); + painter.drawLine(FPoint(0, yg), FPoint(pageWidth, yg)); } //Draw the grid lines if (Doc->guidesSettings.gridShown) @@ -797,37 +795,37 @@ void ScribusView::DrawPageMarks(ScPainte { double i,start; i = Doc->guidesSettings.majorGrid; - p->setPen(Doc->guidesSettings.majorColor, lw, SolidLine, FlatCap, MiterJoin); + painter.setPen(Doc->guidesSettings.majorColor, lw, SolidLine, FlatCap, MiterJoin); start=floor(sty/i); start*=i; for (double b = start; b < endy; b+=i) - p->drawLine(FPoint(0, b), FPoint(pageWidth, b)); + painter.drawLine(FPoint(0, b), FPoint(pageWidth, b)); start=floor(stx/i); start*=i; for (double b = start; b <= endx; b+=i) - p->drawLine(FPoint(b, 0), FPoint(b, pageHeight)); + painter.drawLine(FPoint(b, 0), FPoint(b, pageHeight)); i = Doc->guidesSettings.minorGrid; - p->setPen(Doc->guidesSettings.minorColor, lw, DotLine, FlatCap, MiterJoin); + painter.setPen(Doc->guidesSettings.minorColor, lw, DotLine, FlatCap, MiterJoin); start=floor(sty/i); start*=i; for (double b = start; b < endy; b+=i) - p->drawLine(FPoint(0, b), FPoint(pageWidth, b)); + painter.drawLine(FPoint(0, b), FPoint(pageWidth, b)); start=floor(stx/i); start*=i; for (double b = start; b <= endx; b+=i) - p->drawLine(FPoint(b, 0), FPoint(b, pageHeight)); + painter.drawLine(FPoint(b, 0), FPoint(b, pageHeight)); } } //Draw the guides if (Doc->guidesSettings.guidesShown) { - p->setPen(Doc->guidesSettings.guideColor, lw, DotLine, FlatCap, MiterJoin); + painter.setPen(Doc->guidesSettings.guideColor, lw, DotLine, FlatCap, MiterJoin); if (page->XGuides.count() != 0) { for (uint xg = 0; xg < page->XGuides.count(); ++xg) { if ((page->XGuides[xg] >= 0) && (page->XGuides[xg] <= page->width())) - p->drawLine(FPoint(page->XGuides[xg], 0), FPoint(page->XGuides[xg], pageHeight)); + painter.drawLine(FPoint(page->XGuides[xg], 0), FPoint(page->XGuides[xg], pageHeight)); } } if (page->YGuides.count() != 0) @@ -835,12 +833,12 @@ void ScribusView::DrawPageMarks(ScPainte for (uint yg = 0; yg < page->YGuides.count(); ++yg) { if ((page->YGuides[yg] >= 0) && (page->YGuides[yg] <= pageHeight)) - p->drawLine(FPoint(0, page->YGuides[yg]), FPoint(page->width(), page->YGuides[yg])); + painter.drawLine(FPoint(0, page->YGuides[yg]), FPoint(page->width(), page->YGuides[yg])); } } } - p->restore(); - p->setZoomFactor(z); + painter.restore(); + painter.setZoomFactor(z); } void ScribusView::leaveEvent(QEvent *) @@ -891,10 +889,9 @@ void ScribusView::contentsDragEnterEvent // SeleItemPos(e->pos()); QUrl ur(text); QFileInfo fi = QFileInfo(ur.path()); - ScriXmlDoc *ss = new ScriXmlDoc(); if (fi.exists()) text = ur.path(); - if(ss->ReadElemHeader(text,fi.exists(), &gx, &gy, &gw, &gh)) + if(ScriXmlDoc().ReadElemHeader(text,fi.exists(), &gx, &gy, &gw, &gh)) { GroupX = e->pos().x() / Scale; GroupY = e->pos().y() / Scale; @@ -911,8 +908,6 @@ void ScribusView::contentsDragEnterEvent // PaintSizeRect(&p, QRect(pv, QPoint(pv.x()+qRound(gw), pv.y()+qRound(gh)))); p.end(); } - delete ss; - ss=NULL; } } @@ -1141,14 +1136,12 @@ void ScribusView::contentsDropEvent(QDro { if (!Doc->leaveDrag) { - QPopupMenu *pmen = new QPopupMenu(); + QPopupMenu pmen; qApp->setOverrideCursor(QCursor(ArrowCursor), true); - pmen->insertItem( tr("Copy Here")); - pmen->insertItem( tr("Move Here")); - pmen->insertItem( tr("Cancel")); - re = pmen->indexOf(pmen->exec(QCursor::pos())); - delete pmen; - pmen=NULL; + pmen.insertItem( tr("Copy Here")); + pmen.insertItem( tr("Move Here")); + pmen.insertItem( tr("Cancel")); + re = pmen.indexOf(pmen.exec(QCursor::pos())); } else re = 1; @@ -1416,22 +1409,19 @@ void ScribusView::contentsMouseReleaseEv emit PaintingDone(); return; } - InsertTable *dia = new InsertTable(this, static_cast<int>(Th / 6), static_cast<int>(Tw / 6)); - if (!dia->exec()) { - p.drawRect(AreaR); + InsertTable dia(this, static_cast<int>(Th / 6), static_cast<int>(Tw / 6)); + if (dia.exec()) + { + p.drawRect(AreaR); + p.end(); + Doc->appMode = modeNormal; + emit PaintingDone(); + } p.end(); - Doc->appMode = modeNormal; - emit PaintingDone(); - delete dia; - dia=NULL; - return; + Cols = dia.Cols->value(); + Rows = dia.Rows->value(); } - p.end(); - Cols = dia->Cols->value(); - Rows = dia->Rows->value(); - delete dia; - dia=NULL; deltaX = Tw / Cols; deltaY = Th / Rows; offX = 0.0; @@ -1621,39 +1611,37 @@ void ScribusView::contentsMouseReleaseEv } if ((!GetItem(&currItem)) && (m->button() == RightButton) && (!Doc->DragP) && (Doc->appMode == modeNormal)) { - QPopupMenu *pmen = new QPopupMenu(); + QPopupMenu pmen; if (ScMW->Buffer2.startsWith("<SCRIBUSELEM")) { Mxp = m->x(); Myp = m->y(); - pmen->insertItem( tr("&Paste") , this, SLOT(PasteToPage())); - pmen->insertSeparator(); + pmen.insertItem( tr("&Paste") , this, SLOT(PasteToPage())); + pmen.insertSeparator(); } setObjectUndoMode(); - ScMW->scrActions["editUndoAction"]->addTo(pmen); - ScMW->scrActions["editRedoAction"]->addTo(pmen); - pmen->insertSeparator(); - ScMW->scrActions["viewShowMargins"]->addTo(pmen); - ScMW->scrActions["viewShowFrames"]->addTo(pmen); - ScMW->scrActions["viewShowImages"]->addTo(pmen); - ScMW->scrActions["viewShowGrid"]->addTo(pmen); - ScMW->scrActions["viewShowGuides"]->addTo(pmen); - ScMW->scrActions["viewShowBaseline"]->addTo(pmen); - ScMW->scrActions["viewShowTextChain"]->addTo(pmen); - ScMW->scrActions["viewRulerMode"]->addTo(pmen); - pmen->insertSeparator(); -// pmen->insertItem( tr("Unit"), unitSwitcher); -// pmen->insertSeparator(); - ScMW->scrActions["viewSnapToGrid"]->addTo(pmen); - ScMW->scrActions["viewSnapToGuides"]->addTo(pmen); - pmen->insertSeparator(); - ScMW->scrActions["pageApplyMasterPage"]->addTo(pmen); - ScMW->scrActions["pageManageGuides"]->addTo(pmen); - ScMW->scrActions["pageManageMargins"]->addTo(pmen); - pmen->exec(QCursor::pos()); + ScMW->scrActions["editUndoAction"]->addTo(&pmen); + ScMW->scrActions["editRedoAction"]->addTo(&pmen); + pmen.insertSeparator(); + ScMW->scrActions["viewShowMargins"]->addTo(&pmen); + ScMW->scrActions["viewShowFrames"]->addTo(&pmen); + ScMW->scrActions["viewShowImages"]->addTo(&pmen); + ScMW->scrActions["viewShowGrid"]->addTo(&pmen); + ScMW->scrActions["viewShowGuides"]->addTo(&pmen); + ScMW->scrActions["viewShowBaseline"]->addTo(&pmen); + ScMW->scrActions["viewShowTextChain"]->addTo(&pmen); + ScMW->scrActions["viewRulerMode"]->addTo(&pmen); + pmen.insertSeparator(); +// pmen.insertItem( tr("Unit"), unitSwitcher); +// pmen.insertSeparator(); + ScMW->scrActions["viewSnapToGrid"]->addTo(&pmen); + ScMW->scrActions["viewSnapToGuides"]->addTo(&pmen); + pmen.insertSeparator(); + ScMW->scrActions["pageApplyMasterPage"]->addTo(&pmen); + ScMW->scrActions["pageManageGuides"]->addTo(&pmen); + ScMW->scrActions["pageManageMargins"]->addTo(&pmen); + pmen.exec(QCursor::pos()); setGlobalUndoMode(); - delete pmen; - pmen=NULL; return; } if ((Doc->appMode != modeMagnifier) && (!Doc->EditClip) && (Doc->appMode != modeDrawBezierLine)) @@ -3117,13 +3105,10 @@ void ScribusView::contentsMouseMoveEvent Doc->DragElements.clear(); for (uint dre=0; dre<Doc->selection->count(); ++dre) Doc->DragElements.append(Doc->selection->itemAt(dre)->ItemNr); - ScriXmlDoc *ss = new ScriXmlDoc(); - QDragObject *dr = new QTextDrag(ss->WriteElem(Doc, this, Doc->selection), this); + QDragObject *dr = new QTextDrag(ScriXmlDoc().WriteElem(Doc, this, Doc->selection), this); dr->setPixmap(loadIcon("DragPix.xpm")); if (!dr->drag()) qDebug("ScribusView::contentsMouseMoveEvent: couldn't start drag operation!"); - delete ss; - ss=NULL; Doc->DragP = false; Doc->leaveDrag = false; Mpressed = false; @@ -4491,15 +4476,13 @@ void ScribusView::contentsMousePressEven cc = QApplication::clipboard()->text(QClipboard::Clipboard); if (!cc.isNull()) { - Serializer *ss = new Serializer(""); - ss->Objekt = cc; + Serializer ss(""); + ss.Objekt = cc; int st = Doc->currentParaStyle; if (st > 5) - ss->GetText(currItem, st, Doc->docParagraphStyles[st].Font, Doc->docParagraphStyles[st].FontSize, true); + ss.GetText(currItem, st, Doc->docParagraphStyles[st].Font, Doc->docParagraphStyles[st].FontSize, true); else - ss->GetText(currItem, st, currItem->font(), currItem->fontSize(), true); - delete ss; - ss=NULL; + ss.GetText(currItem, st, currItem->font(), currItem->fontSize(), true); if (Doc->docHyphenator->AutoCheck) Doc->docHyphenator->slotHyphenate(currItem); for (uint a = 0; a < Doc->Items->count(); ++a) @@ -7805,10 +7788,7 @@ void ScribusView::ToggleSizeLock() void ScribusView::sentToScrap() { - ScriXmlDoc *ss = new ScriXmlDoc(); - emit ToScrap(ss->WriteElem(Doc, this, Doc->selection)); - delete ss; - ss=NULL; + emit ToScrap(ScriXmlDoc().WriteElem(Doc, this, Doc->selection)); } void ScribusView::ToBack() @@ -8658,26 +8638,24 @@ QImage ScribusView::MPageToPixmap(QStrin setScale(1.0); previewMode = true; pm = QImage(clipw, cliph, 32, QImage::BigEndian); - ScPainter *painter = new ScPainter(&pm, pm.width(), pm.height()); - painter->clear(white); - painter->translate(-clipx, -clipy); - painter->setLineWidth(1); - painter->setBrush(Doc->papColor); - painter->drawRect(clipx, clipy, clipw, cliph); + ScPainter painter(&pm, pm.width(), pm.height()); + painter.clear(white); + painter.translate(-clipx, -clipy); + painter.setLineWidth(1); + painter.setBrush(Doc->papColor); + painter.drawRect(clipx, clipy, clipw, cliph); //Hmm do we need master page mode before this? Seiten.cpp uses this function. DrawPageItems(painter, QRect(clipx, clipy, clipw, cliph)); Doc->guidesSettings.framesShown = frs; setScale(sca); Doc->currentPage = act; - painter->end(); + painter.end(); double sx = im.width() / static_cast<double>(maxGr); double sy = im.height() / static_cast<double>(maxGr); if (sy < sx) im = pm.smoothScale(static_cast<int>(pm.width() / sx), static_cast<int>(pm.height() / sx)); else im = pm.smoothScale(static_cast<int>(pm.width() / sy), static_cast<int>(pm.height() / sy)); - delete painter; - painter=NULL; previewMode = false; } return im; @@ -8701,17 +8679,17 @@ QImage ScribusView::PageToPixmap(int Nr, Page* act = Doc->currentPage; Doc->currentPage = Doc->Pages->at(Nr); pm = QImage(clipw, cliph, 32, QImage::BigEndian); - ScPainter *painter = new ScPainter(&pm, pm.width(), pm.height()); - painter->clear(Doc->papColor); - painter->translate(-clipx, -clipy); - painter->setFillMode(ScPainter::Solid); - painter->setPen(black, 1, SolidLine, FlatCap, MiterJoin); - painter->setBrush(Doc->papColor); - painter->drawRect(clipx, clipy, clipw, cliph); -// painter->translate(0.5, 0.5); + ScPainter painter(&pm, pm.width(), pm.height()); + painter.clear(Doc->papColor); + painter.translate(-clipx, -clipy); + painter.setFillMode(ScPainter::Solid); + painter.setPen(black, 1, SolidLine, FlatCap, MiterJoin); + painter.setBrush(Doc->papColor); + painter.drawRect(clipx, clipy, clipw, cliph); +// painter.translate(0.5, 0.5); DrawMasterItems(painter, Doc->Pages->at(Nr), QRect(clipx, clipy, clipw, cliph)); DrawPageItems(painter, QRect(clipx, clipy, clipw, cliph)); - painter->end(); + painter.end(); Doc->guidesSettings.framesShown = frs; setScale(sca); Doc->currentPage = act; @@ -8721,8 +8699,6 @@ QImage ScribusView::PageToPixmap(int Nr, im = pm.smoothScale(static_cast<int>(pm.width() / sx), static_cast<int>(pm.height() / sx)); else im = pm.smoothScale(static_cast<int>(pm.width() / sy), static_cast<int>(pm.height() / sy)); - delete painter; - painter=NULL; previewMode = false; } return im; @@ -10097,10 +10073,7 @@ void ScribusView::editExtendedImagePrope PageItem *Item = Doc->selection->itemAt(0); if (Item->pixm.imgInfo.valid) { - ExtImageProps* dia = new ExtImageProps(this, &Item->pixm.imgInfo, Item, this); - dia->exec(); - delete dia; - dia=NULL; + ExtImageProps(this, &Item->pixm.imgInfo, Item, this).exec(); } } } @@ -11183,13 +11156,12 @@ void ScribusView::setScale(const double unitChange(); } -void ScribusView::drawLinkFrameLine(ScPainter* painter, FPoint &start, FPoint &end) +void ScribusView::drawLinkFrameLine(ScPainter & painter, FPoint &start, FPoint &end) { //CB FIXME Add some checking that the painter is setup? - Q_ASSERT(painter!=NULL); - painter->setPen(black, 1.0 / Scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); - painter->setPenOpacity(1.0); - painter->drawLine(start, end); + painter.setPen(black, 1.0 / Scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); + painter.setPenOpacity(1.0); + painter.drawLine(start, end); QWMatrix arrowTrans; arrowTrans.translate(end.x(), end.y()); double r = atan2(end.y()-start.y(), end.x()-start.x())*(180.0/M_PI); @@ -11203,10 +11175,10 @@ void ScribusView::drawLinkFrameLine(ScPa arrow.addQuadPoint(-15, 5, -15, 5, -15, 5, -15, 5); arrow.addQuadPoint(-12, 0, -12, 0, -12, 0, -12, 0); arrow.map(arrowTrans); - painter->setBrush(painter->pen()); - painter->setBrushOpacity(1.0); - painter->setLineWidth(0); - painter->setFillMode(ScPainter::Solid); - painter->setupPolygon(&arrow); - painter->fillPath(); + painter.setBrush(painter.pen()); + painter.setBrushOpacity(1.0); + painter.setLineWidth(0); + painter.setFillMode(ScPainter::Solid); + painter.setupPolygon(&arrow); + painter.fillPath(); } Index: scribusview.h =================================================================== RCS file: /cvs/Scribus/scribus/scribusview.h,v retrieving revision 1.14.2.106 diff -p -u -r1.14.2.106 scribusview.h --- scribusview.h 28 Dec 2005 11:52:12 -0000 1.14.2.106 +++ scribusview.h 2 Jan 2006 20:40:51 -0000 @@ -128,9 +128,6 @@ public: bool previewMode; FPoint RCenter; FPointArray RecordP; - void DrawMasterItems(ScPainter *painter, Page *page, QRect clip); - void DrawPageItems(ScPainter *painter, QRect clip); - void DrawPageMarks(ScPainter *p, Page* page, QRect clip); //CB This MUST now be called AFTER a call to doc->addPage or doc->addMasterPage as it //does NOT create a page anymore. Page* addPage(int nr, bool mov = true); @@ -360,7 +357,10 @@ protected: // Protected methods virtual void setHBarGeometry(QScrollBar &bar, int x, int y, int w, int h); virtual void setVBarGeometry(QScrollBar &bar, int x, int y, int w, int h); - void drawLinkFrameLine(ScPainter* painter, FPoint &start, FPoint &end); + void drawLinkFrameLine(ScPainter & painter, FPoint &start, FPoint &end); + void DrawMasterItems(ScPainter & painter, Page *page, QRect clip); + void DrawPageItems(ScPainter & painter, QRect clip); + void DrawPageMarks(ScPainter & p, Page* page, QRect clip); signals: void changeUN(int); Index: story.cpp =================================================================== RCS file: /cvs/Scribus/scribus/story.cpp,v retrieving revision 1.58.2.108 diff -p -u -r1.58.2.108 story.cpp --- story.cpp 31 Dec 2005 10:21:05 -0000 1.58.2.108 +++ story.cpp 2 Jan 2006 20:40:52 -0000 @@ -53,19 +53,21 @@ extern QPixmap loadIcon(QString nam); -SideBar::SideBar(QWidget *pa) : QLabel(pa) +SideBar::SideBar(QWidget *pa) : QLabel(pa), + offs(0), + editor(0), + noUpdt(true), + inRep(false), + pmen(0) { setEraseColor(QColor(255,255,255)); - offs = 0; - editor = 0; - noUpdt = true; - inRep = false; setMinimumWidth(fontMetrics().width( tr("No Style") )+30); } void SideBar::mouseReleaseEvent(QMouseEvent *m) { CurrentPar = editor->paragraphAt(QPoint(2, m->y()+offs)); + Q_ASSERT(pmen == 0); pmen = new QPopupMenu(); Spalette* Spal = new Spalette(this); Spal->setFormats(editor->doc); @@ -79,10 +81,11 @@ void SideBar::mouseReleaseEvent(QMouseEv else Spal->setFormat(0); connect(Spal, SIGNAL(newStyle(int)), this, SLOT(setPStyle(int))); - pmen->insertItem(Spal); + pmen->insertItem(Spal); // pmen takes ownership of SPal pmen->insertItem( tr("Edit Styles..."), this, SLOT(editStyles())); pmen->exec(QCursor::pos()); delete pmen; + pmen = 0; } void SideBar::editStyles() @@ -90,8 +93,10 @@ void SideBar::editStyles() emit sigEditStyles(); } +// WARNING: only to be called from within mouseReleaseEvent(...), where pmen is set. void SideBar::setPStyle(int s) { + Q_ASSERT(pmen); emit ChangeStyle(CurrentPar, s); pmen->activateItemAt(0); } @@ -2866,14 +2871,13 @@ void StoryEditor::updateStatus() void StoryEditor::Do_insSp() { blockUpdate = true; - CharSelect *dia = new CharSelect(this, currItem, Editor->CurrFont); - dia->exec(); - if (!dia->getCharacters().isEmpty()) + CharSelect dia(this, currItem, Editor->CurrFont); + dia.exec(); + if (!dia.getCharacters().isEmpty()) { - Editor->insChars(dia->getCharacters()); - Editor->insert(dia->getCharacters()); + Editor->insChars(dia.getCharacters()); + Editor->insert(dia.getCharacters()); } - delete dia; blockUpdate = false; } @@ -3106,11 +3110,10 @@ void StoryEditor::updateTextFrame() bool rep = currDoc->RePos; currDoc->RePos = true; QPixmap pgPix(1, 1); - ScPainter *painter = new ScPainter(&pgPix, 1, 1); - painter->translate(0.5, 0.5); - nextItem->DrawObj(painter, QRect(0, 0, 1, 1)); - painter->end(); - delete painter; + ScPainter painter(&pgPix, 1, 1); + painter.translate(0.5, 0.5); + nextItem->DrawObj(&painter, QRect(0, 0, 1, 1)); + painter.end(); currDoc->RePos = rep; nb2 = nextItem; while (nb2 != 0) @@ -3131,9 +3134,7 @@ void StoryEditor::SearchText() { blockUpdate = true; EditorBar->setRepaint(false); - SearchReplace* dia = new SearchReplace(this, currDoc, currItem, false); - dia->exec(); - delete dia; + SearchReplace(this, currDoc, currItem, false).exec(); qApp->processEvents(); blockUpdate = false; EditorBar->setRepaint(true); @@ -3151,12 +3152,13 @@ void StoryEditor::slotEditStyles() disconnect(AlignTools, SIGNAL(NewAlign(int)), this, SLOT(newAlign(int))); //emit EditSt(); - StilFormate *dia = new StilFormate(this, currDoc); - connect(dia, SIGNAL(saveStyle(StilFormate *)), ScMW, SLOT(saveStyles(StilFormate *))); - if (dia->exec()) - ScMW->saveStyles(dia); - disconnect(dia, SIGNAL(saveStyle(StilFormate *)), ScMW, SLOT(saveStyles(StilFormate *))); - delete dia; + { + StilFormate dia(this, currDoc); + connect(&dia, SIGNAL(saveStyle(StilFormate&)), ScMW, SLOT(saveStyles(StilFormate&))); + if (dia.exec()) + ScMW->saveStyles(dia); + disconnect(&dia, SIGNAL(saveStyle(StilFormate&)), ScMW, SLOT(saveStyles(StilFormate&))); + } AlignTools->Spal->setFormats(currDoc); AlignTools->SetAlign(Editor->currentParaStyle); @@ -3482,10 +3484,10 @@ void StoryEditor::LoadTextFile() if (!fileName.isEmpty()) { dirs->set("story_load", fileName.left(fileName.findRev("/"))); - Serializer *ss = new Serializer(fileName); - if (ss->Read(LoadEnc)) + Serializer ss(fileName); + if (ss.Read(LoadEnc)) { - QString data = ss->GetObjekt(); + QString data = ss.GetObjekt(); data.replace(QRegExp("\r"), ""); data.replace(QRegExp("\n"), QChar(13)); Editor->loadText(data, currItem); @@ -3493,7 +3495,6 @@ void StoryEditor::LoadTextFile() emenu->setItemEnabled(Mcopy, 0); emenu->setItemEnabled(Mcut, 0); emenu->setItemEnabled(Mdel, 0); - delete ss; } } EditorBar->setRepaint(true); @@ -3522,10 +3523,9 @@ void StoryEditor::SaveTextFile() if (!fileName.isEmpty()) { dirs->set("story_save", fileName.left(fileName.findRev("/"))); - Serializer *ss = new Serializer(fileName); - ss->Objekt = Editor->text(); - ss->Write(LoadEnc); - delete ss; + Serializer ss(fileName); + ss.Objekt = Editor->text(); + ss.Write(LoadEnc); } blockUpdate = false; } Index: story.h =================================================================== RCS file: /cvs/Scribus/scribus/story.h,v retrieving revision 1.27.2.30 diff -p -u -r1.27.2.30 story.h --- story.h 12 Nov 2005 13:56:08 -0000 1.27.2.30 +++ story.h 2 Jan 2006 20:40:52 -0000 @@ -162,7 +162,6 @@ public: int offs; int CurrentPar; SEditor *editor; - QPopupMenu *pmen; bool noUpdt; bool inRep; @@ -176,12 +175,18 @@ signals: void sigEditStyles(); public slots: - void setPStyle(int s); void doMove(int x, int y); void doRepaint(); void setRepaint(bool r); //! slot raising style manager void editStyles(); + +private slots: + void setPStyle(int s); + +private: + // Managed in mouseReleaseEvent, used by setPStyle + QPopupMenu *pmen; }; class SCRIBUS_API SToolBColorF : public QToolBar Index: plugins/scriptplugin/cmddialog.cpp =================================================================== RCS file: /cvs/Scribus/scribus/plugins/scriptplugin/cmddialog.cpp,v retrieving revision 1.12.2.22 diff -p -u -r1.12.2.22 cmddialog.cpp --- plugins/scriptplugin/cmddialog.cpp 5 Dec 2005 12:04:52 -0000 1.12.2.22 +++ plugins/scriptplugin/cmddialog.cpp 2 Jan 2006 20:40:52 -0000 @@ -103,12 +103,13 @@ PyObject *scribus_newstyledialog(PyObjec It simulates user mouse clicking in the style dialogs. Ugly. Unpleasant. Etc. But working. */ uint styleCount = ScMW->doc->docParagraphStyles.count(); - StilFormate *dia2 = new StilFormate(ScMW, ScMW->doc); - QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); - dia2->neuesFormat(); - QApplication::restoreOverrideCursor(); - ScMW->saveStyles(dia2); - delete dia2; + { + StilFormate dia2(ScMW, ScMW->doc); + QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); + dia2.neuesFormat(); + QApplication::restoreOverrideCursor(); + ScMW->saveStyles(dia2); + } if (styleCount == ScMW->doc->docParagraphStyles.count()) { Py_INCREF(Py_None); |
|
In-progress diff attached. It's not done, though it deals with most of it, nor have I double checked it yet. It'll need a review once I've finished work. The attached diff fixes at least six or seven minor leaks. |
|
as the devil advocate: but using only stack objects can produce large binary file to load into ram. I suggest to use stack things in the "core/deeply internal" classes only. E.g. (as I'm interested in guides management) when I'm opening GuideManager dialog I don't care about pointer speed as it's even quicker than I can see. The same for plugins... |
|
subik, I don't understand the connection to be honest. Whether an object is allocated on the stack or the heap shouldn't affect the binary size in any noticeable way. Additionally, it'll help reduce heap fragmentation, though in Scribus's case that won't gain us anything much because other sources are so much greater. My point is not speed when it comes to GUI dialogs. It's that it's safer. It's easy to accidentally leak objects in cases like this (though this example is oversimplified, I have found bugs exactly like this in the scribus sources): int doSomething() { SomeDialog* dia = new SomeDialog("something"); if (p->exec()) { // ... do series of things return p->value(); // <-- LEAK } delete dia; return -1; } If you do this instead: int doSomething() { SomeDialog dia("something"); if (p.exec()) { // ... do series of things return p.value(); } return -1; } ... then you're protected against leaks, because the dialog is always automatically destroyed when it exits scope. People DO make these mistakes, in fact they're a very common cause of problems in C/C++ code. When the language gives us tools to protect ourselves against them I think we should use them. The same is true for other objects, not just dialogs. Speed is only a consideration for some key code such as in PageItem::DrawObj, and there are almost no changes to make there anyway. This is about making it harder to introduce bugs and memory leaks, and making the code more readable - speed isn't the issue except in a very few cases. More readable? Yes. Because it's more succinct, and because it's much clearer when you're creating an object you intend to keep around (using `new') rather than one you're using only within the current routine (which you can stack allocate). The guide manager example: void ScribusMainWindow::ManageGuides() { if (HaveDoc) { GuideManager *dia = new GuideManager(this); dia->exec(); delete dia; } } becomes void ScribusMainWindow::ManageGuides() { if (HaveDoc) GuideManager(this).exec(); } It's shorter, easier to understand, and there's zero risk of leaking anything if someone screws up when changing the code. |
2006-01-05 04:50
|
|
|
Trivial sample attached. With " -O0 -fno-inline " the heap-based version is slightly larger, with " -O2 " it's slightly smaller (but then again, you can't inline access to the vector with the heap based one, and have to go through a pointer each time you access it, so there's a performance penalty). The demo is kind of pointless anyway, since it's hard to know what the compiler has optimised out, but it shows there's no drastic difference. If you can show me some cases where it makes the binary significantly larger (where not cause by improved optimisations made possible by inlining) I'm interested to hear it. In any case, I think other considerations as outlined above make stack-based objects better where practical. |
Date Modified | Username | Field | Change |
---|---|---|---|
2006-01-02 20:52 |
|
New Issue | |
2006-01-02 20:52 |
|
File Added: scribus_delete_working2.diff | |
2006-01-02 20:53 |
|
Note Added: 0007903 | |
2006-01-02 20:55 |
|
Description Updated | |
2006-01-04 21:12 | subik | Note Added: 0007917 | |
2006-01-05 04:33 |
|
Note Added: 0007923 | |
2006-01-05 04:33 |
|
Status | new => acknowledged |
2006-01-05 04:34 |
|
Note Edited: 0007923 | |
2006-01-05 04:50 |
|
File Added: stackvsheap.tar.gz | |
2006-01-05 04:54 |
|
Note Added: 0007924 |