Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Initialising view from data structure on new/open document

Posted on 2005-04-14
8
Medium Priority
?
271 Views
Last Modified: 2013-11-20
Ah hello.

Bit of an ongoing saga for me at the minute, but I just need some clarification.

I have a data structure of sorts that is in my document.

class CItem{}; // abstract

class CConcreteItem : public CItem {};

class CContainer : public CItem // abstract
{
protected:
  std::list<CItem*>m_pContents;
};

class CConcreteContainer : public CContainer {}

class CProject : public CContainer  {};

As you can see this is based on the composite design pattern.  *A lot of funtionality is missing, eg constructors etc for clarity*.

In my document, I have a CProject* instance.  The is the data structure that is to be respresented in my view class, which is a CTreeView.

As I add more and more items to my data structure, my tree view will need updating.  I have already been advised how to do that, but am not sure on how I should start out when the user creates a new document and opens an existing document.

I have, in my document class:

OnNewDocument()
{
  m_pCategories = new CProject(_T("Untitled project"));
}

Now, from this, OnInitialUpdate() will get called in the view, so I believe it is there that I need to call some method in the document class to get m_pCategories, and then loop through it to output its contents to the view, correct ?  Or should this be done in OnUpdate, since OnInitialUpdate() calls OnUpdate()...

Regarding opening, after I have serialized the data in to my data structure, where do I go from there ?

Thanks.
0
Comment
Question by:mrwad99
  • 4
  • 2
  • 2
8 Comments
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 500 total points
ID: 13780904
OnInitialUpdate vs OnUpdate.  Difficult to advise.  I would tend towards to OnUpdate because of your further comment regarding serialisation and opening a document.  That would cover the case of loading in a new project into your existing document (because OnInitialUpdate is called just once).
<However it could even be appropriate to have some of this code in the OnDraw and in the OnUpdate just invalidate the client area that needs to be redrawn>


Regarding opening, after I have serialized the data in to my data structure, where do I go from there ?
At this point you need to flag all views that the data they display in invalid and needs redrawing - UpdateAllViews with a hint ;-)

Sorry to be so general and vague.
0
 
LVL 9

Accepted Solution

by:
rcarlan earned 500 total points
ID: 13781310
Provide a method in the view that can reset its contents (i.e. remove all existing nodes and re-build the tree from the document). You could call it Reset, for example.

Call this method in OnInitialUpdate and in OnUpdate when there's no hint object.

After you reload the document, call UpdateAllViews with no hint.

Radu
0
 
LVL 19

Author Comment

by:mrwad99
ID: 13781442
Heh, you two should work together :)

Thanks Andy and Radu once again.  What it looks like you are both saying is to have an execution path like this:  (please comment)

For responding to file->new:

1) OnNewDocument() gets called; this re-initialises m_pCategories as stated above.

2) Call UpdateAllViews(), passing no hint.

3) OnInitialUpdate() gets called (or will it ?).  I do a test to determine if there is a hint parameter, which there will not be.  Then call a method to clear the tree out, call a method to get the data from the document, and output it.

{
  if (pHint == NULL) // or whatever
  {
     ClearTree();
     CConcreteContainer* pCont = GetDocument()->GetData();  // or similar
     MethodToOutputData();
  }
}

So is this in OnInitialUpdate() or OnUpdate() ?  And why ?

Thanks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:rcarlan
ID: 13781531
You have to put the code in a separate method and call it from both OnInitialUpdate and OnUpdate.

OnUpdate would be called as a result of OnOpenDocument. OnInitialUpdate would be executed when initialising the view (e.g. after OnNewDocument and as a result of the New Window menu command).

Radu
0
 
LVL 19

Author Comment

by:mrwad99
ID: 13782031
OK, cool, but would that not mean that the code will get executed twice, since the default implementation of OnInitialUpdate calls onUpdate ?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 13784204
The OnInitialUpdate is called once and once only - when the view is created.  I think it just needs to be in the OnUpdate (or OnDraw).  It depends exactly what view you are talking about.  A view that wraps a control (CTreeView, CListView....) can be updated at the OnUpdate call.  If the view is drawing the contents itself then this code really belongs in the OnDraw, the OnUpdate will use the hint to determine how much (if any) of the view is to be invalidated.
0
 
LVL 19

Author Comment

by:mrwad99
ID: 13798167
Hi Again;

related question at http:Q_21391370.html.

I will close this one shortly.  Thanks.
0
 
LVL 19

Author Comment

by:mrwad99
ID: 13834605
Thanks both.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question