Skip to content

Commit

Permalink
added test script NewScore10InstrPutNotesSaveClose
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkorsukov committed Oct 7, 2021
1 parent 285e70e commit 80d1778
Show file tree
Hide file tree
Showing 22 changed files with 290 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ option(ENGRAVING_COMPAT_WRITESTYLE_302 "Write style to score xml file" ON)
option(ENGRAVING_COMPAT_WRITEEXCERPTS_302 "Write excerpts to score xml file" ON)
# -----

option(UI_DISABLE_MODALITY "Disable dialogs modality for testing purpose" OFF)

option(ACCESSIBILITY_LOGGING_ENABLED "Enable accessibility logging" OFF)

option(SOUNDFONT3 "Ogg Vorbis compressed fonts" ON) # Enable Ogg Vorbis compressed fonts, requires Ogg & Vorbis
Expand Down
2 changes: 2 additions & 0 deletions build/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
#cmakedefine ENGRAVING_COMPAT_WRITESTYLE_302
#cmakedefine ENGRAVING_COMPAT_WRITEEXCERPTS_302

#cmakedefine UI_DISABLE_MODALITY

#cmakedefine ACCESSIBILITY_LOGGING_ENABLED

#cmakedefine SPARKLE_ENABLED
Expand Down
2 changes: 1 addition & 1 deletion src/appshell/view/appmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ MenuItem AppMenuModel::diagnosticItem() const
};

MenuItemList autobotItems {
makeMenuItem("autobot-show-batchtests"),
makeMenuItem("autobot-show-scripts"),
makeMenuItem("autobot-show-batchtests"),
};

MenuItemList items {
Expand Down
3 changes: 2 additions & 1 deletion src/autobot/iautobotconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class IAutobotConfiguration : MODULE_EXPORT_INTERFACE

virtual io::path dataPath() const = 0;

virtual io::path filesPath() const = 0;
virtual io::path testingFilesPath() const = 0;
virtual io::path savingFilesPath() const = 0;

virtual io::path drawDataPath() const = 0;
virtual io::path fileDrawDataPath(const io::path& filePath) const = 0;
Expand Down
32 changes: 29 additions & 3 deletions src/autobot/internal/api/autobotapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "autobotapi.h"

#include <QTimer>
#include <QFileInfo>
#include <QDir>
#include <QDateTime>

#include "async/async.h"

Expand All @@ -36,12 +39,23 @@ AutobotApi::AutobotApi(IApiEngine* e)

bool AutobotApi::openProject(const QString& name)
{
io::path dir = autobotConfiguration()->filesPath();
io::path dir = autobotConfiguration()->testingFilesPath();
io::path filePath = dir + "/" + name;
Ret ret = projectFilesController()->openProject(filePath);
return ret;
}

void AutobotApi::saveProject(const QString& name)
{
io::path dir = autobotConfiguration()->savingFilesPath();
if (!QFileInfo::exists(dir.toQString())) {
QDir().mkpath(dir.toQString());
}

io::path filePath = dir + "/" + QDateTime::currentDateTime().toString(Qt::ISODate) + "_" + name;
projectFilesController()->saveProject(filePath);
}

void AutobotApi::setInterval(int msec)
{
m_intervalMsec = msec;
Expand Down Expand Up @@ -109,7 +123,7 @@ bool AutobotApi::pause()
return true;
}

void AutobotApi::sleep(int msec)
void AutobotApi::sleep(int msec) const
{
if (msec < 0) {
msec = m_intervalMsec;
Expand All @@ -122,16 +136,28 @@ void AutobotApi::sleep(int msec)
loop.exec();
}

void AutobotApi::waitPopup()
void AutobotApi::waitPopup() const
{
//! NOTE We could do it smartly, check a current popup actually opened, but or just sleep some time
sleep(500);
}

void AutobotApi::seeChanges(int msec)
{
sleep(msec);
}

void AutobotApi::async(const QJSValue& func, const QJSValueList& args)
{
async::Async::call(this, [func, args]() {
QJSValue mut_func = func;
mut_func.call(args);
});
}

int AutobotApi::randomInt(int min, int max) const
{
srand(time(nullptr)); // Seed the time
int val = rand() % (max - min + 1) + min;
return val;
}
7 changes: 5 additions & 2 deletions src/autobot/internal/api/autobotapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ class AutobotApi : public ApiObject, public async::Asyncable
Q_INVOKABLE void runTestCase(const QJSValue& testCase);

Q_INVOKABLE bool openProject(const QString& name);
Q_INVOKABLE void saveProject(const QString& name = QString());

Q_INVOKABLE void abort();
Q_INVOKABLE bool pause();
Q_INVOKABLE void sleep(int msec = -1);
Q_INVOKABLE void waitPopup();
Q_INVOKABLE void sleep(int msec = -1) const;
Q_INVOKABLE void waitPopup() const;
Q_INVOKABLE void seeChanges(int msec = 300);
Q_INVOKABLE void async(const QJSValue& func, const QJSValueList& args = QJSValueList());
Q_INVOKABLE int randomInt(int min, int max) const;

private:

Expand Down
32 changes: 32 additions & 0 deletions src/autobot/internal/api/navigationapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@
#include "log.h"

using namespace mu::api;
using namespace mu::ui;

NavigationApi::NavigationApi(IApiEngine* e)
: ApiObject(e)
{
//! NOTE Disable reset on mouse press for testing purpose
navigation()->setIsResetOnMousePress(false);
}

NavigationApi::~NavigationApi()
{
//! NOTE Return default
navigation()->setIsResetOnMousePress(true);
}

void NavigationApi::nextPanel()
Expand Down Expand Up @@ -60,6 +69,11 @@ void NavigationApi::down()
dispatcher()->dispatch("nav-down");
}

void NavigationApi::escape()
{
dispatcher()->dispatch("nav-escape");
}

bool NavigationApi::goToControl(const QString& section, const QString& panel, const QString& contol)
{
bool ok = navigation()->requestActivateByName(section.toStdString(), panel.toStdString(), contol.toStdString());
Expand All @@ -79,3 +93,21 @@ bool NavigationApi::triggerControl(const QString& section, const QString& panel,
}
return ok;
}

QString NavigationApi::activeSection() const
{
INavigationSection* sec = navigation()->activeSection();
return sec ? sec->name() : QString();
}

QString NavigationApi::activePanel() const
{
INavigationPanel* p = navigation()->activePanel();
return p ? p->name() : QString();
}

QString NavigationApi::activeControl() const
{
INavigationControl* c = navigation()->activeControl();
return c ? c->name() : QString();
}
6 changes: 6 additions & 0 deletions src/autobot/internal/api/navigationapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ class NavigationApi : public ApiObject

public:
explicit NavigationApi(IApiEngine* e);
~NavigationApi();

Q_INVOKABLE void nextPanel();
Q_INVOKABLE void prevPanel();
Q_INVOKABLE void right();
Q_INVOKABLE void left();
Q_INVOKABLE void up();
Q_INVOKABLE void down();
Q_INVOKABLE void escape();
Q_INVOKABLE bool goToControl(const QString& section, const QString& panel, const QString& contol);
Q_INVOKABLE void trigger();
Q_INVOKABLE bool triggerControl(const QString& section, const QString& panel, const QString& contol);

Q_INVOKABLE QString activeSection() const;
Q_INVOKABLE QString activePanel() const;
Q_INVOKABLE QString activeControl() const;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/autobot/internal/autobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mu::RetVal<mu::io::paths> Autobot::filesList() const
{
using namespace mu::system;

io::path filesPath = configuration()->filesPath();
io::path filesPath = configuration()->testingFilesPath();
LOGI() << "filesPath: " << filesPath;
RetVal<io::paths> paths = fileSystem()->scanFiles(filesPath, QStringList(), IFileSystem::ScanMode::OnlyCurrentDir);
return paths;
Expand Down
18 changes: 15 additions & 3 deletions src/autobot/internal/autobotconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,36 @@
#include "autobotconfiguration.h"

#include <cstdlib>
#include <QDir>

using namespace mu::autobot;

bool AutobotConfiguration::isConfigured() const
{
return !dataPath().empty() && !filesPath().empty();
return !dataPath().empty() && !testingFilesPath().empty();
}

mu::io::path AutobotConfiguration::dataPath() const
{
return io::path(std::getenv("MU_AUTOBOT_DATA_PATH"));
io::path p = io::path(std::getenv("MU_AUTOBOT_DATA_PATH"));
if (p.empty()) {
QDir projDir(QString(PROJECT_ROOT_DIR));
projDir.cdUp();
p = projDir.absolutePath() + "/mu_autobot_data";
}
return p;
}

mu::io::path AutobotConfiguration::filesPath() const
mu::io::path AutobotConfiguration::testingFilesPath() const
{
return io::path(std::getenv("MU_AUTOBOT_FILES_PATH"));
}

mu::io::path AutobotConfiguration::savingFilesPath() const
{
return dataPath() + "/saving_files";
}

mu::io::path AutobotConfiguration::drawDataPath() const
{
return dataPath() + "/draw_data";
Expand Down
3 changes: 2 additions & 1 deletion src/autobot/internal/autobotconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class AutobotConfiguration : public IAutobotConfiguration

io::path dataPath() const override;

io::path filesPath() const override;
io::path testingFilesPath() const override;
io::path savingFilesPath() const override;

io::path drawDataPath() const override;
io::path fileDrawDataPath(const io::path& filePath) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/autobot/qml/MuseScore/Autobot/ScriptsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ StyledDialogView {

title: "Autobot"

contentHeight: 800
contentWidth: 600
contentHeight: 600
contentWidth: 400
resizable: true

ScriptsPanel {
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/inavigationcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class INavigationController : MODULE_EXPORT_INTERFACE
virtual INavigationControl* activeControl() const = 0;

virtual async::Notification navigationChanged() const = 0;

virtual void setIsResetOnMousePress(bool arg) = 0;
};
}

Expand Down
32 changes: 27 additions & 5 deletions src/framework/ui/internal/navigationcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,30 @@ const std::set<INavigationSection*>& NavigationController::sections() const
return m_sections;
}

bool NavigationController::eventFilter(QObject* watched, QEvent* event)
void NavigationController::setIsResetOnMousePress(bool arg)
{
if (event->type() == QEvent::MouseButtonPress) {
m_isResetOnMousePress = arg;
}

void NavigationController::resetActiveIfNeed(QObject* watched)
{
if (!m_isResetOnMousePress) {
return;
}

#ifdef BUILD_DIAGNOSTICS
if (!diagnostics::isDiagnosticHierarchy(watched))
if (diagnostics::isDiagnosticHierarchy(watched)) {
return;
}
#endif
resetActive();

resetActive();
}

bool NavigationController::eventFilter(QObject* watched, QEvent* event)
{
if (event->type() == QEvent::MouseButtonPress) {
resetActiveIfNeed(watched);
}

return QObject::eventFilter(watched, event);
Expand Down Expand Up @@ -420,7 +437,12 @@ void NavigationController::doActivatePanel(INavigationPanel* panel)
ctrlIndex.row = idxVal.at(0).toInt();
ctrlIndex.column = idxVal.at(1).toInt();
control = findByIndex(panel->controls(), ctrlIndex);
IF_ASSERT_FAILED(control) {
if (!control) {
bool isOptional = event->data.value("controlOptional").toBool();
if (!isOptional) {
IF_ASSERT_FAILED(control) {
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/framework/ui/internal/navigationcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class NavigationController : public QObject, public INavigationController, publi

async::Notification navigationChanged() const override;

void setIsResetOnMousePress(bool arg) override;

void init();

private:
Expand Down Expand Up @@ -100,10 +102,12 @@ class NavigationController : public QObject, public INavigationController, publi
void doActivateFirst();
void doActivateLast();

void resetActiveIfNeed(QObject* watched);
void resetActive();

std::set<INavigationSection*> m_sections;
async::Notification m_navigationChanged;
bool m_isResetOnMousePress = true;
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/framework/uicomponents/view/popupview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "popupwindow/popupwindow_qquickview.h"

#include "log.h"
#include "config.h"

using namespace mu::uicomponents;

Expand Down Expand Up @@ -161,6 +162,9 @@ void PopupView::open()
}
qWindow->setTitle(m_title);
qWindow->setModality(m_modal ? Qt::ApplicationModal : Qt::NonModal);
#ifdef UI_DISABLE_MODALITY
qWindow->setModality(Qt::NonModal);
#endif

QRect winRect = m_window->geometry();
qWindow->setMinimumSize(winRect.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Item {
onNavigationEvent: {
if (event.type === NavigationEvent.AboutActive) {
event.setData("controlIndex", prv.currentItemNavigationIndex)
//! NOTE If we changed family, then control with saved index maybe not
event.setData("controlOptional", true)
}
}
}
Expand Down
Loading

0 comments on commit 80d1778

Please sign in to comment.