added new document function

pull/16/head
Marc Zinnschlag 12 years ago
parent 997386d873
commit 303506d24b

@ -1,20 +1,28 @@
#include "editor.hpp"
#include <sstream>
#include <QtGui/QApplication>
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();

@ -1,13 +1,19 @@
#ifndef CS_EDITOR_H
#define CS_EDITOR_H
#include <QObject>
#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();
};
}

@ -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;

@ -1,6 +1,8 @@
#ifndef CSM_DOC_DOCUMENT_H
#define CSM_DOC_DOCUMENT_H
#include <string>
#include <QUndoStack>
#include <QObject>
#include <QTimer>
@ -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();

@ -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);

@ -2,6 +2,7 @@
#define CSM_DOC_DOCUMENTMGR_H
#include <vector>
#include <string>
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);

@ -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);

@ -69,6 +69,10 @@ namespace CSVDoc
void updateProgress (int current, int max, int type, int threads);
signals:
void newDocumentRequest();
private slots:
void newView();

@ -56,6 +56,8 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
view->show();
connect (view, SIGNAL (newDocumentRequest ()), this, SIGNAL (newDocumentRequest()));
updateIndices();
return view;

@ -42,6 +42,10 @@ namespace CSVDoc
bool closeRequest (View *view);
signals:
void newDocumentRequest();
private slots:
void documentStateChanged (int state, CSMDoc::Document *document);

Loading…
Cancel
Save