#include "viewmanager.hpp" #include "../../model/doc/documentmanager.hpp" #include "view.hpp" CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) : mDocumentManager (documentManager) { } CSVDoc::ViewManager::~ViewManager() { for (std::vector::iterator iter (mViews.begin()); iter!=mViews.end(); ++iter) delete *iter; for (std::vector::iterator iter (mClosed.begin()); iter!=mClosed.end(); ++iter) delete *iter; } CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) { View *view = new View (*this, document); mViews.push_back (view); view->show(); return view; } int CSVDoc::ViewManager::countViews (const CSMDoc::Document *document) const { int count = 0; for (std::vector::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter) if ((*iter)->getDocument()==document) ++count; return count; } bool CSVDoc::ViewManager::closeRequest (View *view) { std::vector::iterator iter = std::find (mViews.begin(), mViews.end(), view); if (iter!=mViews.end()) { bool last = countViews (view->getDocument())<=1; /// \todo check if document has not been saved -> return false and start close dialogue mViews.erase (iter); mClosed.push_back (view); if (last) mDocumentManager.removeDocument (view->getDocument()); } return true; }