display view indices in title bar

actorid
Marc Zinnschlag 12 years ago
parent 789cecb9df
commit 1ddcea1f07

@ -1,7 +1,7 @@
#include "view.hpp"
#include <iostream>
#include <sstream>
#include <QCloseEvent>
#include <QMenuBar>
@ -16,7 +16,7 @@ void CSVDoc::View::closeEvent (QCloseEvent *event)
void CSVDoc::View::setupUi()
{
// window menu
// view menu
QMenu *view = menuBar()->addMenu (tr ("&View"));
QAction *newWindow = new QAction (tr ("&New View"), this);
@ -25,12 +25,25 @@ void CSVDoc::View::setupUi()
view->addAction (newWindow);
}
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document)
: mViewManager (viewManager), mDocument (document)
void CSVDoc::View::updateTitle()
{
std::ostringstream stream;
stream << "New Document ";
if (mViewTotal>1)
stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]";
setWindowTitle (stream.str().c_str());
}
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews)
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews)
{
setCentralWidget (new QWidget);
resize (200, 200);
setWindowTitle ("New Document");
updateTitle();
setupUi();
}
@ -45,6 +58,13 @@ CSMDoc::Document *CSVDoc::View::getDocument()
return mDocument;
}
void CSVDoc::View::setIndex (int viewIndex, int totalViews)
{
mViewIndex = viewIndex;
mViewTotal = totalViews;
updateTitle();
}
void CSVDoc::View::newView()
{
mViewManager.addView (mDocument);

@ -20,6 +20,8 @@ namespace CSVDoc
ViewManager& mViewManager;
CSMDoc::Document *mDocument;
int mViewIndex;
int mViewTotal;
// not implemented
View (const View&);
@ -31,15 +33,19 @@ namespace CSVDoc
void setupUi();
void updateTitle();
public:
View (ViewManager& viewManager, CSMDoc::Document *document);
View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);
///< The ownership of \a document is not transferred to *this.
const CSMDoc::Document *getDocument() const;
CSMDoc::Document *getDocument();
void setIndex (int viewIndex, int totalViews);
private slots:
void newView();

@ -1,10 +1,30 @@
#include "viewmanager.hpp"
#include <map>
#include "../../model/doc/documentmanager.hpp"
#include "view.hpp"
void CSVDoc::ViewManager::updateIndices()
{
std::map<CSMDoc::Document *, std::pair<int, int> > documents;
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
{
std::map<CSMDoc::Document *, std::pair<int, int> >::iterator document = documents.find ((*iter)->getDocument());
if (document==documents.end())
document =
documents.insert (
std::make_pair ((*iter)->getDocument(), std::make_pair (0, countViews ((*iter)->getDocument())))).
first;
(*iter)->setIndex (document->second.first++, document->second.second);
}
}
CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
: mDocumentManager (documentManager)
{
@ -22,12 +42,14 @@ CSVDoc::ViewManager::~ViewManager()
CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
{
View *view = new View (*this, document);
View *view = new View (*this, document, countViews (document)+1);
mViews.push_back (view);
view->show();
updateIndices();
return view;
}
@ -57,6 +79,8 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
if (last)
mDocumentManager.removeDocument (view->getDocument());
else
updateIndices();
}
return true;

@ -23,6 +23,8 @@ namespace CSVDoc
ViewManager (const ViewManager&);
ViewManager& operator= (const ViewManager&);
void updateIndices();
public:
ViewManager (CSMDoc::DocumentManager& documentManager);

Loading…
Cancel
Save