• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • kasten
  • gui
  • system
viewmanager.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2006,2008-2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "viewmanager.h"
24 
25 // lib
26 #include "abstractviewfactory.h"
27 #include "dummyview.h"
28 // Qt
29 #include <QtCore/QListIterator>
30 #include <QtCore/QMutableListIterator>
31 
32 // temporary
33 #include "modelcodecviewmanager.h"
34 
35 #include <KDebug>
36 namespace Kasten2
37 {
38 
39 ViewManager::ViewManager()
40  : mCodecViewManager( new ModelCodecViewManager() )
41 {
42 }
43 
44 
45 void ViewManager::setViewFactory( AbstractViewFactory* factory )
46 {
47  mFactory = factory;
48 }
49 
50 QList<AbstractView*> ViewManager::views() const
51 {
52  return mViewList;
53 }
54 
55 AbstractView* ViewManager::viewByWidget( QWidget* widget ) const
56 {
57  AbstractView* result = 0;
58 
59  QListIterator<AbstractView*> it( mViewList );
60  while( it.hasNext() )
61  {
62  AbstractView* view = it.next();
63  if( view->widget() == widget)
64  {
65  result = view;
66  break;
67  }
68  }
69  return result;
70 }
71 
72 void ViewManager::createCopyOfView( AbstractView* view, Qt::Alignment alignment )
73 {
74  AbstractView* viewCopy = mFactory->createCopyOfView( view, alignment );
75  if( ! viewCopy )
76  {
77  AbstractDocument* documentOfView = view->findBaseModel<AbstractDocument*>();
78  viewCopy = new DummyView( documentOfView );
79  }
80 
81  mViewList.append( viewCopy );
82 
83  QList<Kasten2::AbstractView*> views;
84  views.append( viewCopy );
85 
86  emit opened( views );
87 }
88 
89 void ViewManager::createViewsFor( const QList<Kasten2::AbstractDocument*>& documents )
90 {
91  QList<Kasten2::AbstractView*> openedViews;
92 
93  foreach( AbstractDocument* document, documents )
94  {
95  AbstractView* view = mFactory->createViewFor( document );
96  if( ! view )
97  view = new DummyView( document );
98 
99  mViewList.append( view );
100  openedViews.append( view );
101  }
102 
103  if( ! openedViews.isEmpty() )
104  emit opened( openedViews );
105 }
106 
107 
108 void ViewManager::removeViewsFor( const QList<Kasten2::AbstractDocument*>& documents )
109 {
110  QList<Kasten2::AbstractView*> closedViews;
111 
112  QMutableListIterator<AbstractView*> it( mViewList );
113  foreach( AbstractDocument* document, documents )
114  {
115  while( it.hasNext() )
116  {
117  AbstractView* view = it.next();
118  AbstractDocument* documentOfView = view->findBaseModel<AbstractDocument*>();
119  if( documentOfView == document )
120  {
121  it.remove();
122  closedViews.append( view );
123  }
124  }
125  it.toFront();
126  }
127 
128  emit closing( closedViews );
129 
130  foreach( AbstractView* view, closedViews )
131  {
132  kDebug()<<view->title();
133  delete view;
134  }
135 }
136 
137 void ViewManager::removeViews( const QList<AbstractView*>& views )
138 {
139  foreach( AbstractView* view, views )
140  mViewList.removeOne( view );
141 
142  emit closing( views );
143 
144  foreach( AbstractView* view, views )
145  {
146  kDebug()<<view->title();
147  delete view;
148  }
149 }
150 
151 
152 ViewManager::~ViewManager()
153 {
154  // TODO: signal closing here, too?
155  qDeleteAll( mViewList );
156 
157  delete mCodecViewManager;
158  delete mFactory;
159 }
160 
161 }
Kasten2::AbstractView
Definition: abstractview.h:38
Kasten2::ViewManager::~ViewManager
virtual ~ViewManager()
Definition: viewmanager.cpp:152
Kasten2::DummyView
Definition: dummyview.h:36
Kasten2::AbstractModel::title
virtual QString title() const =0
Kasten2::ViewManager::opened
void opened(const QList< Kasten2::AbstractView * > &views)
Kasten2::ViewManager::setViewFactory
void setViewFactory(AbstractViewFactory *factory)
Definition: viewmanager.cpp:45
QWidget
Kasten2::AbstractViewFactory::createViewFor
virtual AbstractView * createViewFor(AbstractDocument *document)=0
abstractviewfactory.h
Kasten2::ViewManager::viewByWidget
AbstractView * viewByWidget(QWidget *widget) const
Definition: viewmanager.cpp:55
Kasten2::ViewManager::views
QList< AbstractView * > views() const
Definition: viewmanager.cpp:50
Kasten2::AbstractModel::findBaseModel
T findBaseModel() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:93
Kasten2::AbstractViewFactory
Definition: abstractviewfactory.h:33
Kasten2::AbstractDocument
Definition: abstractdocument.h:43
Kasten2::AbstractView::widget
virtual QWidget * widget() const =0
Kasten2::AbstractViewFactory::createCopyOfView
virtual AbstractView * createCopyOfView(AbstractView *view, Qt::Alignment alignment=0)
Definition: abstractviewfactory.h:51
dummyview.h
Kasten2::ViewManager::ViewManager
ViewManager()
Definition: viewmanager.cpp:39
Kasten2::ModelCodecViewManager
Definition: modelcodecviewmanager.h:50
Kasten2::ViewManager::removeViewsFor
void removeViewsFor(const QList< Kasten2::AbstractDocument * > &documents)
Definition: viewmanager.cpp:108
Kasten2::ViewManager::closing
void closing(const QList< Kasten2::AbstractView * > &views)
Kasten2::ViewManager::createViewsFor
void createViewsFor(const QList< Kasten2::AbstractDocument * > &documents)
Definition: viewmanager.cpp:89
Kasten2::ViewManager::removeViews
void removeViews(const QList< AbstractView * > &views)
Definition: viewmanager.cpp:137
modelcodecviewmanager.h
viewmanager.h
Kasten2::ViewManager::createCopyOfView
void createCopyOfView(AbstractView *view, Qt::Alignment alignment=0)
Definition: viewmanager.cpp:72
QList
Definition: bookmarkable.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal