PdfViewer::~PdfViewer() { // m_presentationWidget->deleteLater(); delete m_presentationWidget; writeSettings(); closeDocument(); }
bool MainWindow::closeAndPromptForSave() { bool prev_lock = lock_open_blank_page_; lock_open_blank_page_ = true; while (diagrams_notebook_->get_n_pages() > 0) { int pages_count_before_close = diagrams_notebook_->get_n_pages(); DiagramEditor* diagram_editor = diagrams_notebook_->getDiagramEditor (0); closeDocument (diagram_editor); // If after close the page count is equal before the close // the user select to cancel if (pages_count_before_close == diagrams_notebook_->get_n_pages()) { // Do not close the window if the user select cancel lock_open_blank_page_ = prev_lock; return true; } } // Close the window return false; }
void structTextEditor :: v_goAway () { if (v_fileBased () && dirty) { if (! dirtyCloseDialog) { int buttonWidth = 120, buttonSpacing = 20; dirtyCloseDialog = GuiDialog_create (d_windowForm, 150, 70, Gui_LEFT_DIALOG_SPACING + 3 * buttonWidth + 2 * buttonSpacing + Gui_RIGHT_DIALOG_SPACING, Gui_TOP_DIALOG_SPACING + Gui_TEXTFIELD_HEIGHT + Gui_VERTICAL_DIALOG_SPACING_SAME + 2 * Gui_BOTTOM_DIALOG_SPACING + Gui_PUSHBUTTON_HEIGHT, U"Text changed", nullptr, nullptr, GuiDialog_MODAL); GuiLabel_createShown (dirtyCloseDialog, Gui_LEFT_DIALOG_SPACING, - Gui_RIGHT_DIALOG_SPACING, Gui_TOP_DIALOG_SPACING, Gui_TOP_DIALOG_SPACING + Gui_LABEL_HEIGHT, U"The text has changed! Save changes?", 0); int x = Gui_LEFT_DIALOG_SPACING, y = - Gui_BOTTOM_DIALOG_SPACING; GuiButton_createShown (dirtyCloseDialog, x, x + buttonWidth, y - Gui_PUSHBUTTON_HEIGHT, y, U"Discard & Close", gui_button_cb_discardAndClose, this, 0); x += buttonWidth + buttonSpacing; GuiButton_createShown (dirtyCloseDialog, x, x + buttonWidth, y - Gui_PUSHBUTTON_HEIGHT, y, U"Cancel", gui_button_cb_cancelClose, this, 0); x += buttonWidth + buttonSpacing; GuiButton_createShown (dirtyCloseDialog, x, x + buttonWidth, y - Gui_PUSHBUTTON_HEIGHT, y, U"Save & Close", gui_button_cb_saveAndClose, this, 0); } GuiThing_show (dirtyCloseDialog); } else { closeDocument (this); } }
bool DocumentWindow::loadDocument(const QString& path) { if (!closeDocument()) { return false; } const QFile::FileError loading = m_document.loadFromFile(path); if (loading != QFile::NoError) { showPopup(tr("Error"), tr("Failed to load file: %1").arg(path)); return false; } m_path = path; m_synchronized = true; setWindowTitle(separateName(path)); setDocumentModel(); emit documentLoaded(path); return true; }
void OSPlugin::newForSender() { LOG(Trace, "newForSender"); QObject* sender = this->sender(); OSDocument* osDocument = qobject_cast<OSDocument*>(sender); OS_ASSERT(osDocument); boost::optional<std::string> key = getKeyForDocument(osDocument); OS_ASSERT(key); if( !closeDocument(*key) ) { return; } openstudio::model::Model model = openstudio::model::exampleModel(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), "", true) ); connectDocumentSignals(document.get()); m_startupView->hide(); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(*key, document)); emit newModel(*key, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(*key); }
bool ProjectContentComponent::perform (const InvocationInfo& info) { switch (info.commandID) { case CommandIDs::saveProject: case CommandIDs::closeProject: case CommandIDs::saveDocument: case CommandIDs::saveDocumentAs: case CommandIDs::closeDocument: case CommandIDs::goToPreviousDoc: case CommandIDs::goToNextDoc: case CommandIDs::goToCounterpart: case CommandIDs::saveAndOpenInIDE: if (reinvokeCommandAfterCancellingModalComps (info)) { grabKeyboardFocus(); // to force any open labels to close their text editors return true; } break; default: break; } if (isCurrentlyBlockedByAnotherModalComponent()) return false; switch (info.commandID) { case CommandIDs::saveProject: saveProject(); break; case CommandIDs::closeProject: closeProject(); break; case CommandIDs::saveDocument: saveDocument(); break; case CommandIDs::saveDocumentAs: saveAs(); break; case CommandIDs::closeDocument: closeDocument(); break; case CommandIDs::goToPreviousDoc: goToPreviousFile(); break; case CommandIDs::goToNextDoc: goToNextFile(); break; case CommandIDs::goToCounterpart: goToCounterpart(); break; case CommandIDs::showFilePanel: showFilesTab(); break; case CommandIDs::showConfigPanel: showConfigTab(); break; case CommandIDs::showProjectSettings: showProjectSettings(); break; case CommandIDs::showProjectModules: showModules(); break; case CommandIDs::openInIDE: openInIDE (false); break; case CommandIDs::saveAndOpenInIDE: openInIDE (true); break; case CommandIDs::createNewExporter: showNewExporterMenu(); break; case CommandIDs::deleteSelectedItem: deleteSelectedTreeItems(); break; case CommandIDs::showTranslationTool: showTranslationTool(); break; default: return false; } return true; }
void HelpBrowser::createActions() { QAction * action; OverridingAction *ovrAction; mActions[GoHome] = action = new QAction(tr("Home"), this); connect( action, SIGNAL(triggered()), this, SLOT(goHome()) ); mActions[DocClose] = ovrAction = new OverridingAction(tr("Close"), this); connect( ovrAction, SIGNAL(triggered()), this, SLOT(closeDocument()) ); ovrAction->addToWidget(mWebView); mActions[ZoomIn] = ovrAction = new OverridingAction(tr("Zoom In"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomIn())); ovrAction->addToWidget(mWebView); mActions[ZoomOut] = ovrAction = new OverridingAction(tr("Zoom Out"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(zoomOut())); ovrAction->addToWidget(mWebView); mActions[ResetZoom] = ovrAction = new OverridingAction(tr("Reset Zoom"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(resetZoom())); ovrAction->addToWidget(mWebView); mActions[Evaluate] = ovrAction = new OverridingAction(tr("Evaluate as Code"), this); connect(ovrAction, SIGNAL(triggered()), this, SLOT(evaluateSelection())); ovrAction->addToWidget(mWebView); // For the sake of display: mWebView->pageAction(QWebPage::Copy)->setShortcut( QKeySequence::Copy ); mWebView->pageAction(QWebPage::Paste)->setShortcut( QKeySequence::Paste ); }
void PDF::openDocument(const QString& filename) { closeDocument(); pdfDoc_ = Poppler::Document::load(filename); if (!pdfDoc_ || pdfDoc_->isLocked()) { put_flog(LOG_DEBUG, "Could not open document %s", filename.toLocal8Bit().constData()); closeDocument(); return; } pdfDoc_->setRenderHint(Poppler::Document::TextAntialiasing); setPage(0); }
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: openDocument(); break; case 1: saveDocument(); break; case 2: closeDocument(); break; case 3: newDocument(); break; case 4: addShape(); break; case 5: removeShape(); break; case 6: setShapeColor(); break; case 7: addSnowman(); break; case 8: addRobot(); break; case 9: about(); break; case 10: aboutQt(); break; case 11: updateActions(); break; default: ; } _id -= 12; } return _id; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupUi(this); QWidget *w = documentTabs->widget(0); documentTabs->removeTab(0); delete w; connect(actionOpen, SIGNAL(triggered()), this, SLOT(openDocument())); connect(actionClose, SIGNAL(triggered()), this, SLOT(closeDocument())); connect(actionNew, SIGNAL(triggered()), this, SLOT(newDocument())); connect(actionSave, SIGNAL(triggered()), this, SLOT(saveDocument())); connect(actionExit, SIGNAL(triggered()), this, SLOT(close())); connect(actionRed, SIGNAL(triggered()), this, SLOT(setShapeColor())); connect(actionGreen, SIGNAL(triggered()), this, SLOT(setShapeColor())); connect(actionBlue, SIGNAL(triggered()), this, SLOT(setShapeColor())); connect(actionAddCircle, SIGNAL(triggered()), this, SLOT(addShape())); connect(actionAddRectangle, SIGNAL(triggered()), this, SLOT(addShape())); connect(actionAddTriangle, SIGNAL(triggered()), this, SLOT(addShape())); connect(actionRemoveShape, SIGNAL(triggered()), this, SLOT(removeShape())); connect(actionAddRobot, SIGNAL(triggered()), this, SLOT(addRobot())); connect(actionAddSnowman, SIGNAL(triggered()), this, SLOT(addSnowman())); connect(actionAbout, SIGNAL(triggered()), this, SLOT(about())); connect(actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt())); connect(undoLimit, SIGNAL(valueChanged(int)), this, SLOT(updateActions())); connect(documentTabs, SIGNAL(currentChanged(int)), this, SLOT(updateActions())); actionOpen->setShortcut(QString("Ctrl+O")); actionClose->setShortcut(QString("Ctrl+W")); actionNew->setShortcut(QString("Ctrl+N")); actionSave->setShortcut(QString("Ctrl+S")); actionExit->setShortcut(QString("Ctrl+Q")); actionRemoveShape->setShortcut(QString("Del")); actionRed->setShortcut(QString("Alt+R")); actionGreen->setShortcut(QString("Alt+G")); actionBlue->setShortcut(QString("Alt+B")); actionAddCircle->setShortcut(QString("Alt+C")); actionAddRectangle->setShortcut(QString("Alt+L")); actionAddTriangle->setShortcut(QString("Alt+T")); m_undoGroup = new QUndoGroup(this); undoView->setGroup(m_undoGroup); undoView->setCleanIcon(QIcon(":/icons/ok.png")); QAction *undoAction = m_undoGroup->createUndoAction(this); QAction *redoAction = m_undoGroup->createRedoAction(this); undoAction->setIcon(QIcon(":/icons/undo.png")); redoAction->setIcon(QIcon(":/icons/redo.png")); menuShape->insertAction(menuShape->actions().at(0), undoAction); menuShape->insertAction(undoAction, redoAction); toolBar->addAction(undoAction); toolBar->addAction(redoAction); newDocument(); updateActions(); };
bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst) { while (components.size() > 0) if (! closeDocument (components.getLast(), checkItsOkToCloseFirst)) return false; return true; }
void PdfViewer::slotReload() { double cur_pos = m_pdfView->pageNumberWithPosition(); //std::cout << "POSITION WAS " << cur_pos << std::endl ; QString filename = m_file; closeDocument(); loadDocument(filename); // using DocumentObserver::KeepPosition as second argument doesn't work, but since closeDocument() saves the current position, this is not a problem m_pdfView->amkhlvJumpToPosition(cur_pos); }
void DocumentManager::newDocument(int width, int height, float resolution) { closeDocument(); d->newDocWidth = width; d->newDocHeight = height; d->newDocResolution = resolution; QTimer::singleShot(300, this, SLOT(delayedNewDocument())); }
void MainWindow::onFileCloseAction() { DiagramEditor* active_diagram_editor = getActiveDiagramEditor(); if (!active_diagram_editor) return; closeDocument (active_diagram_editor); }
void DocumentWatcher::processUpdates() { while (!m_updates.isEmpty()) { QString path = m_updates.takeFirst(); QString filename = "<i>" + QFileInfo(path).fileName() + "</i>"; // Show document Document* document = m_paths.value(path); if (!document) { continue; } emit showDocument(document); if (QFile::exists(path)) { // Process changed file QMessageBox mbox(document->window()); mbox.setIcon(QMessageBox::Warning); mbox.setWindowTitle(tr("File Changed")); mbox.setText(tr("The file %1 was changed by another program.").arg(filename)); mbox.setInformativeText(tr("Do you want to reload the file?")); QPushButton* reload_button = mbox.addButton(tr("Reload"), QMessageBox::AcceptRole); if (reload_button->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) { reload_button->setIcon(reload_button->style()->standardIcon(QStyle::SP_BrowserReload)); } QPushButton* ignore_button = mbox.addButton(QMessageBox::Cancel); ignore_button->setText(tr("Ignore")); mbox.setDefaultButton(reload_button); mbox.exec(); if (mbox.clickedButton() == reload_button) { document->reload(false); } } else { // Process deleted file QMessageBox mbox(document->window()); mbox.setIcon(QMessageBox::Warning); mbox.setWindowTitle(tr("File Deleted")); mbox.setText(tr("The file %1 was deleted by another program.").arg(filename)); mbox.setInformativeText(tr("Do you want to save or close the file?")); mbox.setStandardButtons(QMessageBox::Save | QMessageBox::Close); mbox.setDefaultButton(QMessageBox::Save); if (mbox.exec() == QMessageBox::Save) { document->save(); } else { emit closeDocument(document); } } } }
void DocumentWindow::closeEvent(QCloseEvent* const eventPtr) { if (!closeDocument()) { eventPtr->ignore(); return; } eventPtr->accept(); QWidget::closeEvent(eventPtr); }
void MainWindow::onFileOpenAction() { Gtk::FileChooserDialog dialog(*this, _("Open diagram"), Gtk::FILE_CHOOSER_ACTION_OPEN); dialog.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_OK); #ifdef GTKMM_3 Glib::RefPtr< Gtk::FileFilter > filter_any = Gtk::FileFilter::create(); filter_any->set_name (_("All files")); filter_any->add_pattern ("*"); #else Gtk::FileFilter filter_any; filter_any.set_name (_("All files")); filter_any.add_pattern ("*"); #endif dialog.add_filter (filter_any); if (dialog.run() == Gtk::RESPONSE_OK) { try { DiagramEditor* active_diagram_editor = getActiveDiagramEditor(); if (active_diagram_editor) { if (!active_diagram_editor->isDirty() && active_diagram_editor->isEmpty()) { bool prev_lock_status = lock_open_blank_page_; lock_open_blank_page_ = true; closeDocument (active_diagram_editor); lock_open_blank_page_ = prev_lock_status; } } appendNotebookPage(dialog.get_filename()); } catch (const std::exception& e) { Gtk::MessageDialog msg(*this, _("Error opening diagram"), false, Gtk::MESSAGE_ERROR); msg.set_secondary_text(e.what()); msg.run(); } } }
void DocumentManager::addDocument(Document *doc) { int insertAt = mDocuments.size(); mDocuments.insert(insertAt, doc); // mUndoGroup->addStack(doc->undoStack()); mFailedToAdd = false; emit documentAdded(doc); if (mFailedToAdd) { closeDocument(insertAt); return; } setCurrentDocument(doc); }
static void gui_button_cb_saveAndClose (TextEditor me, GuiButtonEvent /* event */) { GuiThing_hide (my dirtyCloseDialog); if (my name [0]) { try { saveDocument (me, & my file); } catch (MelderError) { Melder_flushError (); return; } closeDocument (me); } else { menu_cb_saveAs (me, Editor_getMenuCommand (me, U"File", U"Save as..."), nullptr, 0, nullptr, nullptr, nullptr); } }
void OSPlugin::openForSender() { LOG(Trace, "openForLastKey"); QObject* sender = this->sender(); OSDocument* osDocument = qobject_cast<OSDocument*>(sender); OS_ASSERT(osDocument); boost::optional<std::string> key = getKeyForDocument(osDocument); OS_ASSERT(key); QString fileName = QFileDialog::getOpenFileName( m_sketchUpWidget, tr("Open"), QDir::homePath(), tr("(*.osm)") ); if( !(fileName == "") ){ boost::optional<IdfFile> idfFile; idfFile = openstudio::IdfFile::load(toPath(fileName),IddFileType::OpenStudio); if( idfFile ){ if( !closeDocument(*key) ) { return; } IdfFile _idfFile = idfFile.get(); model::Model model(_idfFile); m_startupView->hide(); processEvents(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), fileName, true) ); connectDocumentSignals(document.get()); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(*key, document)); emit newModel(*key, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(*key); } } }
bool DocumentWindow::buildNew() { if (!closeDocument()) { return false; } setWindowTitle(tr("new %1 *").arg(s_newUniqueId++)); m_document.buildNew(); setDocumentModel(); return true; }
void PdfViewer::slotDoAction(Poppler::LinkAction::ActionType actionType) { switch (actionType) { case Poppler::LinkAction::PageFirst: setPage(0); break; case Poppler::LinkAction::PagePrev: slotGoToPreviousPage(); break; case Poppler::LinkAction::PageNext: slotGoToNextPage(); break; case Poppler::LinkAction::PageLast: setPage(m_pdfView->document()->numPages()-1); break; case Poppler::LinkAction::HistoryBack: qCritical("TODO history back"); break; case Poppler::LinkAction::HistoryForward: qCritical("TODO history forward"); break; case Poppler::LinkAction::Quit: qApp->closeAllWindows(); break; case Poppler::LinkAction::Presentation: slotShowPresentation(); break; case Poppler::LinkAction::EndPresentation: break; // do nothing in normal mode case Poppler::LinkAction::Find: slotFind(); break; case Poppler::LinkAction::GoToPage: m_pdfView->slotGoToPage(); break; case Poppler::LinkAction::Close: closeDocument(); break; case Poppler::LinkAction::Print: qCritical("TODO print"); break; } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QPixmap openFilePix("icons/document-open.svg"); QPixmap closeFilePix("icons/process-stop.svg"); btn1 = new QAction(QIcon(openFilePix), "Open Connection", this); btn2 = new QAction(QIcon(closeFilePix), "Close Connection", this); QObject::connect(btn1, SIGNAL(triggered()), this, SLOT(newDocument()) ); QObject::connect(btn2, SIGNAL(triggered()), this, SLOT(closeDocument()) ); ui->mainToolBar->addAction(btn1); ui->mainToolBar->addAction(btn2); ui->mainToolBar->addSeparator(); QLineEdit *myLineEdit = new QLineEdit(); ui->mainToolBar->addWidget(myLineEdit); }
void OSPlugin::newForLastKey( openstudio::NewFromTemplateEnum newFromTemplateEnum ) { LOG(Trace, "newForLastKey"); if( !closeDocument(m_lastKey) ) { return; } openstudio::model::Model model = openstudio::model::exampleModel(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), "", true) ); connectDocumentSignals(document.get()); m_startupView->hide(); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(m_lastKey, document)); emit newModel(m_lastKey, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(m_lastKey); m_lastKey = ""; }
void DocumentManager::closeDocuments(const QList<IDocument *> &documents) { for (IDocument* d : documents) closeDocument(d); }
int main(int argc, char *argv[]) { struct doc_descriptor d; pid_t pid1, pid2; int e; UChar buf[10000]; FILE *fd; if(argc != 4) { printf("usage : ./threadtest doc1 doc2 doc3\n"); return -1; } pid1 = pid2 = 0; pid1 = fork(); if(pid1 == -1) { fprintf(stderr, "error fork 1\n"); exit(0); } else if(pid1) { pid2 = fork(); if(pid2 == -1) { fprintf(stderr, "error fork 2\n"); exit(0); } else if(pid2) { /* read doc 1 */ if(openDocument(argv[1], &d)) { printf("error open doc1\n"); exit(0); } fd = fopen("out1", "w"); e = read_content(&d, buf); while(e >= 0) { fwrite(buf, e, 1, fd); fwrite(" ", 2, 1, fd); e = read_content(&d, buf); } fclose(fd); if(closeDocument(&d)) { printf("error close doc1\n"); } } else { /* read doc 2 */ if(openDocument(argv[2], &d)) { printf("error open doc2\n"); exit(0); } fd = fopen("out2", "w"); e = read_content(&d, buf); while(e >= 0) { fwrite(buf, e, 1, fd); fwrite(" ", 2, 1, fd); e = read_content(&d, buf); } fclose(fd); if(closeDocument(&d)) { printf("error close doc2\n"); } } } else { /* read doc 3 */ if(openDocument(argv[3], &d)) { printf("error open doc3\n"); exit(0); } fd = fopen("out3", "w"); e = read_content(&d, buf); while(e >= 0) { fwrite(buf, e, 1, fd); fwrite(" ", 2, 1, fd); e = read_content(&d, buf); } fclose(fd); if(closeDocument(&d)) { printf("error close doc3\n"); } } return 0; }
PDF::~PDF() { closeDocument(); }
void DocumentWatcher::processUpdates() { while (!m_updates.isEmpty()) { QString path = m_updates.takeFirst(); QFileInfo info(path); QString filename = info.fileName(); // Find document Document* document = m_paths.value(path); if (!document) { continue; } const Details& details = m_documents[document]; if (details.ignored) { continue; } // Ignore unchanged documents if (info.exists() && (details.modified == info.lastModified()) && (details.permissions == info.permissions())) { continue; } // Show document emit showDocument(document); if (info.exists()) { // Process changed file QMessageBox mbox(document->window()); mbox.setIcon(QMessageBox::Warning); mbox.setWindowTitle(tr("File Changed")); mbox.setText(tr("The file '%1' was changed by another program.").arg(filename)); mbox.setInformativeText(tr("Do you want to reload the file?")); QPushButton* reload_button = mbox.addButton(tr("Reload"), QMessageBox::AcceptRole); if (reload_button->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) { reload_button->setIcon(reload_button->style()->standardIcon(QStyle::SP_BrowserReload)); } QPushButton* ignore_button = mbox.addButton(QMessageBox::Cancel); ignore_button->setText(tr("Ignore")); mbox.setDefaultButton(reload_button); mbox.exec(); if (mbox.clickedButton() == reload_button) { document->reload(false); } } else { // Process deleted file QMessageBox mbox(document->window()); mbox.setIcon(QMessageBox::Warning); mbox.setWindowTitle(tr("File Deleted")); mbox.setText(tr("The file %1 was deleted by another program.").arg(filename)); mbox.setInformativeText(tr("Do you want to save or close the file?")); mbox.setStandardButtons(QMessageBox::Save | QMessageBox::Close | QMessageBox::Ignore); mbox.setDefaultButton(QMessageBox::Save); QAbstractButton* save_button = mbox.button(QMessageBox::Save); QAbstractButton* ignore_button = mbox.button(QMessageBox::Ignore); if (ignore_button->icon().isNull() && ignore_button->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) { ignore_button->setIcon(ignore_button->style()->standardIcon(QStyle::SP_MessageBoxWarning)); } mbox.exec(); if (mbox.clickedButton() == save_button) { document->save(); } else if (mbox.clickedButton() == ignore_button) { document->setModified(true); } else { emit closeDocument(document); } } } }
void MainWindow::onDiagramsNotebookCloseDocument(DiagramEditor* diagram_editor) { closeDocument (diagram_editor); }
void OSPlugin::importIdfForSender() { LOG(Trace, "importIdfForSender"); QObject* sender = this->sender(); OSDocument* osDocument = qobject_cast<OSDocument*>(sender); OS_ASSERT(osDocument); boost::optional<std::string> key = getKeyForDocument(osDocument); OS_ASSERT(key); QString fileName = QFileDialog::getOpenFileName( m_sketchUpWidget, tr("Import Idf"), QDir::homePath(), tr("(*.idf)") ); if( ! (fileName == "") ){ boost::optional<IdfFile> idfFile; idfFile = openstudio::IdfFile::load(toPath(fileName),IddFileType::EnergyPlus); if( idfFile ){ if( !closeDocument(*key) ) { return; } IdfFile _idfFile = idfFile.get(); Workspace workspace(_idfFile); energyplus::ReverseTranslator trans; model::Model model = trans.translateWorkspace(workspace); m_startupView->hide(); processEvents(); boost::shared_ptr<OSDocument> document( new OSDocument(model, model, openstudio::path(), boost::optional<openstudio::model::Model>(), "", true) ); connectDocumentSignals(document.get()); document->markAsModified(); QMessageBox messageBox; messageBox.setText("Some portions of the idf file were not imported."); QString log; std::vector<LogMessage> messages = trans.errors(); for( std::vector<LogMessage>::iterator it = messages.begin(); it < messages.end(); it++ ) { log.append(QString::fromStdString(it->logMessage())); log.append("\n"); log.append("\n"); } messages = trans.warnings(); for( std::vector<LogMessage>::iterator it = messages.begin(); it < messages.end(); it++ ) { log.append(QString::fromStdString(it->logMessage())); log.append("\n"); log.append("\n"); } messageBox.setDetailedText(log); messageBox.exec(); m_osDocuments.insert(std::make_pair<std::string, boost::shared_ptr<OSDocument> >(*key, document)); emit newModel(*key, document->model().getImpl<openstudio::model::detail::Model_Impl>().get()); emit documentShown(*key); } } }