#include "QtDocument.h" #include "QtNetwork.h" #include #include #include #include "QtRunContext.h" #include "UIDocumentController.h" #include "UINetworkController.h" namespace FD { using namespace std; QtDocument::QtDocument(QWidget *parent, const std::string &name) : QDialog(parent), m_doc(NULL), m_name(name) { cerr<<"QtDocument created"<setSpacing(6); m_vboxLayout->setMargin(0); m_vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); //Create button group m_buttonGroup = new QButtonGroup(this); //m_vboxLayout->insertLayout(0,m_buttonGroup); //Create run button QPushButton *runButton = new QPushButton("RUN", this); m_buttonGroup->addButton(runButton); //connect signal connect(runButton,SIGNAL(clicked()),this, SLOT(onRunDocument())); //create tab widget m_tabWidget = new QTabWidget(NULL); m_tabWidget->setObjectName(QString::fromUtf8("tabWidget")); connect(m_tabWidget, SIGNAL(currentChanged(int)),this, SLOT(tabWidgetChanged(int))); m_vboxLayout->addWidget(runButton); m_vboxLayout->addWidget(m_tabWidget); setLayout(m_vboxLayout); resize(800,600); open(name); } QtDocument::QtDocument(QWidget *parent, UINetwork::Type type, UIDocumentController* doc) : QDialog(parent), m_doc(doc) { cerr<<"QtDocument::QtDocument(QWidget *parent, UIDocumentController* doc)"<<__FILE__<<__LINE__<setSpacing(6); m_vboxLayout->setMargin(0); m_vboxLayout->setObjectName(QString::fromUtf8("vboxLayout")); //Create button group m_buttonGroup = new QButtonGroup(this); //m_vboxLayout->insertLayout(0,m_buttonGroup); //Create run button QPushButton *runButton = new QPushButton("RUN", this); m_buttonGroup->addButton(runButton); //connect signal connect(runButton,SIGNAL(clicked()),this, SLOT(onRunDocument())); //create tab widget m_tabWidget = new QTabWidget(NULL); m_tabWidget->setObjectName(QString::fromUtf8("tabWidget")); connect(m_tabWidget, SIGNAL(currentChanged(int)),this, SLOT(tabWidgetChanged(int))); m_vboxLayout->addWidget(runButton); m_vboxLayout->addWidget(m_tabWidget); setLayout(m_vboxLayout); resize(800,600); if (m_doc == NULL) { //Create a new document with a MAIN network m_doc = new UIDocumentController("Untitled",this); m_doc->addNetwork("MAIN",type); } else { //OPEN ALREADY EXISTING DOCUMENT } } bool QtDocument::isNetworkExist(const QString &name) { for(unsigned int i=0; igetName() == name.toStdString()) return true; return false; } void QtDocument::open(const std::string &fname) { int pos = fname.rfind("/"); string doc_name; if (pos != string::npos) { doc_name = fname.substr(pos + 1,fname.size() - (pos +1)); } else { doc_name = fname; } m_doc = new UIDocumentController(doc_name,this); m_doc->setFullPath(fname); try { m_doc->load(); m_doc->updateView(); cerr<<"loading document : "<print(cerr); //doc->less_print (except.str()); } catch (...) { //doc->less_print ("Unknown exception caught while loading document"); } m_doc->resetModified(); /* if (m_doc) { //create Qt networks std::vector nets = m_doc->get_networks(); cerr<<"networks found :"<(nets[i]))); m_networks.back()->setObjectName(QString::fromUtf8(nets[i]->getName().c_str())); m_tabWidget->addTab(m_networks.back(), nets[i]->getName().c_str()); } } */ } void QtDocument::save(const std::string &file) { if (m_doc) { m_doc->setFullPath(file); m_doc->save(); } } void QtDocument::onRunDocument() { cerr<<"Run clicked..."<setQtNetwork(qtnet); m_networks.push_back(qtnet); qtnet->setObjectName(QString::fromUtf8(net->getName().c_str())); m_tabWidget->addTab(qtnet, net->getName().c_str()); return qtnet; } void QtDocument::addNetwork(const QString &name, UINetwork::Type type) { m_doc->addNetwork(name.toStdString(),type); } void QtDocument::tabWidgetChanged(int index) { m_doc->updateView(); } }//namespace FD