From 303506d24b00a0bbcbb7f796fa071b5f750c3be9 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 23 Nov 2012 14:05:49 +0100 Subject: [PATCH] added new document function --- apps/opencs/editor.cpp | 12 ++++++++++-- apps/opencs/editor.hpp | 14 +++++++++++--- apps/opencs/model/doc/document.cpp | 9 ++++++++- apps/opencs/model/doc/document.hpp | 9 ++++++++- apps/opencs/model/doc/documentmanager.cpp | 4 ++-- apps/opencs/model/doc/documentmanager.hpp | 3 ++- apps/opencs/view/doc/view.cpp | 8 ++++++-- apps/opencs/view/doc/view.hpp | 4 ++++ apps/opencs/view/doc/viewmanager.cpp | 2 ++ apps/opencs/view/doc/viewmanager.hpp | 4 ++++ 10 files changed, 57 insertions(+), 12 deletions(-) diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 264ae75434..c03a1dc5dc 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -1,20 +1,28 @@ #include "editor.hpp" +#include + #include -CS::Editor::Editor() : mViewManager (mDocumentManager) +CS::Editor::Editor() : mViewManager (mDocumentManager), mNewDocumentIndex (0) { + connect (&mViewManager, SIGNAL (newDocumentRequest ()), this, SLOT (createDocument ())); } void CS::Editor::createDocument() { - CSMDoc::Document *document = mDocumentManager.addDocument(); + std::ostringstream stream; + + stream << "NewDocument" << (++mNewDocumentIndex); + + CSMDoc::Document *document = mDocumentManager.addDocument (stream.str()); mViewManager.addView (document); } int CS::Editor::run() { + /// \todo Instead of creating an empty document, open a small welcome dialogue window with buttons for new/load/recent projects createDocument(); return QApplication::exec(); diff --git a/apps/opencs/editor.hpp b/apps/opencs/editor.hpp index 6e183b843b..60f7beaf1d 100644 --- a/apps/opencs/editor.hpp +++ b/apps/opencs/editor.hpp @@ -1,13 +1,19 @@ #ifndef CS_EDITOR_H #define CS_EDITOR_H +#include + #include "model/doc/documentmanager.hpp" #include "view/doc/viewmanager.hpp" namespace CS { - class Editor + class Editor : public QObject { + Q_OBJECT + + int mNewDocumentIndex; ///< \todo remove when the proper new document dialogue is implemented. + CSMDoc::DocumentManager mDocumentManager; CSVDoc::ViewManager mViewManager; @@ -19,10 +25,12 @@ namespace CS Editor(); - void createDocument(); - int run(); ///< \return error status + + public slots: + + void createDocument(); }; } diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 5c39e16c0f..cd65e83aef 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -1,8 +1,10 @@ #include "document.hpp" -CSMDoc::Document::Document() +CSMDoc::Document::Document (const std::string& name) { + mName = name; ///< \todo replace with ESX list + connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool))); // dummy implementation -> remove when proper save is implemented. @@ -35,6 +37,11 @@ int CSMDoc::Document::getState() const return state; } +const std::string& CSMDoc::Document::getName() const +{ + return mName; +} + void CSMDoc::Document::save() { mSaveCount = 1; diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index e691bb38f6..0249d8e5ce 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -1,6 +1,8 @@ #ifndef CSM_DOC_DOCUMENT_H #define CSM_DOC_DOCUMENT_H +#include + #include #include #include @@ -21,6 +23,7 @@ namespace CSMDoc State_Verifying = 8 }; + std::string mName; ///< \todo replace name with ESX list QUndoStack mUndoStack; int mSaveCount; ///< dummy implementation -> remove when proper save is implemented. @@ -35,12 +38,16 @@ namespace CSMDoc public: - Document(); + Document (const std::string& name); + ///< \todo replace name with ESX list QUndoStack& getUndoStack(); int getState() const; + const std::string& getName() const; + ///< \todo replace with ESX list + void save(); void verify(); diff --git a/apps/opencs/model/doc/documentmanager.cpp b/apps/opencs/model/doc/documentmanager.cpp index 68595f2d41..8ae2764f24 100644 --- a/apps/opencs/model/doc/documentmanager.cpp +++ b/apps/opencs/model/doc/documentmanager.cpp @@ -14,9 +14,9 @@ CSMDoc::DocumentManager::~DocumentManager() delete *iter; } -CSMDoc::Document *CSMDoc::DocumentManager::addDocument() +CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::string& name) { - Document *document = new Document; + Document *document = new Document (name); mDocuments.push_back (document); diff --git a/apps/opencs/model/doc/documentmanager.hpp b/apps/opencs/model/doc/documentmanager.hpp index f20f3101d9..730c7fae1d 100644 --- a/apps/opencs/model/doc/documentmanager.hpp +++ b/apps/opencs/model/doc/documentmanager.hpp @@ -2,6 +2,7 @@ #define CSM_DOC_DOCUMENTMGR_H #include +#include namespace CSMDoc { @@ -20,7 +21,7 @@ namespace CSMDoc ~DocumentManager(); - Document *addDocument(); + Document *addDocument (const std::string& name); ///< The ownership of the returned document is not transferred to the caller. bool removeDocument (Document *document); diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 8ed1f83b8d..5c7199aa4b 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -21,6 +21,10 @@ void CSVDoc::View::setupFileMenu() { QMenu *file = menuBar()->addMenu (tr ("&File")); + QAction *new_ = new QAction (tr ("New"), this); + connect (new_, SIGNAL (triggered()), this, SIGNAL (newDocumentRequest())); + file->addAction (new_); + mSave = new QAction (tr ("&Save"), this); connect (mSave, SIGNAL (triggered()), this, SLOT (save())); file->addAction (mSave); @@ -75,7 +79,7 @@ void CSVDoc::View::updateTitle() { std::ostringstream stream; - stream << "New Document "; + stream << mDocument->getName(); if (mDocument->getState() & CSMDoc::Document::State_Modified) stream << " *"; @@ -104,7 +108,7 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to : mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews) { setCentralWidget (new QWidget); - resize (200, 200); + resize (200, 200); /// \todo get default size from settings and set reasonable minimal size mOperations = new Operations; addDockWidget (Qt::BottomDockWidgetArea, mOperations); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 15394a7d85..d15d942fc0 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -69,6 +69,10 @@ namespace CSVDoc void updateProgress (int current, int max, int type, int threads); + signals: + + void newDocumentRequest(); + private slots: void newView(); diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 673afbad82..22847c78b7 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -56,6 +56,8 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) view->show(); + connect (view, SIGNAL (newDocumentRequest ()), this, SIGNAL (newDocumentRequest())); + updateIndices(); return view; diff --git a/apps/opencs/view/doc/viewmanager.hpp b/apps/opencs/view/doc/viewmanager.hpp index caf75a0cdb..5e4b1be075 100644 --- a/apps/opencs/view/doc/viewmanager.hpp +++ b/apps/opencs/view/doc/viewmanager.hpp @@ -42,6 +42,10 @@ namespace CSVDoc bool closeRequest (View *view); + signals: + + void newDocumentRequest(); + private slots: void documentStateChanged (int state, CSMDoc::Document *document);