cyrille / braindump

Braindump is a tool to dump and organize the content of your brain (ideas, drawings, images, texts...) to your computer.

Clone this repository (size: 744.2 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/cyrille/braindump/
commit 456: 8da2aed67a98
parent 455: f76acc68332f
branch: default
correctly set the undo stack
Cyrille Berger
6 months ago

Changed (Δ592 bytes):

raw changeset »

src/RootSection.cpp (3 lines added, 2 lines removed)

src/RootSection.h (1 lines added, 1 lines removed)

src/Section.cpp (1 lines added, 1 lines removed)

src/Section.h (2 lines added, 1 lines removed)

src/SectionContainer.cpp (5 lines added, 9 lines removed)

src/SectionContainer.h (2 lines added, 3 lines removed)

src/SectionGroup.cpp (4 lines added, 1 lines removed)

src/SectionsBoxDock.cpp (3 lines added, 3 lines removed)

src/SectionsIO.cpp (4 lines added, 4 lines removed)

src/SectionsIO.h (2 lines added, 1 lines removed)

src/View.cpp (0 lines added, 1 lines removed)

Up to file-list src/RootSection.cpp:

26
26
27
27
#include "ViewManager.h"
28
28
29
RootSection::RootSection() : SectionGroup(0), m_viewManager(new ViewManager(this)), m_sectionsSaver(new SectionsIO(this))
29
#include <KDebug>
30
31
RootSection::RootSection() : SectionGroup(0), m_undoStack(new KoUndoStack(0)), m_viewManager(new ViewManager(this)), m_sectionsSaver(new SectionsIO(this))
30
32
{
31
  m_undoStack = new KoUndoStack(0);
32
33
  connect(m_undoStack, SIGNAL(indexChanged(int)), SIGNAL(commandExecuted()));
33
34
}
34
35

Up to file-list src/RootSection.h:

@@ -43,8 +43,8 @@ class RootSection : public QObject, publ
43
43
    /// This signal is emited when a command is executed in the undo stack
44
44
    void commandExecuted();
45
45
  private:
46
    KoUndoStack* m_undoStack;
46
47
    ViewManager* m_viewManager;
47
    KoUndoStack* m_undoStack;
48
48
    SectionsIO* m_sectionsSaver;
49
49
};
50
50

Up to file-list src/Section.cpp:

23
23
#include "LayoutFactoryRegistry.h"
24
24
#include "Layout.h"
25
25
26
Section::Section() : SectionGroup(0), m_layout(LayoutFactoryRegistry::instance()->createLayout("freelayout")), m_sectionContainer(new SectionContainer(this))
26
Section::Section(KoUndoStack* _stack) : SectionGroup(0), m_layout(LayoutFactoryRegistry::instance()->createLayout("freelayout")), m_sectionContainer(new SectionContainer(this, _stack))
27
27
{
28
28
}
29
29

Up to file-list src/Section.h:

25
25
26
26
class Layout;
27
27
class SectionContainer;
28
class KoUndoStack;
28
29
29
30
class Section :  public SectionGroup {
30
31
  public:
31
    Section();
32
    Section(KoUndoStack* _stack);
32
33
    Section(const Section& _rhs);
33
34
  public:
34
35
    SectionContainer* sectionContainer();

Up to file-list src/SectionContainer.cpp:

39
39
#include "Utils.h"
40
40
#include "Layout.h"
41
41
42
SectionContainer::SectionContainer(Section* section) : m_section(0), m_layer(0)
42
SectionContainer::SectionContainer(Section* section, KoUndoStack* _stack) : m_section(0), m_layer(0)
43
43
{
44
  initContainer(section);
44
  initContainer(section, _stack);
45
45
}
46
46
47
47
SectionContainer::SectionContainer(const SectionContainer& _rhs)
@@ -71,7 +71,7 @@ class SectionContainerShapePaste : publi
71
71
};
72
72
73
73
SectionContainer::SectionContainer(const SectionContainer& _rhs, Section* _section ) : m_section(0), m_layer(0) {
74
  initContainer(_section);
74
  initContainer(_section, dynamic_cast<KoUndoStack*>(_rhs.m_dataCenterMap["UndoStack"]));
75
75
  KoShapeOdfSaveHelper saveHelper(_rhs.m_layer->childShapes());
76
76
  KoDrag drag;
77
77
  drag.setOdf(KoOdf::mimeType(KoOdf::Text), saveHelper);
@@ -86,21 +86,17 @@ SectionContainer::SectionContainer(const
86
86
  delete mimeData;
87
87
}
88
88
89
void SectionContainer::initContainer(Section* _section) {
89
void SectionContainer::initContainer(Section* _section, KoUndoStack* _stack) {
90
90
  m_section = _section;
91
91
  m_sectionModel = new SectionShapeContainerModel(m_section);
92
92
  m_layer = new KoShapeLayer(m_sectionModel);
93
  m_dataCenterMap["UndoStack"] = _stack;
93
94
  foreach (QString id, KoShapeRegistry::instance()->keys()) {
94
95
    KoShapeFactory *shapeFactory = KoShapeRegistry::instance()->value(id);
95
96
    shapeFactory->populateDataCenterMap(m_dataCenterMap);
96
97
  }
97
98
}
98
99
99
void SectionContainer::setUndoStack(KoUndoStack* stack)
100
{
101
  m_dataCenterMap["UndoStack"] = stack;
102
}
103
104
100
Section* SectionContainer::section()
105
101
{
106
102
  return m_section;

Up to file-list src/SectionContainer.h:

@@ -29,12 +29,11 @@ class KoUndoStack;
29
29
30
30
class SectionContainer {
31
31
  public:
32
    SectionContainer(Section* );
32
    SectionContainer(Section* , KoUndoStack* _stack );
33
33
    SectionContainer(const SectionContainer& _rhs, Section* );
34
34
  private:
35
    void initContainer(Section* );
35
    void initContainer(Section* , KoUndoStack* _stack );
36
36
  public:
37
    void setUndoStack(KoUndoStack* );
38
37
    Section* section();
39
38
    KoShapeLayer* layer();
40
39
    bool loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context, QList<KoShape*>& shapes);

Up to file-list src/SectionGroup.cpp:

20
20
#include "SectionGroup.h"
21
21
#include "Section.h"
22
22
#include <klocalizedstring.h>
23
#include "RootSection.h"
23
24
24
25
int SectionGroup::s_count = 0;
25
26
@@ -69,7 +70,9 @@ QList<Section*> SectionGroup::sections(
69
70
70
71
Section* SectionGroup::newSection( Section* before )
71
72
{
72
  Section* section = new Section;
73
  SectionGroup* root = this;
74
  while(root->sectionParent()) root = root->sectionParent();
75
  Section* section = new Section( dynamic_cast<RootSection*>(root)->undoStack()) ;
73
76
  insertSection(section, before);
74
77
  section->setName(nextName());
75
78
  return section;

Up to file-list src/SectionsBoxDock.cpp:

@@ -178,7 +178,7 @@ void SectionsBoxDock::slotDuplicateClick
178
178
void SectionsBoxDock::slotNewSectionAsChildOfCurrent()
179
179
{
180
180
  Q_ASSERT(m_view->activeSection());
181
  Section* section = new Section();
181
  Section* section = new Section(m_view->rootSection()->undoStack());
182
182
  section->setName(SectionGroup::nextName());
183
183
  m_view->rootSection()->addCommand(section, new InsertSectionCommand(m_view->rootSection()->sectionsIO(), section, m_view->activeSection(), m_model, 0));
184
184
}
@@ -186,7 +186,7 @@ void SectionsBoxDock::slotNewSectionAsCh
186
186
void SectionsBoxDock::slotNewSectionAboveCurrent()
187
187
{
188
188
  SectionGroup* parentSection = m_view->activeSection() ? m_view->activeSection()->sectionParent() : m_view->rootSection();
189
  Section* section = new Section();
189
  Section* section = new Section(m_view->rootSection()->undoStack());
190
190
  section->setName(SectionGroup::nextName());
191
191
  m_view->rootSection()->addCommand(section, new InsertSectionCommand(m_view->rootSection()->sectionsIO(), section, parentSection, m_model, m_view->activeSection()));
192
192
}
@@ -195,7 +195,7 @@ void SectionsBoxDock::slotNewSectionBell
195
195
{
196
196
  SectionGroup* parentSection = m_view->activeSection() ? m_view->activeSection()->sectionParent() : m_view->rootSection();
197
197
  Section* above = parentSection->nextSection( m_view->activeSection() );
198
  Section* section = new Section();
198
  Section* section = new Section(m_view->rootSection()->undoStack());
199
199
  section->setName(SectionGroup::nextName());
200
200
  m_view->rootSection()->addCommand(section, new InsertSectionCommand(m_view->rootSection()->sectionsIO(), section, parentSection, m_model, above));
201
201
}

Up to file-list src/SectionsIO.cpp:

@@ -298,13 +298,13 @@ void SectionsIO::save()
298
298
  }
299
299
}
300
300
301
void SectionsIO::loadTheStructure(QDomElement& elt, SectionGroup* root)
301
void SectionsIO::loadTheStructure(QDomElement& elt, SectionGroup* root, KoUndoStack* _stack)
302
302
{
303
303
  QDomNode n = elt.firstChild();
304
304
  while(!n.isNull()) {
305
305
    QDomElement e = n.toElement(); // try to convert the node to an element.
306
306
    if(!e.isNull() and e.nodeName() == "Section" ) {
307
      Section* section = new Section();
307
      Section* section = new Section(_stack);
308
308
      QString name = e.attribute("name", "");
309
309
      if(name.isEmpty())
310
310
      {
@@ -316,7 +316,7 @@ void SectionsIO::loadTheStructure(QDomEl
316
316
      context->filename = e.attribute("filename", "");
317
317
      context->section = section;
318
318
      m_contextes[section] = context;
319
      loadTheStructure(e, section);
319
      loadTheStructure(e, section, _stack);
320
320
    }
321
321
    n = n.nextSibling();
322
322
  }
@@ -337,7 +337,7 @@ void SectionsIO::load()
337
337
  QDomElement docElem = doc.documentElement();
338
338
  if(docElem.nodeName() != "RootElement") return;
339
339
340
  loadTheStructure(docElem, m_rootSection);
340
  loadTheStructure(docElem, m_rootSection, m_rootSection->undoStack());
341
341
  
342
342
  // Second: load each section
343
343
  foreach(SaveContext* saveContext, m_contextes)

Up to file-list src/SectionsIO.h:

@@ -29,6 +29,7 @@ class QTimer;
29
29
class RootSection;
30
30
class Section;
31
31
class SectionGroup;
32
class KoUndoStack;
32
33
33
34
class SectionsIO : public QObject {
34
35
  Q_OBJECT
@@ -62,7 +63,7 @@ class SectionsIO : public QObject {
62
63
     *                        associated files
63
64
     */
64
65
    void saveTheStructure(QDomDocument& doc, QDomElement& elt, SectionGroup* root, QList<SaveContext*>& contextToRemove);
65
    void loadTheStructure(QDomElement& elt, SectionGroup* root);
66
    void loadTheStructure(QDomElement& elt, SectionGroup* root, KoUndoStack* _stack);
66
67
    QString generateFileName();
67
68
    bool usedFileName(const QString&);
68
69
    QString structureFileName();

Up to file-list src/View.cpp:

@@ -292,7 +292,6 @@ void View::setActiveSection( Section* pa
292
292
293
293
  if(m_activeSection)
294
294
  {
295
    m_activeSection->sectionContainer()->setUndoStack(rootSection()->undoStack());
296
295
    QList<KoShape*> shapes;
297
296
    shapes.push_back(page->sectionContainer()->layer());
298
297
    shapeManager()->setShapes( shapes, KoShapeManager::AddWithoutRepaint );