*view & *doc relationship
Hauke.Hildebrandt at iup.uni-heidelberg.de
Fri Apr 7 08:39:53 UTC 2000
> I'm not quite as far along as you are. My lack of understanding right now has
> to do with getting the data from the doc to the view. Take the "simple" example
> of the html viewer. I changed the base class for the view to KHTMLWidget.
> Now, I set a QString to point to an html file and create a new instance of
> KHTMLWidget in the App constructor. Of course, to get it to view, I have to do
> a show() which creates a new window seperate from the main view. I am not
> connecting the app, doc, and views. Perhaps I shouldn't be creating the
> instance of KHTMLWidget in the App constructor but if I don't, how do I get the
> data in? Perhaps I'm mixing things up to much? I've been working my way through
> the tutorials and the kscribble example but maybe I need to go back to that and
> put more time into it.
> I just noticed a couple more articles came in on this thread. I'll give them a
Well, the other postings about this topic make a lot of things clearer.
About your special app:
1) You create the KHTML widget by creating a new instance of your View
class. This is done in the Apps constructor by calling the initView()
method. Of course, you can add further methods that create additional
2) The widget's data are stored as private members in the document
class. When you open a file, the document class reads the files contents
and stores them in its members. Neither the App nor the view class have
direct access to the data. Instead, the document provides methods like
doc::htmlText() or doc::gifList() that provides access to them.
3) The document knows which views are connected to it via the static
member viewList. When you create a new view of a document you have to
call the doc->addView(View*) method so that the document knows there's
another view connected to it. When the document changes its data (e.g.
you add a new gif) it can look into its viewList and decide which views
must be redrawn - eg if all views should be redrawn it calls the
4) The View has a pointer to the App (using the parentWidget() method).
Using this it can get a pointer to the document that it represents (look
at the getDocument() method). Now, using this pointer it gets access to
the document's data (via the access methods, see 2)). So if a view
object shows the doc's text on the screen and wants to redraw itself it
calls something like
Maybe this helps a little, don't despair,
Institut für Umweltphysik
email: hauke.hildebrandt at iup.uni-heidelberg.de
More information about the KDevelop