From a264c277653406db42d2c1503bbed3c40c094f35 Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Fri, 10 Apr 2015 14:32:37 +0200
Subject: [PATCH] Cleanup from old PyScriptView and PythonHighlighter

---
 GUI/coregui/Views/PyScriptView.cpp            | 110 ------------------
 GUI/coregui/Views/PyScriptView.h              |  49 --------
 GUI/coregui/mainwindow/mainwindow.cpp         |   3 -
 GUI/coregui/mainwindow/mainwindow.h           |   1 -
 .../utils/PyScriptSyntaxHighlighter.cpp       |  64 ----------
 GUI/coregui/utils/PyScriptSyntaxHighlighter.h |  54 ---------
 6 files changed, 281 deletions(-)
 delete mode 100644 GUI/coregui/Views/PyScriptView.cpp
 delete mode 100644 GUI/coregui/Views/PyScriptView.h
 delete mode 100644 GUI/coregui/utils/PyScriptSyntaxHighlighter.cpp
 delete mode 100644 GUI/coregui/utils/PyScriptSyntaxHighlighter.h

diff --git a/GUI/coregui/Views/PyScriptView.cpp b/GUI/coregui/Views/PyScriptView.cpp
deleted file mode 100644
index 19a233fdd7f..00000000000
--- a/GUI/coregui/Views/PyScriptView.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-// ************************************************************************** //
-//
-//  BornAgain: simulate and fit scattering at grazing incidence
-//
-//! @file      coregui/Views/PyScriptView.cpp
-//! @brief     Implements class PyScriptView
-//!
-//! @homepage  http://www.bornagainproject.org
-//! @license   GNU General Public License v3 or higher (see COPYING)
-//! @copyright Forschungszentrum Jülich GmbH 2015
-//! @authors   Scientific Computing Group at MLZ Garching
-//! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
-//
-// ************************************************************************** //
-
-#include "PyScriptView.h"
-
-#include "PyScriptSyntaxHighlighter.h"
-
-#include <iostream>
-
-#include <QWidget>
-#include <QLabel>
-#include <QPushButton>
-#include <QTextEdit>
-#include <QHBoxLayout>
-#include <QGridLayout>
-#include <QFileDialog>
-#include <QFile>
-#include <QTextStream>
-
-PyScriptView::PyScriptView(SimulationDataModel *p_simulation_data_model, QWidget *parent)
-    : QWidget(parent)
-    , mp_simulation_data_model(p_simulation_data_model)
-{
-    QLabel *openLabel = new QLabel(tr("Open Script:"));
-    QLabel *saveLabel = new QLabel(tr("Save Script:"));
-    openButton = new QPushButton(tr("Open..."));
-    openButton->show();
-    saveButton = new QPushButton(tr("Save as..."));
-    saveButton->setEnabled(false);
-    saveButton->show();
-
-    connect(openButton, SIGNAL(clicked()), this, SLOT(onOpenScript()));
-    connect(saveButton, SIGNAL(clicked()), this, SLOT(onSaveScript()));
-
-    QGridLayout *buttonLayoutNoStretch = new QGridLayout;
-    buttonLayoutNoStretch->addWidget(openLabel, 0, 0);
-    buttonLayoutNoStretch->addWidget(openButton, 0, 1);
-    buttonLayoutNoStretch->addWidget(saveLabel, 1, 0);
-    buttonLayoutNoStretch->addWidget(saveButton, 1, 1);
-
-    QHBoxLayout *buttonLayout = new QHBoxLayout;
-    buttonLayout->addLayout(buttonLayoutNoStretch);
-    buttonLayout->addStretch();
-
-    scriptEdit = new QTextEdit;
-    scriptEdit->setFontFamily("Courier");
-    scriptEdit->setFontPointSize(14);
-    connect(scriptEdit, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
-
-    PyScriptSyntaxHighlighter *highlighter = new PyScriptSyntaxHighlighter(scriptEdit->document());
-    Q_UNUSED(highlighter);
-
-    QGridLayout *mainLayout = new QGridLayout;
-    mainLayout->addLayout(buttonLayout, 0, 0);
-    mainLayout->addWidget(scriptEdit, 1, 0);
-
-    setLayout(mainLayout);
-    setWindowTitle(tr("Python script editing"));
-}
-
-void PyScriptView::onOpenScript()
-{
-    QString newScriptFilename = QFileDialog::getOpenFileName(this, tr("Open Python Script"),
-        QDir::homePath(), tr("Python SCripts (*.py)"),
-        0, QFileDialog::ReadOnly | QFileDialog::DontUseNativeDialog);
-    if (newScriptFilename.isNull()) {
-        return;
-    }
-    QFile scriptFile(newScriptFilename);
-    if (!scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
-        return;
-    }
-    QTextStream fileStream(&scriptFile);
-    oldScriptFilename = newScriptFilename;
-    scriptEdit->setText(fileStream.readAll());
-}
-
-void PyScriptView::onSaveScript()
-{
-    QString saveFilename = QFileDialog::getSaveFileName(this, tr("Save Python SCript"),
-                              oldScriptFilename, tr("Python Scripts (*.py)"),
-                              0, QFileDialog::ReadOnly | QFileDialog::DontUseNativeDialog);
-    if (saveFilename.isNull()) {
-        return;
-    }
-    QFile scriptFile(saveFilename);
-    if (!scriptFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
-        return;
-    }
-    QTextStream fileStream(&scriptFile);
-    fileStream << scriptEdit->toPlainText();
-    saveButton->setEnabled(false);
-}
-
-void PyScriptView::onTextChanged()
-{
-    saveButton->setEnabled(true);
-}
diff --git a/GUI/coregui/Views/PyScriptView.h b/GUI/coregui/Views/PyScriptView.h
deleted file mode 100644
index 165c3dff9e6..00000000000
--- a/GUI/coregui/Views/PyScriptView.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// ************************************************************************** //
-//
-//  BornAgain: simulate and fit scattering at grazing incidence
-//
-//! @file      coregui/Views/PyScriptView.h
-//! @brief     Defines class PyScriptView
-//!
-//! @homepage  http://www.bornagainproject.org
-//! @license   GNU General Public License v3 or higher (see COPYING)
-//! @copyright Forschungszentrum Jülich GmbH 2015
-//! @authors   Scientific Computing Group at MLZ Garching
-//! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
-//
-// ************************************************************************** //
-
-#ifndef PYSCRIPTVIEW_H
-#define PYSCRIPTVIEW_H
-
-#include "WinDllMacros.h"
-#include <QWidget>
-#include <QString>
-
-class SimulationDataModel;
-class QPushButton;
-class QTextEdit;
-
-class BA_CORE_API_ PyScriptView : public QWidget
-{
-    Q_OBJECT
-
-public:
-    PyScriptView(SimulationDataModel *p_simulation_data_model, QWidget *parent = 0);
-    virtual ~PyScriptView() {}
-
-public slots:
-    void onOpenScript();
-    void onSaveScript();
-    void onTextChanged();
-
-private:
-    QPushButton *openButton;
-    QPushButton *saveButton;
-    QTextEdit *scriptEdit;
-    SimulationDataModel *mp_simulation_data_model;
-    QString oldScript;
-    QString oldScriptFilename;
-};
-
-#endif // PYSCRIPTVIEW_H
diff --git a/GUI/coregui/mainwindow/mainwindow.cpp b/GUI/coregui/mainwindow/mainwindow.cpp
index d69ce6833eb..cab131f72a4 100644
--- a/GUI/coregui/mainwindow/mainwindow.cpp
+++ b/GUI/coregui/mainwindow/mainwindow.cpp
@@ -19,7 +19,6 @@
 #include "actionmanager.h"
 #include "WelcomeView.h"
 #include "SampleView.h"
-#include "PyScriptView.h"
 #include "InstrumentView.h"
 #include "SimulationView.h"
 #include "MaterialEditorWidget.h"
@@ -75,7 +74,6 @@ MainWindow::MainWindow(QWidget *parent)
     , m_welcomeView(0)
     , m_instrumentView(0)
     , m_sampleView(0)
-    , m_scriptView(0)
     , m_simulationView(0)
     , m_jobView(0)
     , m_fitView(0)
@@ -117,7 +115,6 @@ MainWindow::MainWindow(QWidget *parent)
     m_welcomeView = new WelcomeView(this);
     m_instrumentView = new InstrumentView(m_instrumentModel);
     m_sampleView = new SampleView(m_sampleModel, m_instrumentModel);
-    //m_scriptView = new PyScriptView(mp_sim_data_model);
     m_simulationView = new SimulationView(this);
 
 //    m_testView = new TestView(m_sampleModel, this);
diff --git a/GUI/coregui/mainwindow/mainwindow.h b/GUI/coregui/mainwindow/mainwindow.h
index 35898d2c2bb..26538d81067 100644
--- a/GUI/coregui/mainwindow/mainwindow.h
+++ b/GUI/coregui/mainwindow/mainwindow.h
@@ -85,7 +85,6 @@ private:
     WelcomeView *m_welcomeView;
     InstrumentView *m_instrumentView;
     SampleView *m_sampleView;
-    PyScriptView *m_scriptView;
     SimulationView *m_simulationView;
 
     JobView *m_jobView;
diff --git a/GUI/coregui/utils/PyScriptSyntaxHighlighter.cpp b/GUI/coregui/utils/PyScriptSyntaxHighlighter.cpp
deleted file mode 100644
index b795a94e374..00000000000
--- a/GUI/coregui/utils/PyScriptSyntaxHighlighter.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-// ************************************************************************** //
-//
-//  BornAgain: simulate and fit scattering at grazing incidence
-//
-//! @file      coregui/utils/PyScriptSyntaxHighlighter.cpp
-//! @brief     Implements class PyScriptSyntaxHighlighter
-//!
-//! @homepage  http://www.bornagainproject.org
-//! @license   GNU General Public License v3 or higher (see COPYING)
-//! @copyright Forschungszentrum Jülich GmbH 2015
-//! @authors   Scientific Computing Group at MLZ Garching
-//! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
-//
-// ************************************************************************** //
-
-#include "PyScriptSyntaxHighlighter.h"
-
-PyScriptSyntaxHighlighter::PyScriptSyntaxHighlighter(QTextDocument *document)
-    : QSyntaxHighlighter(document)
-{
-    QTextCharFormat keywordFormat;
-    keywordFormat.setForeground(Qt::darkRed);
-    setFormatForElementType(KEYWORD, keywordFormat);
-
-    QTextCharFormat commentFormat;
-    commentFormat.setForeground(Qt::blue);
-    setFormatForElementType(COMMENT, commentFormat);
-}
-
-void PyScriptSyntaxHighlighter::setFormatForElementType(EElementType element_type,
-                                    const QTextCharFormat &format)
-{
-    m_formats[element_type] = format;
-    rehighlight();
-}
-
-void PyScriptSyntaxHighlighter::highlightBlock(const QString &text)
-{
-    int state = previousBlockState();
-    int line_length = text.length();
-    int pos = 0;
-
-    while (pos<line_length)
-    {
-        switch (state)
-        {
-        case NORMAL:
-        default:
-            if (text.at(pos) == '#') {
-                setFormat(pos, line_length - pos, formatFor(COMMENT));
-                pos = line_length;
-                break;
-            } else {
-                ++pos;
-            }
-        }
-    }
-}
-
-bool PyScriptSyntaxHighlighter::isKeyword(const QString &text) const
-{
-    (void)text;
-    return false;
-}
diff --git a/GUI/coregui/utils/PyScriptSyntaxHighlighter.h b/GUI/coregui/utils/PyScriptSyntaxHighlighter.h
deleted file mode 100644
index 656340b5cda..00000000000
--- a/GUI/coregui/utils/PyScriptSyntaxHighlighter.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// ************************************************************************** //
-//
-//  BornAgain: simulate and fit scattering at grazing incidence
-//
-//! @file      coregui/utils/PyScriptSyntaxHighlighter.h
-//! @brief     Defines class PyScriptSyntaxHighlighter
-//!
-//! @homepage  http://www.bornagainproject.org
-//! @license   GNU General Public License v3 or higher (see COPYING)
-//! @copyright Forschungszentrum Jülich GmbH 2015
-//! @authors   Scientific Computing Group at MLZ Garching
-//! @authors   C. Durniak, M. Ganeva, G. Pospelov, W. Van Herck, J. Wuttke
-//
-// ************************************************************************** //
-
-#ifndef PYSCRIPTSYNTAXHIGHLIGHTER_H
-#define PYSCRIPTSYNTAXHIGHLIGHTER_H
-
-#include "WinDllMacros.h"
-#include <QSyntaxHighlighter>
-
-class BA_CORE_API_  PyScriptSyntaxHighlighter : public QSyntaxHighlighter
-{
-    Q_OBJECT
-
-public:
-    enum EElementType {
-        KEYWORD,
-        COMMENT,
-        LAST_ELEMENT_TYPE = COMMENT
-    };
-
-    PyScriptSyntaxHighlighter(QTextDocument *document);
-    virtual ~PyScriptSyntaxHighlighter() {}
-
-    void setFormatForElementType(EElementType element_type,
-                                 const QTextCharFormat &format);
-    QTextCharFormat formatFor(EElementType element_type) const {
-        return m_formats[element_type];
-    }
-
-protected:
-    enum EState {
-        NORMAL = -1,
-        INSIDE_COMMENT
-    };
-
-    virtual void highlightBlock(const QString &text);
-private:
-    bool isKeyword(const QString &text) const;
-    QTextCharFormat m_formats[LAST_ELEMENT_TYPE + 1];
-};
-
-#endif // PYSCRIPTSYNTAXHIGHLIGHTER_H
-- 
GitLab