[SOLVED] how to have only one instance of a tab in MDIarea
-
The problem that I'm facing at the moment is hw can I have only one instance of a tab in mdi area.
@void AtpMainWindow::onActCompEditCompany(){
//FIXME only one tab of company editor - no need of many to be opened
/*
AtpCompanyEdit *mdiChild;foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
mdiChild = qobject_cast<AtpCompanyEdit *>(window->widget());}
if(mdiChild){
mdiArea->setActiveSubWindow(mdiChild);
} else {
*/
AtpCompanyEdit *companyEditor = new AtpCompanyEdit;
companyEditor->setAttribute(Qt::WA_DeleteOnClose);
//possible windows to close
connect(companyEditor, SIGNAL(exitSignal()), actFileClose, SLOT(trigger()));
mdiArea->addSubWindow(companyEditor);
companyEditor->show();
companyEditor->activateWindow();
// }
}@this is what I have at the moment... is working fine except that if the user want to open 100 tabs nothing is stopping him from that. also this is editing a SQLite dataBase and I do not want in one tab to delete a company and in another tab to edit the same company... so I will need only one tab for this. my idea is to have like an id or something like that because I have classes that will need to open many times like a list of invoices where a user can click on invoice and open up it's details (based on id he can open many invoice details at once but only one of same id)
any help... Highly appreciated..
thanks
Andrew -
Hi,
Just make it a member variable, create in the constructor and only show it in onActCompEditCompany
Hope it helps
-
yep I've tried that and is working but the second problem is not sorted out
- my idea is to have like an id or something like that because I have classes that will need to open many times like a list of invoices where a user can click on invoice and open up it’s details (based on id he can open many invoice details at once but only one of same id)
-
You can keep a QVector of opened record, since every invoices will have a unique primary key you can use it for identification.
-
good point... I will try it in few moments and I'll let you know the result. Thanks for now...
-
ok... is working but what is the impact on the memory??
-
It depends on how you manage your vector. It should not contain more element that the number of current opened records.
-
yes this it will be a bit difficult to implement it but I hope at the end to get a good management on tab closer. the thing is that I have always to keep the vector or in my idea a QMap<QString, QWidget>, synchronised. but I'll think about because every class that I have is a class that extended QWidget @class ATPCOMPANY_EXPORT AtpCompanyGroupPlace : public QWidget@ or @class ATPCLIENT_EXPORT AtpClientInvoices : public QWidget@.
Ok.thanks.. I'll mark it Solved as this is an obvious solution (I do not know if this is the only one... but... I will further search or research )
Thanks for your help..... you can have a look at "github":https://github.com/arsinte-andrei/electricity in order to see the project that I'm speaking about -
@void AtpMainWindow::onActCompEditCompany(){
AtpCompanyEdit *mdiChild;
foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
mdiChild = qobject_cast<AtpCompanyEdit *>(window->widget());
if(mdiChild){
mdiArea->setActiveSubWindow(window);
return;
}
}AtpCompanyEdit *companyEditor = new AtpCompanyEdit;
companyEditor->setAttribute(Qt::WA_DeleteOnClose);
//possible windows to close
connect(companyEditor, SIGNAL(exitSignal()), actFileClose, SLOT(trigger()));
mdiArea->addSubWindow(companyEditor);
companyEditor->show();
companyEditor->activateWindow();
}@this is looking to be also a solution without using a Vector and without to maintain a vector. this is iterating all the mdiArea subwindows and check for my class if is opened. if it is then it just bring it up. - found it in the MDI example that came with Qt