Commit 7b98f621 authored by Alexander A. Maly's avatar Alexander A. Maly

Fixing autocyrillization

Fixing #6
parent 7397c7e0
Pipeline #814 passed with stages
in 3 minutes and 1 second
#ifndef ACTORINTERFACE_H
#define ACTORINTERFACE_H
#include <QtCore>
//Kumir actor interface
class QMenu;
class QWidget;
namespace Shared
{
/** This MUST be returned by concrete function slot */
enum EvaluationStatus {
ES_Error, /* Evaluation error */
......@@ -17,8 +18,6 @@ enum EvaluationStatus {
ES_StackRezResult /* Success, has both indirect and stack value result */
};
class ActorInterface
{
public /*types*/:
......@@ -58,10 +57,9 @@ public /*types*/:
QMap<QLocale::Language, QString> localizedNames; /* optional */
quint8 dimension; /* array dimension (from 1 to 3) or 0 in scalar case */
inline Argument()
: accessType(InArgument), type(Void), dimension(0u) {}
Argument() : accessType(InArgument), type(Void), dimension(0u) {}
inline Argument(const QByteArray & name, const FieldType t)
Argument(const QByteArray & name, const FieldType t)
: accessType(InArgument), type(t), asciiName(name), dimension(0u) {}
};
......@@ -96,33 +94,33 @@ public /*methods*/:
virtual QString localizedModuleName(const QLocale::Language lang) const = 0;
/** List of available functions in programming language independent format */
inline virtual FunctionList functionList() const { return FunctionList(); }
virtual FunctionList functionList() const { return FunctionList(); }
/** List of custom-provided scalar types */
inline virtual TypeList typeList() const { return TypeList(); }
virtual TypeList typeList() const { return TypeList(); }
/** Runtime values for function template parameters */
inline virtual QVariantList templateParameters() const { return defaultTemplateParameters(); }
virtual QVariantList templateParameters() const { return defaultTemplateParameters(); }
/** List of actor dependencies */
inline virtual QList<ActorInterface*> usesList() const { return QList<ActorInterface*>(); }
virtual QList<ActorInterface*> usesList() const { return QList<ActorInterface*>(); }
/** Default parameters for template names */
inline virtual QVariantList defaultTemplateParameters() const { return QVariantList(); }
virtual QVariantList defaultTemplateParameters() const { return QVariantList(); }
/* === Actor control methods === */
/** Reset actor to initial state before execution starts */
inline virtual void reset() {}
virtual void reset() {}
/** Set/unset animation enabled flag */
inline virtual void setAnimationEnabled(bool on) { Q_UNUSED(on); }
virtual void setAnimationEnabled(bool on) { Q_UNUSED(on); }
/** Load actor data from external resource
* @param source ready-to-read (i.e. in opened state abstract IO device
*/
inline virtual void loadActorData(QIODevice * source) { Q_UNUSED(source); }
virtual void loadActorData(QIODevice * source) { Q_UNUSED(source); }
/* === Actor initialization methods === */
......@@ -132,22 +130,22 @@ public /*methods*/:
* @param receiver QObject-derived signal receiver
* @param methid parameterless Qt slot created by macro SLOT(...)
*/
inline virtual void connectSync(QObject * receiver, const char * method) {
virtual void connectSync(QObject * receiver, const char * method) {
Q_UNUSED(receiver); Q_UNUSED(method);
}
inline virtual void notifyGuiReady() { }
virtual void notifyGuiReady() { }
/* === Actor utilities === */
/** Converts custom-type scalar value to string representation */
inline virtual QString customValueToString(
virtual QString customValueToString(
const QByteArray & clazz,
const QVariant & value /* invalid value of a list of field values */
) const { Q_UNUSED(clazz); Q_UNUSED(value); return QString(); }
/** Converts string representation in custom-type value */
inline virtual QVariant customValueFromString(
virtual QVariant customValueFromString(
const QByteArray & clazz,
const QString & stringg
) const { Q_UNUSED(clazz); Q_UNUSED(stringg); return QVariant::Invalid; }
......@@ -164,16 +162,16 @@ public /*methods*/:
* @param arguments arguments passed to method
* @return state of method evaluation (see EvaluationStatus for more details)
*/
inline virtual EvaluationStatus evaluate(quint32 id, const QVariantList & arguments) { Q_UNUSED(id); Q_UNUSED(arguments); return ES_Error; }
virtual EvaluationStatus evaluate(quint32 id, const QVariantList & arguments) { Q_UNUSED(id); Q_UNUSED(arguments); return ES_Error; }
/** Last evaluated method return-value */
inline virtual QVariant result() const { return QVariant::Invalid; }
virtual QVariant result() const { return QVariant::Invalid; }
/** Last evaluated method error text, or an empty string in case of success */
inline virtual QString errorText() const { return QString(); }
virtual QString errorText() const { return QString(); }
/** Out-Argument and InOut-Argument values left from last evaluated method */
inline virtual QVariantList algOptResults() const { return QVariantList(); }
virtual QVariantList algOptResults() const { return QVariantList(); }
/** Terminate long-running evaluation in case of program interrupt */
virtual void terminateEvaluation() = 0;
......@@ -182,24 +180,24 @@ public /*methods*/:
/*=== Actor GUI specification === */
/** Main actor's window (if exists) */
inline virtual class QWidget * mainWidget() { return 0; }
virtual QWidget* mainWidget() { return 0; }
/** Control window (if exists) */
inline virtual class QWidget * pultWidget() { return 0; }
virtual QWidget * pultWidget() { return 0; }
/** Main window icon file name (without prefix and extension) */
inline virtual QString mainIconName() const {return QString(); }
virtual QString mainIconName() const {return QString(); }
/** Control window icon file name (without prefix and extension) */
inline virtual QString pultIconName() const {return QString(); }
virtual QString pultIconName() const {return QString(); }
/** List of toplevel GUI-menus provided by actor */
inline virtual QList<class QMenu*> moduleMenus() const { return QList<class QMenu*>(); }
virtual QList<QMenu*> moduleMenus() const { return QList<QMenu*>(); }
/*=== Generic C++ methods === */
/** The destructor. Must be declared virtual */
inline virtual ~ActorInterface() {}
virtual ~ActorInterface() {}
};
template <class StringType>
......
......@@ -68,6 +68,7 @@ public:
}
virtual AnalizerInterface * plugin() = 0;
virtual ~InstanceInterface() {};
};
......
......@@ -34,7 +34,7 @@ public:
virtual SyntaxHighlightBehaviour syntaxHighlightBehaviour() const = 0;
virtual QString languageName() const = 0;
virtual QWidget * languageQuickReferenceWidget() { return 0; }
inline virtual QByteArray asciiLanguageIdentifier() const { return languageName().toLower().toLatin1(); }
virtual QByteArray asciiLanguageIdentifier() const { return languageName().toLower().toLatin1(); }
virtual QString defaultDocumentFileNameSuffix() const = 0;
virtual Analizer::InstanceInterface * createInstance() = 0;
......
......@@ -2338,8 +2338,8 @@ TabWidgetElement * MainWindow::loadFromUrl(const QUrl & url, bool addToRecentFil
if (editor) {
QWidget * vc = editor->widget();
connect(vc, SIGNAL(message(QString)), this, SLOT(showMessage(QString)));
connect(vc, SIGNAL(requestHelpForAlgorithm(QString)),
this, SLOT(showAlgorithmHelp(QString)));
connect(vc, SIGNAL(requestHelpForAlgorithm(QString, QString)),
this, SLOT(showAlgorithmHelp(QString, QString)));
QString fileName = QFileInfo(url.toLocalFile()).fileName();
if (tabsDisabledFlag_) {
while(tabWidget_->count()) tabWidget_->removeTab(0);
......
......@@ -141,30 +141,33 @@ void EditorInstance::loadDocument(const QString &fileName, QString * error)
}
}
void EditorInstance::loadDocument(const Shared::Analizer::SourceFileInterface::Data &data, QString * error)
{
Shared::AnalizerInterface * analizerPlugin = nullptr;
Shared::Analizer::InstanceInterface * analizerInstance = nullptr;
void EditorInstance::loadDocument(
const Shared::Analizer::SourceFileInterface::Data &data,
QString * error
) {
QList<Shared::AnalizerInterface*> analizers =
ExtensionSystem::PluginManager::instance()
->findPlugins<Shared::AnalizerInterface>();
for (int i=0; i<analizers.size(); i++) {
if (analizers[i]->defaultDocumentFileNameSuffix() == data.canonicalSourceLanguageName) {
analizerPlugin = analizers[i];
analizerInstance = analizerPlugin->createInstance();
analizerPlugin_ = analizers[i];
delete analizerInstance_;
analizerInstance_ = 0;
analizerInstance_ = analizerPlugin_->createInstance();
if (data.sourceUrl.isLocalFile()) {
const QString localPath = data.sourceUrl.toLocalFile();
const QString dirName = QFileInfo(localPath).absoluteDir().path();
analizerInstance->setSourceDirName(dirName);
QString localPath = data.sourceUrl.toLocalFile();
QString dirName = QFileInfo(localPath).absoluteDir().path();
analizerInstance_->setSourceDirName(dirName);
}
break;
}
}
analizerPlugin_ = analizerPlugin;
analizerInstance_ = analizerInstance;
if (plane_) {
plane_->updateAnalizer();
}
if (analizerInstance_) {
analizerInstance_->connectUpdateRequest(this, SLOT(updateFromAnalizer()));
}
......@@ -648,7 +651,7 @@ EditorInstance::EditorInstance(
createConnections();
timerId_ = startTimer(50);
autoScrollTimerId_ = startTimer(100);
autoScrollTimerId_ = startTimer(100);
clipboardCheckTimerId_ = startTimer(250);
updateSettings(QStringList());
......@@ -661,6 +664,19 @@ EditorInstance::EditorInstance(
}
}
EditorInstance::~EditorInstance()
{
delete doc_;
doc_ = 0;
delete analizerInstance_;
analizerInstance_ = 0;
if (plane_)
plane_->deleteLater();
killTimer(timerId_);
}
void EditorInstance::setupUi()
{
horizontalScrollBar_ = new QScrollBar(Qt::Horizontal, this);
......@@ -1052,14 +1068,6 @@ Shared::Analizer::InstanceInterface * EditorInstance::analizer()
}
EditorInstance::~EditorInstance()
{
delete doc_;
plane_->deleteLater();
killTimer(timerId_);
}
QList<QAction*> EditorInstance::toolBarActions() const
{
QList<QAction*> result;
......
......@@ -151,8 +151,8 @@ private /* methods */:
void focusInEvent(QFocusEvent *e);
void loadMacros();
void createActions();
void loadMacros();
void createActions();
void timerEvent(QTimerEvent *e);
private /* fields */:
......
......@@ -35,7 +35,8 @@ uint EditorPlane::MarginWidthDefault = 15u /*px*/;
EditorPlane::EditorPlane(EditorInstance * editor)
: QWidget(editor)
, editor_(editor)
, analizerHelper_(0)
, analizer_(editor ? editor->analizer() : 0)
, helper_(0)
, caseInsensitive_(false)
, marginMousePressedPoint_(QPoint(-1000, -1000))
, delimeterRuleMousePressedPoint_(QPoint(-1000, -1000))
......@@ -52,9 +53,9 @@ EditorPlane::EditorPlane(EditorInstance * editor)
, escPressFlag_(false)
, typeTextFlag_(false)
{
if (editor->analizer()) {
caseInsensitive_ = editor->analizer()->plugin()->caseInsensitiveGrammatic();
analizerHelper_ = editor->analizer()->helper();
if (analizer_) {
helper_ = analizer_->helper();
caseInsensitive_ = analizer_->plugin()->caseInsensitiveGrammatic();
}
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
......@@ -62,11 +63,17 @@ EditorPlane::EditorPlane(EditorInstance * editor)
setAttribute(Qt::WA_Hover);
setMouseTracking(true);
setAcceptDrops(true);
setAcceptDrops(true);
initMouseCursor();
}
void EditorPlane::updateAnalizer()
{
analizer_ = editor_ ? editor_->analizer() : 0;
helper_ = analizer_ ? analizer_->helper() : 0;
}
void EditorPlane::updateSettings(const QStringList & keys)
{
if (keys.isEmpty() || keys.contains(SettingsPage::KeyFontName) || keys.contains(SettingsPage::KeyFontSize)) {
......@@ -1005,7 +1012,7 @@ void EditorPlane::paintEvent(QPaintEvent *e)
paintText(&p, e->rect().translated(-offset()));
// Paint structure marks
if (editor_->analizer() && Shared::AnalizerInterface::PythonIndents == editor_->analizer()->plugin()->indentsBehaviour()) {
if (analizer_ && Shared::AnalizerInterface::PythonIndents == analizer_->plugin()->indentsBehaviour()) {
paintProgramStructureLines(&p, e->rect().translated(-offset()));
}
......@@ -1630,7 +1637,7 @@ void EditorPlane::keyPressEvent(QKeyEvent *e)
editor_->cursor()->evaluateCommand(Utils::textByKey(Qt::Key(e->key())
, e->text()
, e->modifiers().testFlag(Qt::ShiftModifier)
, editor_->isTeacherMode() && editor_->analizer()
, editor_->isTeacherMode() && analizer_
));
}
......@@ -2194,7 +2201,7 @@ void EditorPlane::paintMarginBackground(QPainter *p, const QRect &rect)
p->drawRect(marginBackgroundRect().intersected(rect));
// Draw margin line
unsigned errorsCount = editor_->analizer() ? editor_->analizer()->errors().size() : 0u;
unsigned errorsCount = analizer_ ? analizer_->errors().size() : 0u;
QColor marginLineColor = palette().color(hasFocus()? QPalette::Highlight : QPalette::Mid);
if (errorsCount) {
const QColor bgColor = palette().color(QPalette::Base);
......@@ -2264,7 +2271,7 @@ void EditorPlane::paintSelection(QPainter *p, const QRect &rect)
int lh = lineHeight();
int cw = charWidth();
bool prevLineSelected = false;
bool hardIndent = editor_->analizer() &&
bool hardIndent = analizer_ &&
Shared::AnalizerInterface::HardIndents==editor_->analizerPlugin_->indentsBehaviour();
for (int i=startLine; i<endLine+1; i++) {
if (i<(int)editor_->document()->linesCount()) {
......@@ -2668,7 +2675,7 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
// Draw text lines themselves
for (uint i=startLine; i<=endLine; i++)
{
bool hardIndents = editor_->analizer() &&
bool hardIndents = analizer_ &&
Shared::AnalizerInterface::HardIndents==editor_->analizerPlugin_->indentsBehaviour();
// Indent count (in logical levels)
......@@ -2771,7 +2778,7 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
// Draw a symbol using obtained format
QChar ch = text[j];
if (curType & LxTypeName || curType == LxTypePrimaryKwd || curType == LxTypeSecondaryKwd) {
if (caseInsensitive_ && analizerHelper_ && text[j].isLetterOrNumber()) {
if (caseInsensitive_ && helper_ && text[j].isLetterOrNumber()) {
int wordStart = j;
int wordEnd = j;
while (text[wordStart].isLetterOrNumber() && wordStart > 0)
......@@ -2783,7 +2790,7 @@ void EditorPlane::paintText(QPainter *p, const QRect &rect)
int wordLen = wordEnd - wordStart;
if (wordLen > 0) {
const QString word = text.mid(wordStart, wordLen);
const QString capWord = analizerHelper_->correctCapitalization(word, curType);
const QString capWord = helper_->correctCapitalization(word, curType);
ch = capWord[j-wordStart];
}
}
......@@ -3068,7 +3075,7 @@ QString EditorPlane::tryCorrectKeyboardLayout(const QString &source) const
invertedLayoutText[i] = invertedLayoutText[i].toUpper();
}
}
if ( analizerHelper_->isKnownLexem(invertedLayoutText, lineNo, colNo, context) ) {
if ( helper_->isKnownLexem(invertedLayoutText, lineNo, colNo, context) ) {
return invertedLayoutText;
}
else {
......@@ -3081,7 +3088,7 @@ void EditorPlane::tryCorrectKeyboardLayoutForLastLexem()
if (Utils::isRussianLayout()) {
return; // nothing to correct: already russian keyboard layout
}
if ( ! editor_->analizerPlugin_ || ! analizerHelper_) {
if ( ! editor_->analizerPlugin_ || ! helper_) {
return; // has no information how to do it
}
if ( editor_->analizerPlugin_->primaryAlphabetIsLatin() ) {
......
......@@ -3,6 +3,7 @@
#include <kumir2-libs/extensionsystem/settings.h>
#include <kumir2-libs/docbookviewer/docbookview.h>
#include <kumir2/analizer_instanceinterface.h>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
......@@ -38,6 +39,7 @@ public:
void updateScrollBars();
void findCursor();
void ensureCursorVisible();
void updateAnalizer();
public slots:
void selectAll();
......@@ -112,8 +114,9 @@ protected slots:
private:
int timerId_;
class EditorInstance * editor_;
Shared::Analizer::HelperInterface * analizerHelper_;
class EditorInstance *editor_;
Shared::Analizer::InstanceInterface *analizer_;
Shared::Analizer::HelperInterface *helper_;
bool caseInsensitive_;
QPoint marginMousePressedPoint_;
......
......@@ -45,7 +45,8 @@ set(HEADERS
if(NOT WIN32)
# 1. -fexceptions: Exceptions is widely used by Boost
# 2. -std=c++03: Due to bug in boost 1.49 (Ticket #6785)
set(CXXFLAGS "-fexceptions -std=c++03")
# set(CXXFLAGS "-fexceptions -std=c++03")
set(CXXFLAGS "-DBOOST_EXCEPTION_DISABLE")
endif()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment