/** * Closes all windows that are editing the given block. */ void QC_DialogFactory::closeEditBlockWindow(RS_Block* block) { RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow"); QC_ApplicationWindow* appWindow = QC_ApplicationWindow::getAppWindow(); QMdiArea* mdiAreaCAD = appWindow->getMdiArea(); if (mdiAreaCAD!=NULL) { RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow: workspace found"); QList<QMdiSubWindow*> windows = mdiAreaCAD->subWindowList(); for (int i = 0; i <windows.size(); ++i) { RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow: window: %d", i); QC_MDIWindow* m = qobject_cast<QC_MDIWindow*>(windows.at(i)->widget()); if (m!=NULL) { RS_DEBUG->print( "QC_DialogFactory::closeEditBlockWindow: got mdi"); if (m->getDocument()==block) { RS_DEBUG->print( "QC_DialogFactory::closeEditBlockWindow: closing mdi"); //m->closeMDI(true, false); m->setAttribute(Qt::WA_DeleteOnClose);//RLZ: to ensure the window is deleted m->close(); } } } } QMdiSubWindow* subWindow=NULL; appWindow->slotWindowActivated(subWindow); RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow: OK"); }
void Monitor::create(QWidget* parent) { QWidget* window; /* Must not create more than one instance */ if (s_instance != NULL) return; #ifdef __APPLE__ /* Create a separate window for OSX */ s_instance = new Monitor(parent, Qt::Window); window = s_instance; #else /* Create an MDI window for X11 & Win32 */ QMdiArea* area = qobject_cast<QMdiArea*> (_app->centralWidget()); Q_ASSERT(area != NULL); s_instance = new Monitor(parent); window = area->addSubWindow(s_instance); #endif /* Set some common properties for the window and show it */ window->setAttribute(Qt::WA_DeleteOnClose); window->setWindowIcon(QIcon(":/monitor.png")); window->setWindowTitle(tr("Fixture Monitor")); window->setContextMenuPolicy(Qt::CustomContextMenu); QSettings settings; QVariant var = settings.value(SETTINGS_GEOMETRY); if (var.isValid() == true) window->restoreGeometry(var.toByteArray()); window->show(); }
static PyObject * openBrowserHTML(PyObject *self, PyObject *args) { const char* HtmlCode; const char* BaseUrl; const char* TabName = "Browser"; if (! PyArg_ParseTuple(args, "ss|s",&HtmlCode,&BaseUrl,&TabName)) return NULL; PY_TRY { QMdiSubWindow* browserView = 0; QMdiArea* mdiArea = Gui::getMainWindow()->findChild<QMdiArea*>(); QList<QMdiSubWindow *> mdiViews = mdiArea->subWindowList(); for (QList<QMdiSubWindow *>::iterator it = mdiViews.begin(); it != mdiViews.end(); ++it) { if (qobject_cast<WebGui::BrowserView*>((*it)->widget())) { browserView = *it; break; } } if (!browserView) { WebGui::BrowserView* pcBrowserView = 0; pcBrowserView = new WebGui::BrowserView(Gui::getMainWindow()); pcBrowserView->resize(400, 300); pcBrowserView->setHtml(QString::fromUtf8(HtmlCode),QUrl(QString::fromLatin1(BaseUrl)),QString::fromUtf8(TabName)); Gui::getMainWindow()->addWindow(pcBrowserView); } else { mdiArea->setActiveSubWindow(browserView); } } PY_CATCH; Py_Return; }
void FixtureManager::create(QWidget* parent) { QWidget* window; /* Must not create more than one instance */ if (s_instance != NULL) return; #ifdef __APPLE__ /* Create a separate window for OSX */ s_instance = new FixtureManager(parent, Qt::Window); window = s_instance; #else /* Create an MDI window for X11 & Win32 */ QMdiArea* area = qobject_cast<QMdiArea*> (_app->centralWidget()); Q_ASSERT(area != NULL); s_instance = new FixtureManager(parent); window = area->addSubWindow(s_instance); #endif /* Set some common properties for the window and show it */ window->setAttribute(Qt::WA_DeleteOnClose); window->setWindowIcon(QIcon(":/fixture.png")); window->setWindowTitle(tr("Fixture Manager")); window->setContextMenuPolicy(Qt::CustomContextMenu); window->show(); QSettings settings; QVariant w = settings.value("fixturemanager/width"); QVariant h = settings.value("fixturemanager/height"); if (w.isValid() == true && h.isValid() == true) window->resize(w.toInt(), h.toInt()); else window->resize(600, 400); }
void RMdiChildQt::closeEvent(QCloseEvent* closeEvent) { // ask before closing (document was modified): if (documentInterface != NULL) { emit closeRequested(this); } else { closeEvent->accept(); return; } // close canceled: if (!closeEventAccepted) { closeEvent->ignore(); return; } if (documentInterface != NULL) { if (diLast==documentInterface) { diLast = NULL; } // 20130510: leads to empty layer list, etc when // closing background tab //RMainWindowQt::getMainWindow()->notifyListeners(true); // make sure rulers don't try to access view anymore: QList<RRulerQt*> rulers = findChildren<RRulerQt*>(); for (int i=0; i<rulers.size(); i++) { rulers.at(i)->setGraphicsView(NULL); } // give current action a chance to clean up: RAction* action = documentInterface->getCurrentAction(); if (action!=NULL) { action->suspendEvent(); } RDocumentInterface* di = documentInterface; documentInterface=NULL; delete di; di = NULL; } closeEvent->accept(); #ifndef Q_OS_WIN32 // part of the workaround for QMdiArea bug // with events filtering through all stacked windows: QMdiArea* mdiArea = RMainWindowQt::getMainWindow()->getMdiArea(); QMdiSubWindow* child = mdiArea->currentSubWindow(); QList<QMdiSubWindow *> children = mdiArea->subWindowList(QMdiArea::ActivationHistoryOrder); int index = children.indexOf(child); int nextIndex = children.length()-2; nextIndex = nextIndex%children.length(); if (nextIndex!=index) { children.at(nextIndex)->showMaximized(); mdiArea->setActiveSubWindow(children.at(nextIndex)); } #endif }
void CmdTestMDI2::activated(int iMsg) { QMdiArea* area = getMainWindow()->findChild<QMdiArea*>(); if (area) { MDIView* mdi = getMainWindow()->activeWindow(); area->removeSubWindow(mdi->parentWidget()); mdi->parentWidget()->showNormal(); } }
void mainWindowExample() { QMdiArea *mdiArea = new QMdiArea; //! [0] QMainWindow *mainWindow = new QMainWindow; mainWindow->setCentralWidget(mdiArea); //! [0] mdiArea->addSubWindow(new QPushButton("Push Me Now!")); mainWindow->show(); }
void FilteringService::applyFiltering() { StandardImageWindow* siw = dynamic_cast<StandardImageWindow*>(_ws->getCurrentImageWindow()); if (siw != NULL) { _siw = siw; _filterChoice = new FilterChoice(); QMdiArea* area = (QMdiArea*)_gi->centralWidget(); area->addSubWindow(_filterChoice); _filterChoice->show(); QObject::connect(_filterChoice, SIGNAL(choiceValidate(imagein::algorithm::Filtering*)), this, SLOT(apply(imagein::algorithm::Filtering*))); QObject::connect(_filterChoice, SIGNAL(cancelAction()), this, SLOT(cancelAction())); }
void InputManager::createAndShow(QWidget* parent, InputMap* inputMap) { QWidget* window = NULL; /* Must not create more than one instance */ if (s_instance == NULL) { #ifdef __APPLE__ /* Create a separate window for OSX */ s_instance = new InputManager(parent, inputMap, Qt::Window); window = s_instance; #else /* Create an MDI window for X11 & Win32 */ QMdiArea* area = qobject_cast<QMdiArea*> (parent); Q_ASSERT(area != NULL); QMdiSubWindow* sub = new QMdiSubWindow; s_instance = new InputManager(sub, inputMap); sub->setWidget(s_instance); window = area->addSubWindow(sub); #endif /* Set some common properties for the window and show it */ window->setAttribute(Qt::WA_DeleteOnClose); window->setWindowIcon(QIcon(":/input.png")); window->setWindowTitle(tr("Input Manager")); window->setContextMenuPolicy(Qt::CustomContextMenu); window->show(); QSettings settings; QVariant var = settings.value(SETTINGS_GEOMETRY); if (var.isValid() == true) { window->restoreGeometry(var.toByteArray()); AppUtil::ensureWidgetIsVisible(window); } } else { #ifdef __APPLE__ window = s_instance; #else window = s_instance->parentWidget(); #endif } window->show(); window->raise(); }
void DetectorMainWindow::showImages(QStringList selected) { ui->lineEdit->setText(selected.join(';')); QMdiArea * mdiarea = new QMdiArea() ; //ui->imagesViewWidget=new QWidget(this); ui->imagesViewWidget->setLayout(new QVBoxLayout(ui->imagesViewWidget)); ui->imagesViewWidget->layout()->removeItem(ui->imagesViewWidget->layout()->itemAt(0)); ui->imagesViewWidget->layout()->addWidget(mdiarea); DetectMultiScaleBatchDialog *d = new DetectMultiScaleBatchDialog (this,selected,&detector); QMdiSubWindow *w=mdiarea->addSubWindow(d); mdiarea->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); w->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); mdiarea->setViewMode(QMdiArea::TabbedView); w->show(); ui->imagesViewWidget->show(); }
void InputManager::create(QWidget* parent) { QWidget* window; /* Must not create more than one instance */ if (s_instance != NULL) return; #ifdef __APPLE__ /* Create a separate window for OSX */ s_instance = new InputManager(parent, Qt::Window); window = s_instance; #else /* Create an MDI window for X11 & Win32 */ QMdiArea* area = qobject_cast<QMdiArea*> (_app->centralWidget()); Q_ASSERT(area != NULL); s_instance = new InputManager(parent); window = area->addSubWindow(s_instance); #endif /* Set some common properties for the window and show it */ window->setAttribute(Qt::WA_DeleteOnClose); window->setWindowIcon(QIcon(":/input.png")); window->setWindowTitle(tr("Input Manager")); window->setContextMenuPolicy(Qt::CustomContextMenu); window->show(); QSettings settings; QVariant var = settings.value(SETTINGS_GEOMETRY); if (var.isValid() == true) { window->restoreGeometry(var.toByteArray()); AppUtil::ensureWidgetIsVisible(window); } else { QVariant w = settings.value("inputmanager/width"); QVariant h = settings.value("inputmanager/height"); if (w.isValid() == true && h.isValid() == true) window->resize(w.toInt(), h.toInt()); else window->resize(700, 300); } }
int mainAdapterWidget(QApplication& a, osg::ArgumentParser& arguments) { // load the scene. osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) { std::cerr << arguments[0] << ": No data loaded." << std::endl; std::cout << "usage: " << arguments[0] << " [--mdi] nodefile" << std::endl; return 1; } std::cout << "Using AdapterWidget - QGLWidget subclassed to integrate with " "osgViewer using its embedded graphics window support." << std::endl; if (arguments.read("--mdi")) { std::cout << "Using ViewetQT MDI version" << std::endl; /* Following problems are found here: - miminize causes loaded model to disappear (some problem with Camera matrix? - clampProjectionMatrix is invalid) */ ViewerQT* viewerWindow = new ViewerQT; viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator); viewerWindow->setSceneData(loadedModel.get()); QMainWindow* mw = new QMainWindow(); QMdiArea* mdiArea = new QMdiArea(mw); mw->setCentralWidget(mdiArea); QMdiSubWindow* subWindow = mdiArea->addSubWindow(viewerWindow); subWindow->showMaximized(); subWindow->setWindowTitle("New Window"); mw->show(); } else { ViewerQT* viewerWindow = new ViewerQT; viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator); viewerWindow->setSceneData(loadedModel.get()); viewerWindow->show(); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec(); }
void DnsLookupPlugin::slotMainActionForMenuTriggered() { QWidget *parentWidget = qobject_cast<QWidget *> (parent()); DnsLookupWidget *wgt = new DnsLookupWidget(parentWidget); //connect(wgt, SIGNAL(destroyed(QObject *)), this, SLOT(slotWidgetDestoryed(QObject *))); QMdiArea *mdiArea = 0; if(parentWidget) { mdiArea = qobject_cast<QMdiArea *>(parentWidget); } if(mdiArea) { QMdiSubWindow *subWindow = new QMdiSubWindow; subWindow->setWidget(wgt); subWindow->setAttribute(Qt::WA_DeleteOnClose); mdiArea->addSubWindow(subWindow); //connect(this, SIGNAL(signalPluginToBeUnloaded()), subWindow, SLOT(close())); connect(subWindow, SIGNAL(destroyed(QObject *)), this, SLOT(slotWidgetDestoryed(QObject *))); widgetList.append(subWindow); } else {
void addingSubWindowsExample() { QWidget *internalWidget1 = new QWidget; QWidget *internalWidget2 = new QWidget; //! [1] QMdiArea mdiArea; QMdiSubWindow *subWindow1 = new QMdiSubWindow; subWindow1->setWidget(internalWidget1); subWindow1->setAttribute(Qt::WA_DeleteOnClose); mdiArea.addSubWindow(subWindow1); QMdiSubWindow *subWindow2 = mdiArea.addSubWindow(internalWidget2); //! [1] subWindow1->show(); subWindow2->show(); mdiArea.show(); }
void UserManagerPlugin::slotMainActionForMenuTriggered() { if(isSingle() && UserManagerMainWindow::isRunning()) { //TODO: Activate the widget qDebug() << "----UserManagerPlugin::slotRun():UserManager Is Running!"; return; } QWidget *parentWidget = qobject_cast<QWidget *> (parent()); HEHUI::User user; HEHUI::LoginBase login(&user, name(), parentWidget); if (!login.isVerified()) { return ; } bool isYDAdmin = false; if(user.getBusinessAddress() == "DG") { isYDAdmin = false; } else if(user.getBusinessAddress() == "YD") { isYDAdmin = true; } UserManagerMainWindow *wgt = new UserManagerMainWindow(isYDAdmin, parentWidget); //connect(userManager, SIGNAL(destroyed(QObject *)), this, SLOT(slotUserManagerWidgetDestoryed(QObject *))); QMdiArea *mdiArea = 0; if(parentWidget) { mdiArea = qobject_cast<QMdiArea *>(parentWidget); } if(mdiArea) { QMdiSubWindow *subWindow = new QMdiSubWindow; subWindow->setWidget(wgt); subWindow->setAttribute(Qt::WA_DeleteOnClose); mdiArea->addSubWindow(subWindow); //connect(this, SIGNAL(signalPluginToBeUnloaded()), subWindow, SLOT(close())); connect(subWindow, SIGNAL(destroyed(QObject *)), this, SLOT(slotWidgetDestoryed(QObject *))); widgetList.append(subWindow); } else {
void OutputManager::create(QWidget* parent) { QWidget* window; /* Must not create more than one instance */ if (s_instance != NULL) return; #ifdef __APPLE__ /* Create a separate window for OSX */ s_instance = new OutputManager(parent, Qt::Window); window = s_instance; #else /* Create an MDI window for X11 & Win32 */ QMdiArea* area = qobject_cast<QMdiArea*> (_app->centralWidget()); Q_ASSERT(area != NULL); s_instance = new OutputManager(parent); window = area->addSubWindow(s_instance); #endif /* Set some common properties for the window and show it */ window->setAttribute(Qt::WA_DeleteOnClose); window->setWindowIcon(QIcon(":/output.png")); window->setWindowTitle(tr("Output Manager")); window->setContextMenuPolicy(Qt::CustomContextMenu); window->show(); connect(_app, SIGNAL(modeChanged(App::Mode)), s_instance, SLOT(slotAppModeChanged(App::Mode))); connect(_app, SIGNAL(documentChanged(Doc*)), s_instance, SLOT(slotDocumentChanged())); QSettings settings; QVariant w = settings.value("outputmanager/width"); QVariant h = settings.value("outputmanager/height"); if (w.isValid() == true && h.isValid() == true) window->resize(w.toInt(), h.toInt()); else window->resize(700, 300); }
App::App(QWidget* parent) : QMainWindow(parent) { _app = this; m_fileMenu = NULL; m_helpMenu = NULL; m_toolBar = NULL; m_copyChannel = NULL; setWindowTitle(App::longName()); setWindowIcon(QIcon(":/qlcplus-fixtureeditor.png")); QMdiArea *mdiArea = new QMdiArea(this); mdiArea->setBackground(QBrush(QColor(0x60, 0x60, 0x60))); setCentralWidget(mdiArea); QCoreApplication::setOrganizationName("qlcplus"); QCoreApplication::setOrganizationDomain("sf.net"); QCoreApplication::setApplicationName(FXEDNAME); initActions(); //initMenuBar(); initToolBar(); QSettings settings; QVariant var = settings.value(SETTINGS_GEOMETRY); if (var.isValid() == true) restoreGeometry(var.toByteArray()); QVariant dir = settings.value(SETTINGS_WORKINGPATH); if (dir.isValid() == false || QDir(dir.toString()).exists() == false) m_workingDirectory = QLCFixtureDefCache::userDefinitionDirectory(); else m_workingDirectory = QDir(dir.toString()); this->raise(); }
/** * Closes all windows that are editing the given block. */ void QC_DialogFactory::closeEditBlockWindow(RS_Block* block) { RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow"); QC_ApplicationWindow* appWindow = QC_ApplicationWindow::getAppWindow(); QMdiArea* mdiAreaCAD = appWindow->getMdiArea(); if (mdiAreaCAD==NULL) return; //should not happen RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow: workspace found"); for (int i = 0; i <mdiAreaCAD->subWindowList().size(); ) { RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow: window: %d", i); QC_MDIWindow* m = qobject_cast<QC_MDIWindow*>(mdiAreaCAD->subWindowList().at(i)); if(m==NULL) { mdiAreaCAD->removeSubWindow(mdiAreaCAD->subWindowList().at(i)); continue; } RS_DEBUG->print( "QC_DialogFactory::closeEditBlockWindow: got mdi"); if (m->getDocument()==block) { RS_DEBUG->print( "QC_DialogFactory::closeEditBlockWindow: closing mdi"); appWindow->slotFilePrintPreview(false); m->closeMDI(true, false); mdiAreaCAD->removeSubWindow(mdiAreaCAD->subWindowList().at(i)); continue; // m->setAttribute(Qt::WA_DeleteOnClose);//RLZ: to ensure the window is deleted // m->close(); } i++; } //activate a subWindow, bug#3486357 QMdiSubWindow* subWindow=mdiAreaCAD->currentSubWindow(); appWindow->slotWindowActivated(subWindow); RS_DEBUG->print("QC_DialogFactory::closeEditBlockWindow: OK"); }
void ch_cad_window::initialize() throw(ch_unknown_exc, std::bad_alloc) { QMdiArea* mdi = ch_application::mdi(); std::shared_ptr<QVTKWidget> cad_window(new QVTKWidget(mdi, Qt::SubWindow)); vtkSmartPointer<vtkRenderWindow> renderWindow = cad_window->GetRenderWindow(); vtkSmartPointer<vtkRenderWindowInteractor> interactor = /*_cad_window->GetInteractor();*/ vtkSmartPointer<vtkRenderWindowInteractor>::New(); vtkSmartPointer<vtkInteractorStyleDrawPolygon> style = vtkSmartPointer<vtkInteractorStyleDrawPolygon>::New(); //vtkSmartPointer<vtkContextInteractorStyle> style = vtkSmartPointer<vtkContextInteractorStyle>::New(); interactor->SetInteractorStyle(style); interactor->SetRenderWindow(renderWindow); // Create the RenderWindow, Renderer and both Actors // vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); // vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); renderer->SetBackground(0, 0, 0); renderWindow->SetFullScreen(true); vtkSmartPointer<vtkContourWidget> contourWidget = vtkSmartPointer<vtkContourWidget>::New(); // vtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRep = vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New(); vtkOrientedGlyphContourRepresentation *contourRep = vtkOrientedGlyphContourRepresentation:: SafeDownCast(contourWidget->GetRepresentation()); vtkSmartPointer<vtkLinearContourLineInterpolator> contourStyle = vtkSmartPointer<vtkLinearContourLineInterpolator>::New(); contourRep->GetLinesProperty()->SetColor(1, 0, 0); //set color to red contourRep->SetLineInterpolator(contourStyle); contourWidget->SetInteractor(interactor); contourWidget->SetRepresentation(contourRep); contourWidget->On(); //contourWidget->SetProcessEvents(true); //contourWidget->SetContinuousDraw(1); //contourWidget->AllowNodePickingOn(); //contourWidget->FollowCursorOn(); //for (int i = 0; i < argc; i++) //{ // if (strcmp("-Shift", argv[i]) == 0) // { contourWidget->GetEventTranslator()->RemoveTranslation( vtkCommand::LeftButtonPressEvent ); contourWidget->GetEventTranslator()->SetTranslation( vtkCommand::LeftButtonPressEvent, vtkWidgetEvent::Translate ); // } // else if (strcmp("-Scale", argv[i]) == 0) // { contourWidget->GetEventTranslator()->RemoveTranslation( vtkCommand::MouseWheelForwardEvent); contourWidget->GetEventTranslator()->SetTranslation( vtkCommand::MouseWheelForwardEvent, vtkWidgetEvent::Scale); // } //} vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New(); vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New(); vtkIdType* lineIndices = new vtkIdType[21]; for (int i = 0; i< 20; i++) { const double angle = 2.0*vtkMath::Pi()*i/20.0; points->InsertPoint(static_cast<vtkIdType>(i), 0.1*cos(angle), 0.1*sin(angle), 0.0 ); lineIndices[i] = static_cast<vtkIdType>(i); } lineIndices[20] = 0; lines->InsertNextCell(21,lineIndices); delete [] lineIndices; pd->SetPoints(points); pd->SetLines(lines); //vtkSmartPointer<vtkPolyDataPointPlacer> pdPlacer = vtkSmartPointer<vtkPolyDataPointPlacer>::New(); //vtkSmartPointer<vtkActor> pdActor = vtkSmartPointer<vtkActor>::New(); //pdPlacer->AddProp(pdActor); //contourRep->SetPointPlacer(pdPlacer); mdi->addSubWindow(cad_window.get()); cad_window->showMaximized(); contourWidget->Initialize(pd); contourWidget->Render(); renderer->ResetCamera(); renderWindow->Render(); interactor->Initialize(); interactor->Start(); contourWidget->Off(); }
/*! * \brief main * Ejercicio 2 Guia de Trabajos Practicos 1 * \param argc * \param argv * \return */ int main(int argc, char *argv[]) { QApplication a( argc, argv ); QMainWindow main; a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); main.showMaximized(); QMdiArea *mdiArea = new QMdiArea; mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); main.setCentralWidget(mdiArea); //Inicializo con una semilla aleatoria para la generacion de Aleatorios qsrand( QTime::currentTime().msec() ); // Cargo los parametros del ejercicio QSettings parametros( "parametros.cfg", QSettings::IniFormat ); // Archivo de entrada QString archivo = QCoreApplication::applicationDirPath().append( QDir::separator() ).append( parametros.value( "archivo_entrada" ).toString() ); // Cargo los datos de los archivos que corresponda matriz entradas( parametros.value( "cantidad_entradas" ).toInt() ); QVector<int> salidas; qDebug() << endl << "--------------- /Datos del entrenamiento/ -----------------" << endl; qWarning() << "Archivo de lectura de datos originales: "<< archivo; if( ! leer_archivo_entrenamiento( archivo, &entradas, &salidas, parametros.value( "cantidad_entradas" ).toInt() ) ) { qDebug() << "No se pudo encontrar el archivo de entrenamiento! cancelando!"; abort(); } // particionamos los datos Particionador particiones; particiones.setearCantidadDatos( entradas.size() ); particiones.setearCantidadDeParticiones( parametros.value( "cantidad_particiones" ).toInt() ); particiones.setearPorcentajeEntrenamiento( parametros.value( "porcentaje_entrenamiento" ).toDouble() ); particiones.setearPorcentajeValidacion( parametros.value("porcentaje_validacion").toDouble() ); particiones.setearK(parametros.value("k").toInt()); particiones.particionarDatos(); // Inicializo la red neuronal QVector<int> neuronas_por_capas; // Primer parametro es la cantidad de clases neuronas_por_capas << parametros.value( "cant_clases" ).toInt(); neuronas_por_capas << stringAQVector( parametros.value( "codificacion_salida" ).toString() ).size(); // Inicilizo la red radial RedNeuronalRadial red( neuronas_por_capas.at(0), neuronas_por_capas.at(1), parametros.value("cantidad_entradas").toInt(), parametros.value( "cant_clases" ).toInt() ); red.setearTasaAprendizaje( parametros.value( "tasa_aprendizaje" ).toDouble() ); qDebug() << "Tasa de aprendizaje: " << parametros.value( "tasa_aprendizaje" ).toDouble(); red.setearCodificacion( stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); qDebug() << "Codificacion salida: " << red.mostrarCodificacionSalida(); int max_epocas = parametros.value( "epocas_maximas", 20 ).toInt(); qDebug() << "Epocas: " << max_epocas; double tolerancia_error = parametros.value( "tolerancia_error" ).toDouble(); qDebug() << "Error de corte: " << ( tolerancia_error ) << "%"; qDebug() << endl << "---------------- /Comienza el entrenamiento/ ----------------"; int epoca = 0; /* Contador de epocas */ double porcentaje_error = 100.0; /* Mucho sino sale */ int cantidad_particiones_exitosas = 0; GraficadorMdi *graf1 = new GraficadorMdi( mdiArea ); graf1->setearTitulo( QString::fromUtf8( "Porcentaje de error según particion ( entrenamiento )" ) ); graf1->setearTituloEjeX( QString::fromUtf8( "Epoca" ) ); graf1->setearTituloEjeY( QString::fromUtf8( "Porcentaje error" ) ); mdiArea->addSubWindow( graf1 ); mdiArea->tileSubWindows(); if( stringAQVector( parametros.value( "codificacion_salida" ).toString() ).size() <= 2 ) { GraficadorMdi *graf2 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf2 ); graf2->showMaximized(); graf2->setearTitulo( "Datos originales" ); graf2->setearEjesEnGrafico(); graf2->setearTituloEjeX( " X " ); graf2->setearTituloEjeY( " y " ); graf2->agregarPuntosClasificados( entradas, salidas, 0.5 ); mdiArea->tileSubWindows(); } else { matriz entradas1, entradas2; vector salidas1, salidas2; for( int i=0; i < entradas.size(); i++ ) { vector temp; temp.append( entradas.at(i).at(0) ); temp.append( entradas.at(i).at(1) ); entradas1.append( temp ); vector temp2; temp2.append( entradas.at(i).at(2) ); temp2.append( entradas.at(i).at(3) ); entradas2.append( temp2 ); salidas1.append( salidas.at( i ) ); salidas2.append( salidas.at( i ) ); } GraficadorMdi *graf2 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf2 ); graf2->showMaximized(); graf2->setearTitulo( "Datos originales" ); //graf2->setearEjesEnGrafico(); graf2->setearTituloEjeX( "Longitud" ); graf2->setearTituloEjeY( "Ancho" ); graf2->agregarPuntosClasificados( entradas1, salidas1, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); GraficadorMdi *graf3 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf3 ); graf3->showMaximized(); graf3->setearTitulo( "Datos originales" ); graf3->setearTituloEjeX( "Petalos" ); graf3->setearTituloEjeY( "Sepalos" ); graf3->agregarPuntosClasificados( entradas2, salidas2, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); mdiArea->tileSubWindows(); } QDockWidget *dockBarra1 = new QDockWidget( "Progreso de Particiones" ); main.addDockWidget( Qt::BottomDockWidgetArea, dockBarra1 ); QProgressBar *PBParticiones = new QProgressBar( dockBarra1 ); dockBarra1->setWidget( PBParticiones ); QDockWidget *dockBarra2 = new QDockWidget( "Progreso de Epocas" ); main.addDockWidget( Qt::BottomDockWidgetArea, dockBarra2 ); QProgressBar *PBEpocas = new QProgressBar( dockBarra2 ); dockBarra2->setWidget( PBEpocas ); QVector<double> errores_particiones; PBParticiones->setRange( 0, particiones.cantidadDeParticiones() ); PBParticiones->setValue( 0 ); PBParticiones->setFormat( "Particion %v de %m - %p%" ); PBEpocas->setRange( 0, max_epocas ); PBEpocas->setFormat( "Epoca %v de %m - %p%" ); // Mido el tiempo QElapsedTimer medidor_tiempo; medidor_tiempo.start(); // Busco los centroides red.setearDatosOriginales( entradas, &salidas ); red.buscarCentroides(); // Grafico la agrupacion que hizo GraficadorMdi *graf = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf ); graf->setearTitulo( QString( "Agrupamientos según RB" ) ); graf->setearEjesEnGrafico(); graf->setearTituloEjeX( " X " ); graf->setearTituloEjeY( " Y " ); red.graficarClusters( graf ); mdiArea->tileSubWindows(); //return a.exec(); for( int p=0; p<particiones.cantidadDeParticiones(); p++ ) { Particionador::particion part_local = particiones.getParticion( p ); qDebug() << endl << "Utilizando Particion: " << p ; //pongo nuevamente en los valores iniciales las variables de corte para que entre en todas las particiones epoca = 0; porcentaje_error = 100.0; red.inicializarPesos(); QVector<double> errores_epocas; //std::cout << "Epoca: " << std::endl; PBEpocas->setValue( 0 ); while ( epoca < max_epocas && porcentaje_error > tolerancia_error ) { // Inicio la etapa de entrenamiento for(int i = 0; i < part_local.entrenamiento.size(); i++ ) { vector prueba = entradas.at( part_local.entrenamiento.at(i) ); int salida = salidas.at( part_local.entrenamiento.at( i ) ); red.entrenarCapaNeuronalComun( prueba, salida ); } // Verifico el error int errores = 0; int correcto = 0; for( int i = 0; i < part_local.validacion.size(); i++ ) { int pos = part_local.validacion.at( i ); vector entrada_a_evaluar = entradas.at( pos ); int salida_red = red.probarPatron( entrada_a_evaluar ) ; //double salida_mapeada = red.mapeadorSalidas( salida_red ); double salida_deseada = salidas.at( pos ); if( salida_red != salida_deseada ) { errores++; } else { correcto++; } } porcentaje_error = ( (double) errores * 100 ) / (double) part_local.validacion.size(); errores_epocas.push_back( porcentaje_error ); // Aumento el contador de epocas epoca++; PBEpocas->setValue( epoca ); QApplication::processEvents(); } graf1->agregarCurva( errores_epocas, QString( "Particion %1" ).arg( p ) ); qDebug() << " Epoca de finalizacion: " << epoca+1 << " - Error de salida de entrenamiento: " << porcentaje_error << "%"; // Genero las estadisticas con los datos de prueba porcentaje_error = 0.0; int errores = 0; int correcto = 0; for( int i = 0; i < part_local.prueba.size(); i++ ) { if( red.probarPatron( entradas.at( part_local.prueba.at( i ) ) ) != salidas.at( part_local.prueba.at( i ) ) ) { errores++; } else { correcto++; } } porcentaje_error = ( (double) errores * 100 ) / (double) part_local.prueba.size(); errores_particiones.push_back( porcentaje_error ); //Aumento el contador de las no exitosas if (epoca < max_epocas) { cantidad_particiones_exitosas++; } //qDebug() << errores_epocas; qDebug() <<"Terminada particion " << p << "- Error de prueba: " << errores_particiones.at( p ) << "%"; //Calculo el error promedio y la desviacion estandar para la particion // double error_promedio = 0.0; // double desviacion_estandar = 0.0; // double error_aux = 0.0; // for (int i = 0 ; i < errores_epocas.size() ; i++ ) { error_promedio += errores_epocas.at(i);} // error_promedio /= errores_epocas.size(); // qDebug() <<"Error Promedio: " << error_promedio << "%"; // for (int i = 0 ; i < errores_epocas.size() ; i++ ) { error_aux += exp(errores_epocas.at(i) - error_promedio);} // desviacion_estandar = sqrt( (1.0 / (errores_epocas.size() - 1.0) ) * error_aux ); // qDebug() <<"Desviacion Estandar: " << desviacion_estandar << "%"; errores_epocas.clear(); PBParticiones->setValue( PBParticiones->value() + 1 ); QVector<int> nueva_salida; matriz nueva_entrada; for( int i=0; i<part_local.prueba.size(); i++ ) { nueva_salida.append( red.probarPatron( entradas.at( part_local.prueba.at( i ) ) ) ); nueva_entrada.append( entradas.at( part_local.prueba.at( i ) ) ); } /*if( particiones.cantidadDeParticiones() <= 5 ) { GraficadorMdi *graf = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf ); graf->show(); graf->setearTitulo( QString( "Datos de prueba evaluados con red neuronal - Particion %1" ).arg( p+1 ) ); graf->setearEjesEnGrafico(); graf->setearTituloEjeX( " X " ); graf->setearTituloEjeY( " y " ); graf->agregarPuntosClasificados( nueva_entrada, nueva_salida, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); mdiArea->tileSubWindows(); }*/ QApplication::processEvents(); } qint64 milisegundos = medidor_tiempo.elapsed(); //std::cout << std::endl; // Calculo el promedio de todos los errores double sumatoria = 0.0; for( int i=0; i<errores_particiones.size(); i++ ) { sumatoria+=errores_particiones.at(i); } qDebug() << endl << "--------------- /Resumen/ -----------------"; qDebug() << endl << "Error total: " << sumatoria/errores_particiones.size() << "%"; qDebug() << endl << "Cantidad de Particiones que convergen: " << cantidad_particiones_exitosas ; qDebug() << endl << "Cantidad de Particiones sin converger: " << (particiones.cantidadDeParticiones() - cantidad_particiones_exitosas) ; //Calculo el error promedio y la desviacion estandar para todo double error_promedio = sumatoria/errores_particiones.size(); double desviacion_estandar = 0.0; double error_aux = 0.0; for (int i = 0 ; i < errores_particiones.size() ; i++ ) { error_aux += exp(errores_particiones.at(i) - error_promedio);} desviacion_estandar = sqrt( (1.0 / (errores_particiones.size() - 1.0) ) * error_aux ); qDebug() <<"Desviacion Estandar: " << desviacion_estandar << "%"; qDebug() << "Tiempo medido: " << milisegundos << " ms"; if( particiones.cantidadDeParticiones() != 1 ) { GraficadorMdi *graf3 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf3 ); graf3->showMaximized(); graf3->setearTitulo( "Errores por particion( datos de prueba )" ); graf3->setearTituloEjeX( "Particion" ); graf3->setearTituloEjeY( "Error" ); graf3->agregarCurva( errores_particiones, "Errores" ); mdiArea->tileSubWindows(); } QVector<int> nueva_salida; for( int i=0; i<entradas.size(); i++ ) { nueva_salida.append( red.probarPatron( entradas.at(i) ) ); } matriz entradas1, entradas2; vector salidas1, salidas2; for( int i=0; i < entradas.size(); i++ ) { vector temp; temp.append( entradas.at(i).at(0) ); temp.append( entradas.at(i).at(1) ); entradas1.append( temp ); if( entradas.at(i).size() > 2 ) { vector temp2; temp2.append( entradas.at(i).at(2) ); temp2.append( entradas.at(i).at(3) ); entradas2.append( temp2 ); } salidas1.append( nueva_salida.at( i ) ); salidas2.append( nueva_salida.at( i ) ); } if( stringAQVector( parametros.value( "codificacion_salida" ).toString() ).size() == 2 ) { GraficadorMdi *graf4 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf4 ); graf4->showMaximized(); graf4->setearTitulo( "Datos evaluados con red neuronal" ); graf4->setearEjesEnGrafico(); graf4->setearTituloEjeX( " X " ); graf4->setearTituloEjeY( " y " ); graf4->agregarPuntosClasificados( entradas, nueva_salida, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); //graf4->agregarPuntosClasificados( entradas, nueva_salida ); } else if( stringAQVector( parametros.value("codificacion_salida").toString() ).size() == 1 ) { GraficadorMdi *graf4 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf4 ); graf4->showMaximized(); graf4->setearTitulo( "Datos evaluados con red neuronal" ); graf4->setearEjesEnGrafico(); graf4->setearTituloEjeX( " X " ); graf4->setearTituloEjeY( " y " ); //graf4->agregarPuntosClasificados( entradas, nueva_salida, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); graf4->agregarPuntosClasificados( entradas, nueva_salida ); } else { GraficadorMdi *graf4 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf4 ); graf4->showMaximized(); graf4->setearTitulo( "Datos evaluados con red neuronal" ); graf4->setearTituloEjeX( "Largo" ); graf4->setearTituloEjeY( "Ancho" ); graf4->agregarPuntosClasificados( entradas1, salidas1, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); GraficadorMdi *graf5 = new GraficadorMdi( mdiArea ); mdiArea->addSubWindow( graf5 ); graf5->showMaximized(); graf5->setearTitulo( "Datos evaluados con red neuronal" ); graf5->setearTituloEjeX( "Petalos" ); graf5->setearTituloEjeY( "Sepalos" ); graf5->agregarPuntosClasificados( entradas2, salidas2, stringAQVector( parametros.value( "codificacion_salida" ).toString() ) ); } mdiArea->tileSubWindows(); return a.exec(); }
/*! * \brief main * Guia de Trabajos Practicos 3 * \param argc * \param argv * \return */ int main(int argc, char *argv[]) { QApplication a( argc, argv ); QMainWindow main; a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); main.showMaximized(); QMdiArea *mdiArea = new QMdiArea; mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); main.setCentralWidget(mdiArea); GraficadorMdi *grafFuncion = new GraficadorMdi( mdiArea ); grafFuncion->setearTitulo( QString::fromUtf8( "Funcion" ) ); grafFuncion->setearTituloEjeX( QString::fromUtf8( "X" ) ); grafFuncion->setearTituloEjeY( QString::fromUtf8( "Y" ) ); mdiArea->addSubWindow( grafFuncion ); grafFuncion->show(); mdiArea->tileSubWindows(); GraficadorMdi *grafFitnes = new GraficadorMdi( mdiArea ); grafFitnes->setearTitulo( QString::fromUtf8( "Evolucion Mejor Fitness" ) ); grafFitnes->setearTituloEjeX( QString::fromUtf8( "Generacion" ) ); grafFitnes->setearTituloEjeY( QString::fromUtf8( "fitness" ) ); mdiArea->addSubWindow( grafFitnes ); grafFitnes->show(); mdiArea->tileSubWindows(); grafFitnes->setearParaSOM(); GraficadorMdi *grafPuntos = new GraficadorMdi( mdiArea ); grafPuntos->setearTitulo( QString::fromUtf8( "Puntos a evaluar" ) ); grafPuntos->setearTituloEjeX( QString::fromUtf8( "Posicion" ) ); grafPuntos->setearTituloEjeY( QString::fromUtf8( "Y" ) ); mdiArea->addSubWindow( grafPuntos ); grafPuntos->show(); mdiArea->tileSubWindows(); //grafPuntos->setearParaSOM(); // grafPuntos->setearEjesEnGrafico(); GraficadorMdi *grafPromedio = new GraficadorMdi( mdiArea ); grafPromedio->setearTitulo( QString::fromUtf8( "Fitness Promedio" ) ); grafPromedio->setearTituloEjeX( QString::fromUtf8( "Posicion" ) ); grafPromedio->setearTituloEjeY( QString::fromUtf8( "Y" ) ); mdiArea->addSubWindow( grafPromedio ); grafPromedio->show(); mdiArea->tileSubWindows(); grafPromedio->setearParaSOM(); // barra de progreso para mostrar el avance del tiempo QDockWidget *dockBarra = new QDockWidget( QString::fromUtf8( "Evaluaciones" ) ); main.addDockWidget( Qt::BottomDockWidgetArea, dockBarra ); QProgressBar *PBTiempo = new QProgressBar( dockBarra ); dockBarra->setWidget( PBTiempo ); //Inicializo con una semilla aleatoria para la generacion de Aleatorios qsrand( QTime::currentTime().msec() ); // Cargo los parametros del ejercicio QSettings parametros( "parametros.cfg", QSettings::IniFormat ); // Inicializo la poblacion Poblacion<GenomaX> pob; int cant_total = parametros.value( "cantidad_elementos" ).toInt(); pob.setearTotal( cant_total ); pob.setearElitismo( parametros.value( "elitismo", false ).toBool() ); pob.setearBrechaGeneracional( parametros.value( "brecha_generacional" ).toDouble() ); pob.setearProbabilidadMutacion( parametros.value( "probabilidad_mutacion").toDouble() ); pob.setearModoSeleccionPadres( (Poblacion<GenomaX>::MetodoSeleccion)parametros.value( "metodo_seleccion" ).toInt() ); pob.setearPorcentajeCantidadDePadres( parametros.value( "cantidad_padres" ).toDouble() ); double max = parametros.value( "max" ).toDouble(); double min = parametros.value( "min" ).toDouble(); pob.setearMinMax( min, max ); for( int i=0; i<cant_total; i++ ) { GenomaX temp; double valor = valor_random( min, max ); temp.setX( valor ); temp.setMinMax( min, max ); pob.append( temp ); } // Grafico la funcion QVector<double> posy, posx; for( double i=min; i<max; i+=0.05 ) { posx.append( i ); posy.append( evaluar( i ) ); } grafFuncion->agregarCurva( posx, posy, "funcion" ); a.processEvents(); /*GenomaX p1; p1.setX( 128.0 ); p1.mostrarGenotipo(); p1.mutar( 9 ); p1.mostrarGenotipo(); p1.mutar( 1 ); p1.mostrarGenotipo(); p1.mutar( 2 ); p1.mostrarGenotipo(); p1.mutar( 15 ); p1.mostrarGenotipo(); p1.mutar( 10 ); p1.mostrarGenotipo(); p1.mutar( 11 ); p1.mostrarGenotipo();*/ double fitnes_necesario = parametros.value( "fitnes_necesario", 0.0 ).toDouble(); int iteracciones_maximas = parametros.value( "iteracciones_maximas", 1000 ).toInt(); int iteracciones = 0; PBTiempo->setRange( 0, iteracciones_maximas ); pob.evaluarPoblacion(); a.processEvents(); QVector<double> histFitness; QVector<int> histIteracion; QVector<double> histPromFitnes; histFitness.append( pob.mejorFitnes() ); histIteracion.append( 0 ); histPromFitnes.append( pob.mejorFitnes() ); double mejor_fitness = 0.0; double pos_mejor_fitness = 0.0; int generacion_mejor_fitness = -1; while( pob.mejorFitnes() <= fitnes_necesario && iteracciones <= iteracciones_maximas ) { pob.seleccionarPadres(); a.processEvents(); pob.generarHijos(); a.processEvents(); pob.evaluarPoblacion(); a.processEvents(); iteracciones++; PBTiempo->setValue( iteracciones ); histFitness.append( pob.mejorFitnes() ); histIteracion.append( iteracciones ); grafFitnes->setearPuntos( histFitness, histIteracion ); a.processEvents(); QVector<double> x, y; double sumatoria = 0.0; for( int i=0; i<pob.size(); i++ ) { y.append( i ); x.append( pob.at( i ).getX() ); sumatoria += (-1.0)*evaluar( pob.at( i ).getX() ); } sumatoria /= pob.size(); histPromFitnes.append( sumatoria ); grafPuntos->agregarCurva( x, y, QString( "Gen%1" ).arg( iteracciones ) ); if( mejor_fitness <= pob.mejorFitnes() ) { mejor_fitness = pob.mejorFitnes(); pos_mejor_fitness = pob.elementoMinimo().getX(); generacion_mejor_fitness = iteracciones; } grafPromedio->setearPuntos( histPromFitnes, histIteracion ); } qDebug() << "Mejor Fitness: " << mejor_fitness; qDebug() << "Posicion Minimo: " << pos_mejor_fitness; qDebug() << "Minimo: " << evaluar( pos_mejor_fitness ); qDebug() << "Generacion: " << generacion_mejor_fitness; return a.exec(); }
// id is an old ident in case of an import ColDiagramWindow::ColDiagramWindow(const QString & s, BrowserColDiagram * b, int id) : DiagramWindow(b, s), view(0) { QToolBar * toolbar = new QToolBar("communication diagram operations", this); toolbar->setMinimumHeight(50); toolbar->setOrientation(Qt::Horizontal); addToolBar(Qt::TopToolBarArea, toolbar); add_edit_button(toolbar); select = ToolBarFactory::createToolButton(*selectButton, TR("Select"), QString(), this, SLOT(hit_select()), toolbar, "select"); select->setCheckable(TRUE); select->setChecked(TRUE); current_button = UmlSelect; addPackage = ToolBarFactory::createToolButton(*packageButton, TR("Add Package"), QString(), this, SLOT(hit_package()), toolbar, "add package"); addPackage->setCheckable(TRUE); addPackage->setWhatsThis(addpackageText()); addFragment = ToolBarFactory::createToolButton(*fragmentButton, TR("Add Fragment"), QString(), this, SLOT(hit_fragment()), toolbar, "add fragment"); addFragment->setCheckable(TRUE); addFragment->setWhatsThis(addfragmentText()); addClassInstance = ToolBarFactory::createToolButton(*classinstanceButton, TR("Add modeled Class instance"), QString(), this, SLOT(hit_classinstance()), toolbar, "add modeled class instance"); addClassInstance->setCheckable(TRUE); addClassInstance->setWhatsThis(addmodeledclassinstanceText()); addClass = ToolBarFactory::createToolButton(*classButton, TR("Add Class instance"), QString(), this, SLOT(hit_class()), toolbar, "add class instance"); addClass->setCheckable(TRUE); addClass->setWhatsThis(addclassinstanceText()); addLink = ToolBarFactory::createToolButton(*associationButton, TR("Add Link"), QString(), this, SLOT(hit_link()), toolbar, "add link"); addLink->setCheckable(TRUE); addLink->setWhatsThis(linkText()); addSelfLink = ToolBarFactory::createToolButton(*selflinkButton, TR("Add Self Link"), QString(), this, SLOT(hit_selflink()), toolbar, "add self link"); addSelfLink->setCheckable(TRUE); addSelfLink->setWhatsThis(selflinkText()); note = ToolBarFactory::createToolButton(*noteButton, TR("Note"), QString(), this, SLOT(hit_note()), toolbar, "note"); note->setCheckable(TRUE); note->setWhatsThis(noteText()); anchor = ToolBarFactory::createToolButton(*anchorButton, TR("Anchor"), QString(), this, SLOT(hit_anchor()), toolbar, "anchor"); anchor->setCheckable(TRUE); anchor->setWhatsThis(anchorText()); text = ToolBarFactory::createToolButton(*textButton, TR("Text"), QString(), this, SLOT(hit_text()), toolbar, "text"); text->setCheckable(TRUE); text->setWhatsThis(textText()); image = ToolBarFactory::createToolButton(*imageButton, TR("Image"), QString(), this, SLOT(hit_image()), toolbar, "image"); image->setCheckable(TRUE); image->setWhatsThis(imageText()); toolbar->addSeparator(); add_scale_cmd(toolbar); // view = new ColDiagramView(this, canvas, (id != -1) ? id : b->get_ident()); setFocusProxy(view); setCentralWidget(view); //qApp->setMainWidget(this); QMdiArea * w = UmlWindow::get_workspace(); m_containingSubWindow->resize((w->width() * 4) / 5, (w->height() * 4) / 5); /*if (w->windowList().isEmpty()) showMaximized(); else*/ show(); view->preferred_size_zoom(); //qApp->setMainWidget(0); }
int mainAdapterWidget(QApplication& a, osg::ArgumentParser& arguments) { // load the scene. osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) { std::cout << arguments[0] <<": No data loaded." << std::endl; return 1; } std::cout<<"Using AdapterWidget - QGLWidget subclassed to integrate with osgViewer using its embedded graphics window support."<<std::endl; if (arguments.read("--CompositeViewer")) { CompositeViewerQT* viewerWindow = new CompositeViewerQT; unsigned int width = viewerWindow->width(); unsigned int height = viewerWindow->height(); { osgViewer::View* view1 = new osgViewer::View; view1->getCamera()->setGraphicsContext(viewerWindow->getGraphicsWindow()); view1->getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width)/static_cast<double>(height/2), 1.0, 1000.0); view1->getCamera()->setViewport(new osg::Viewport(0,0,width,height/2)); view1->setCameraManipulator(new osgGA::TrackballManipulator); view1->setSceneData(loadedModel.get()); viewerWindow->addView(view1); } { osgViewer::View* view2 = new osgViewer::View; view2->getCamera()->setGraphicsContext(viewerWindow->getGraphicsWindow()); view2->getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width)/static_cast<double>(height/2), 1.0, 1000.0); view2->getCamera()->setViewport(new osg::Viewport(0,height/2,width,height/2)); view2->setCameraManipulator(new osgGA::TrackballManipulator); view2->setSceneData(loadedModel.get()); viewerWindow->addView(view2); } viewerWindow->show(); } else if (arguments.read("--mdi")) { std::cout<<"Using ViewetQT MDI version"<<std::endl; /* Following problems are found here: - miminize causes loaded model to disappear (some problem with Camera matrix? - clampProjectionMatrix is invalid) */ ViewerQT* viewerWindow = new ViewerQT; viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator); viewerWindow->setSceneData(loadedModel.get()); QMainWindow* mw = new QMainWindow(); QMdiArea* mdiArea = new QMdiArea(mw); mw->setCentralWidget(mdiArea); QMdiSubWindow *subWindow = mdiArea->addSubWindow(viewerWindow); subWindow->showMaximized(); subWindow->setWindowTitle("New Window"); mw->show(); } else { ViewerQT* viewerWindow = new ViewerQT; viewerWindow->setCameraManipulator(new osgGA::TrackballManipulator); viewerWindow->setSceneData(loadedModel.get()); viewerWindow->show(); } a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); return a.exec(); }
// id is an old ident in case of an import DeploymentDiagramWindow::DeploymentDiagramWindow(const QString & s, BrowserDeploymentDiagram * b, int id) : DiagramWindow(b, s), view(0) { QToolBar * toolbar = new QToolBar("deployment operations", this); toolbar->setMinimumHeight(50); toolbar->setOrientation(Qt::Horizontal); addToolBar(Qt::TopToolBarArea, toolbar); add_edit_button(toolbar); select = ToolBarFactory::createToolButton(*selectButton, tr("Select"), QString(), this, SLOT(hit_select()), toolbar, "select"); select->setCheckable(TRUE); select->setChecked(TRUE); current_button = UmlSelect; addPackage = ToolBarFactory::createToolButton(*packageButton, tr("Add Package"), QString(), this, SLOT(hit_package()), toolbar, "add package"); addPackage->setCheckable(TRUE); addPackage->setWhatsThis(addpackageText()); addFragment = ToolBarFactory::createToolButton(*fragmentButton, tr("Add Fragment"), QString(), this, SLOT(hit_fragment()), toolbar, "add fragment"); addFragment->setCheckable(TRUE); addFragment->setWhatsThis(addfragmentText()); addDeploymentNode = ToolBarFactory::createToolButton(*deploymentNodeButton, tr("Add Deployment Node"), QString(), this, SLOT(hit_deploymentnode()), toolbar, "add deployment node"); addDeploymentNode->setCheckable(TRUE); addDeploymentNode->setWhatsThis(adddeploymentnodeText()); addArtifact = ToolBarFactory::createToolButton(*artifactButton, tr("Add Artifact"), QString(), this, SLOT(hit_artifact()), toolbar, "add artifact"); addArtifact->setCheckable(TRUE); addArtifact->setWhatsThis(addartifactText()); addComponent = ToolBarFactory::createToolButton(*componentButton, tr("Add Component"), QString(), this, SLOT(hit_component()), toolbar, "add component"); addComponent->setCheckable(TRUE); addComponent->setWhatsThis(addcomponentText()); hub = ToolBarFactory::createToolButton(*hubButton, tr("Network connexion/ending"), QString(), this, SLOT(hit_hub()), toolbar, "network connexion/ending"); hub->setCheckable(TRUE); hub->setWhatsThis(hubText()); network = ToolBarFactory::createToolButton(*associationButton, tr("Network"), QString(), this, SLOT(hit_network()), toolbar, "network"); network->setCheckable(TRUE); network->setWhatsThis(networkText()); inherit = ToolBarFactory::createToolButton(*generalisationButton, tr("Inheritance"), QString(), this, SLOT(hit_inherit()), toolbar, "inheritance"); inherit->setCheckable(TRUE); inherit->setWhatsThis(inheritText()); association = ToolBarFactory::createToolButton(*directionalAssociationButton, tr("Association"), QString(), this, SLOT(hit_association()), toolbar, "association"); association->setCheckable(TRUE); association->setWhatsThis(associationText()); dependency = ToolBarFactory::createToolButton(*dependencyButton, tr("Dependency"), QString(), this, SLOT(hit_dependency()), toolbar, "dependency"); dependency->setCheckable(TRUE); dependency->setWhatsThis(dependencyText()); note = ToolBarFactory::createToolButton(*noteButton, tr("Note"), QString(), this, SLOT(hit_note()), toolbar, "note"); note->setCheckable(TRUE); note->setWhatsThis(noteText()); anchor = ToolBarFactory::createToolButton(*anchorButton, tr("Anchor"), QString(), this, SLOT(hit_anchor()), toolbar, "anchor"); anchor->setCheckable(TRUE); anchor->setWhatsThis(anchorText()); text = ToolBarFactory::createToolButton(*textButton, tr("Text"), QString(), this, SLOT(hit_text()), toolbar, "text"); text->setCheckable(TRUE); text->setWhatsThis(textText()); image = ToolBarFactory::createToolButton(*imageButton, tr("Image"), QString(), this, SLOT(hit_image()), toolbar, "image"); image->setCheckable(TRUE); image->setWhatsThis(imageText()); toolbar->addSeparator(); add_scale_cmd(toolbar); // view = new DeploymentDiagramView(this, canvas, (id != -1) ? id : b->get_ident()); setFocusProxy(view); setCentralWidget(view); //qApp->setMainWidget(this); QMdiArea * w = UmlWindow::get_workspace(); m_containingSubWindow->resize((w->width() * 4) / 5, (w->height() * 4) / 5); /*if (w->windowList().isEmpty()) showMaximized(); else*/ show(); view->preferred_size_zoom(); //qApp->setMainWidget(0); }
void Dialog::createMainWindow() { QPushButton* btn = new QPushButton( "This is a MainWindow\nwith mdi area and subwindow\n(Close)" ); //On mainwindows with mdiarea or //any widget which takes the layout //margins as 0, the frameless helper //will not be able to detect corners. //To workaround this, either change the //mainwindow layout's margin or put the mainwindow //inside a QWidget with margins. QMainWindow* mw = new QMainWindow; QMdiArea* area = new QMdiArea; area->addSubWindow(btn); mw->setCentralWidget(area); //This dosent seem to work! //mw.layout()->setMargin(fh2.borderWidth()); //so we will use a QWidget mWidget = new QWidget; QVBoxLayout* vl = new QVBoxLayout; vl->addWidget(mw); mWidget->setLayout(vl); connect( btn, SIGNAL(clicked()), mWidget, SLOT(close()) ); //mWidget->setAttribute(Qt::WA_DeleteOnClose); //mWidget->show(); }