Exemplo n.º 1
0
void GraphEditorTabs::handleSaveAs(void)
{
    auto editor = dynamic_cast<GraphEditor *>(this->currentWidget());
    assert(editor != nullptr);

    QString lastPath;
    if(editor->getCurrentFilePath().isEmpty())
    {
        auto defaultPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/untitled.pth";
        assert(!defaultPath.isEmpty());
        lastPath = defaultPath;
    }
    else
    {
        lastPath = editor->getCurrentFilePath();
    }
    this->setCurrentWidget(editor);
    auto filePath = QFileDialog::getSaveFileName(this,
                        tr("Save As"),
                        lastPath,
                        tr("Pothos Topologies (*.pth)"));
    if (filePath.isEmpty()) return;
    if (not filePath.endsWith(".pth")) filePath += ".pth";
    getSettings().setValue("GraphEditorTabs/lastFile", filePath);
    editor->setCurrentFilePath(filePath);
    editor->save();
    this->saveState();
}
Exemplo n.º 2
0
void GraphEditorTabs::handleExit(QCloseEvent *event)
{
    //save the currently selected editor tab
    getSettings().setValue("GraphEditorTabs/activeIndex", this->currentIndex());

    //exit logic -- save changes dialogs
    for (int i = 0; i < this->count(); i++)
    {
        auto editor = dynamic_cast<GraphEditor *>(this->widget(i));
        assert(editor != nullptr);
        if (not editor->hasUnsavedChanges()) continue;

        this->setCurrentIndex(i); //select this editor

        //yes/no dialog if we have unsaved changes
        const auto reply = QMessageBox::question(this,
            tr("Exit: unsaved changes!"),
            tr("Unsaved changes %1!\nWould you like to save changes?").arg(editor->getCurrentFilePath()),
            QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);

        if (reply == QMessageBox::Cancel)
        {
            event->ignore();
            return;
        }
        if (reply == QMessageBox::Yes) this->handleSave();
    }

    event->accept();
}
Exemplo n.º 3
0
void GraphEditorTabs::handleSave(void)
{
    auto editor = dynamic_cast<GraphEditor *>(this->currentWidget());
    assert(editor != nullptr);

    //no file path? redirect to save as
    if (editor->getCurrentFilePath().isEmpty()) this->handleSaveAs();

    //otherwise, just save the topology
    else editor->save();
}
Exemplo n.º 4
0
void GraphEditorTabs::saveState(void)
{
    //save the file paths for the editors
    QStringList files;
    for (int i = 0; i < this->count(); i++)
    {
        auto editor = dynamic_cast<GraphEditor *>(this->widget(i));
        assert(editor != nullptr);
        files.push_back(editor->getCurrentFilePath());
    }
    getSettings().setValue("GraphEditorTabs/files", files);
}
Exemplo n.º 5
0
void GraphEditorTabs::handleExport(void)
{
    auto editor = dynamic_cast<GraphEditor *>(this->currentWidget());
    assert(editor != nullptr);

    auto path = editor->getCurrentFilePath();
    if (path.endsWith(".pothos")) path = path.left(path.size()-7);
    if (path.endsWith(".pth")) path = path.left(path.size()-4);
    path += ".json";

    editor->exportToJSONTopology(path);
}
Exemplo n.º 6
0
void GraphEditorTabs::handleOpen(const QString &filePath)
{
    //filter out files that are already open
    for (int j = 0; j < this->count(); j++)
    {
        auto editor = dynamic_cast<GraphEditor *>(this->widget(j));
        assert(editor != nullptr);
        if (editor->getCurrentFilePath() == filePath)
        {
            return this->doReloadDialog(editor);
        }
    }

    //open a new editor with the specified file
    auto editor = new GraphEditor(this);
    editor->setCurrentFilePath(filePath);
    this->addTab(editor, "");
    editor->load();
    this->setCurrentWidget(editor);

    this->saveState();
}
Exemplo n.º 7
0
void GraphEditorTabs::handleExportAs(void)
{
    auto editor = dynamic_cast<GraphEditor *>(this->currentWidget());
    assert(editor != nullptr);

    QString lastPath = editor->getCurrentFilePath();
    if (lastPath.isEmpty()) lastPath = defaultSavePath();
    if (lastPath.endsWith(".pothos")) lastPath = lastPath.left(lastPath.size()-7);
    if (lastPath.endsWith(".pth")) lastPath = lastPath.left(lastPath.size()-4);
    lastPath += ".json";

    this->setCurrentWidget(editor);
    auto filePath = QFileDialog::getSaveFileName(this,
                        tr("Export As"),
                        lastPath,
                        tr("Exported JSON Topologies (*.json)"));
    if (filePath.isEmpty()) return;
    if (not filePath.endsWith(".json")) filePath += ".json";
    filePath = QDir(filePath).absolutePath();

    editor->exportToJSONTopology(filePath);
}
Exemplo n.º 8
0
void GraphEditorTabs::handleSaveAs(void)
{
    auto editor = dynamic_cast<GraphEditor *>(this->currentWidget());
    assert(editor != nullptr);

    QString lastPath = editor->getCurrentFilePath();
    if (lastPath.isEmpty()) lastPath = defaultSavePath();

    this->setCurrentWidget(editor);
    auto filePath = QFileDialog::getSaveFileName(this,
                        tr("Save As"),
                        lastPath,
                        tr("Pothos Topologies (*.pothos *.pth)"));
    if (filePath.isEmpty()) return;
    if (not filePath.endsWith(".pothos")) filePath += ".pothos";
    filePath = QDir(filePath).absolutePath();
    auto settings = MainSettings::global();
    settings->setValue("GraphEditorTabs/lastFile", filePath);
    editor->setCurrentFilePath(filePath);
    editor->save();
    this->saveState();
}