
Originally Posted by
amleto
honestly, it looks like something knows 'too much'. Why does anything need to know about all leftsides?
A leftside is a group of widgets (textedit, lineedit, treeview and some buttons) used to show text of files from a compressed one. User may want to open more compressed files simultaneously but in different tabs. So when a new compressed file is opened, a new leftside instance is created and this is showed in one tab. So far so good.. :-) Then wanted to give the user the possibility to create a new tab and look at a different file of the same compressed file. So a new leftside instance is created and showed in another tab.
Moreover, I wanted to give the user the possibility to open also a new compressed files in another tab and look at the files of it possibly in different tabs. So even more leftside instances.
An unlimited number of leftside can be created.. My solution was:
instead of naming all them in a different way (page1, page2, page3....), I though it was much simple to always use the same pointer name, "page", and change the assigment of it "at need", before actually using it. So:
A tab is created:
page = new LeftSide(this);
pageWidgets->append(page);
page->setDir;
page->setModel();
page->show();
page = new LeftSide(this);
pageWidgets->append(page);
page->setDir;
page->setModel();
page->show();
To copy to clipboard, switch view to plain text mode
Another tab is created:
page = new LeftSide(this); // page now points to a different leftside object in the heap but the previous one is still there
pageWidgets->append(page);
page->setDir;
page->setModel();
page->show();
page = new LeftSide(this); // page now points to a different leftside object in the heap but the previous one is still there
pageWidgets->append(page);
page->setDir;
page->setModel();
page->show();
To copy to clipboard, switch view to plain text mode
and then when moving among all the different pages
page = pageWidgets(tab->currentIndex());
page->setDir;
page->setModel();
page->show();
page = pageWidgets(tab->currentIndex());
page->setDir;
page->setModel();
page->show();
To copy to clipboard, switch view to plain text mode
[/CODE]
So to sum up, I created unlimited leftside objects in the heap and use the same pointer name for them and I change the assigments of it to always point to the right one (lists are used to keep track of all of them in memory)
Not sure it is clear, code is actually much longer and I reported here only very few parts which hopefully make you understand.
Thanks,
Jan
Bookmarks