[Ktutorial-commits] SF.net SVN: ktutorial:[199] trunk/ktutorial/ktutorial-editor/src
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-27 04:25:20
|
Revision: 199 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=199&view=rev Author: danxuliu Date: 2010-03-27 04:25:13 +0000 (Sat, 27 Mar 2010) Log Message: ----------- Add action to create a new tutorial, replacing the current one Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-26 21:03:26 UTC (rev 198) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-03-27 04:25:13 UTC (rev 199) @@ -48,12 +48,16 @@ //public: -KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0) { +KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0), + mTutorial(0), + mCurrentStep(0), + mCurrentReaction(0) { + mTreeView = new QTreeView(); mTreeView->setObjectName("centralTreeView"); setCentralWidget(mTreeView); - setupTutorialToBeEdited(); + setTutorialToBeEdited(); setupDocks(); @@ -64,22 +68,41 @@ //private: -void KTutorialEditor::setupTutorialToBeEdited() { - mTutorial = new Tutorial(this); +void KTutorialEditor::setTutorialToBeEdited(Tutorial* tutorial) { + if (!tutorial) { + tutorial = new Tutorial(this); + } - TutorialTreeItem* tutorialTreeItem = new TutorialTreeItem(mTutorial); + //Clear the selection model to ensure that the actions are disabled as + //needed when the selection model is replaced + if (mTreeView->selectionModel()) { + mTreeView->selectionModel()->clear(); + } + + TutorialTreeItem* tutorialTreeItem = new TutorialTreeItem(tutorial); TreeModel* model = new TreeModel(tutorialTreeItem, mTreeView); + //Neither the old model nor the old selection model are deleted by the + //QTreeView when a new model is set (which creates a new selection model), + //so it must be done explicitly + QItemSelectionModel* oldSelectionModel = mTreeView->selectionModel(); QAbstractItemModel* oldModel = mTreeView->model(); mTreeView->setModel(model); + delete oldSelectionModel; delete oldModel; + //Parent object is set to the selection model, so the manager is also + //deleted when the selection model it watches is deleted TutorialTreeSelectionManager* selectionManager = - new TutorialTreeSelectionManager(mTreeView->selectionModel(), this); + new TutorialTreeSelectionManager(mTreeView->selectionModel(), + mTreeView->selectionModel()); connect(selectionManager, SIGNAL(stepSelected(Step*)), this, SLOT(selectStep(Step*))); connect(selectionManager, SIGNAL(reactionSelected(Reaction*)), this, SLOT(selectReaction(Reaction*))); + + delete mTutorial; + mTutorial = tutorial; } void KTutorialEditor::setupDocks() { @@ -99,6 +122,8 @@ } void KTutorialEditor::setupActions() { + KStandardAction::openNew(this, SLOT(newTutorial()), actionCollection()); + KAction* action = new KAction(this); action->setText(i18nc("@action", "Export...")); action->setStatusTip(i18nc("@info:status", "Exports the tutorial to a " @@ -286,6 +311,10 @@ } } +void KTutorialEditor::newTutorial() { + setTutorialToBeEdited(); +} + void KTutorialEditor::exportTutorial() { KUrl url; QPointer<KFileDialog> dialog = new KFileDialog(url, QString(), this); Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-26 21:03:26 UTC (rev 198) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-03-27 04:25:13 UTC (rev 199) @@ -78,11 +78,15 @@ Reaction* mCurrentReaction; /** - * Sets up the tutorial to be edited. + * Sets the tutorial to be edited. * It creates a new tutorial, prepares the tree view to represent it and * handles the selection of items. + * + * If the tutorial is null, a new empty tutorial is set. + * + * @param tutorial The tutorial to set. */ - void setupTutorialToBeEdited(); + void setTutorialToBeEdited(Tutorial* tutorial = 0); /** * Sets up the dock widgets. @@ -123,6 +127,11 @@ void selectReaction(Reaction* reaction); /** + * Creates a new empty tutorial replacing the current one, if any. + */ + void newTutorial(); + + /** * Shows a KFileDialog to select the file to save the exported tutorial in. * An error message is shown if the tutorial couldn't be saved. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |