void MainForm::showCalculator(){ if(calcWindow == 0) { QAction *a = qobject_cast<QAction *>(sender()); calcWindow = new CalcWindow(a, m_Settings, false, this); calcWindow->show(); } else if(calcWindow->isVisible() && (lastFocusForm = f_CalacWindow)) calcWindow->close(); else calcWindow->show();}
void MainForm::showCalculator(AbstractWindow w){ if(w == 0) w = new ... // а вот тут чтоб вызывался конструктор не AbstractWindow , а наследника?
AbstractWindow *MainForm::instance(const QString &win_name){int id = QMetaType::type(win_name.toUtf8());if(id) return (AbstractWindow*)QMetaType::construct(id);return NULL;}
Q_DECLARE_METATYPE(CalcWindow(QAction *a, QSettings *s, bool isModal, QWidget *parent))
QPointer<CalcWindow> calcWindow;
typedef void (*ShowFunc)(void);QAction* MainForm::createActionForWindows(QString winName, ShowFunc f){ QAction *a = new QAction(winName, 0); connect(a, SIGNAL(triggered()), SLOT(f)); a->setCheckable(true); a->setObjectName(winName); if(m_Settings->value("MainSetup/" + winName, false).toBool()) a->trigger(); return a;}void MainForm::showCalculator(){ if(calcWindow == 0) { QAction *a = qobject_cast<QAction *>(sender()); calcWindow = new CalcWindow(a, m_Settings, false, this); calcWindow->show(); } else if(calcWindow->isVisible() && (lastFocusForm = f_CalacWindow)) calcWindow->close(); else calcWindow->show();}
QAction *w1 = createActionForWindows("Calculator", showCalculator);
QAction* MainForm::createActionForWindows(QString winName, ShowFunc f){ ... connect(a, SIGNAL(triggered()), SLOT(f));
C++ (Qt)AbstractWindow * MyCreateWindow( int ID. ... ){ switch (ID) { case ID_CALC: return new CalcWindow(..); ... } assert(0); return 0;}
void MainForm::showWindow(){ QAction *a = qobject_cast<QAction *>(sender()); AbstractLogWindow *w = findWindow(a->objectName()); if(w != 0) { if(a->data().toInt() != int(lastFocusForm)) w->show(); else w->close(); } else { w = createWindow(a); w->show(); } a->setChecked(w ? true : false);}AbstractLogWindow* MainForm::createWindow(QAction *a){ if(a->objectName() == "CalcWindow") return calcWindow = new CalcWindow(a, m_Settings, false, this); // здесь добавляем другие нужные нам конструкторы окон return 0;}AbstractLogWindow *MainForm::findWindow(QString winName){ QObject *b; foreach(b, this->children()) if(b->objectName() == winName) { AbstractLogWindow *l = qobject_cast<AbstractLogWindow *>(b); if(l != 0) return l; } return 0;}