Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rgm settings #212

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set(RGM_SOURCES
Models/ResourceModelMap.cpp
Models/ImmediateMapper.cpp
Models/ProtoModel.cpp
Models/SystemsModel.cpp
Models/EventTypesListSortFilterProxyModel.cpp
Models/RepeatedSortFilterProxyModel.cpp
Components/Utility.cpp
Expand Down Expand Up @@ -114,6 +115,7 @@ set(RGM_HEADERS
Models/RepeatedModel.h
Models/EventsListModel.h
Models/ModelMapper.h
Models/SystemsModel.h
Models/RepeatedSortFilterProxyModel.h
Models/TreeSortFilterProxyModel.h
main.h
Expand Down Expand Up @@ -242,16 +244,8 @@ find_package(yaml-cpp CONFIG REQUIRED)
target_link_libraries(${EXE} PRIVATE yaml-cpp)

#Find gRPC
if (MSVC) # Windows actually does something right for once
find_package(gRPC CONFIG REQUIRED)
target_link_libraries(${EXE} PRIVATE gRPC::gpr gRPC::grpc gRPC::grpc++)
else() # https://tinyurl.com/arch-grpc-bug
find_library(LIB_GRPC_UNSECURE NAMES grpc++_unsecure)
find_library(LIB_GPR NAMES gpr)
find_library(LIB_CARES NAMES cares)
find_library(LIB_ADDRESS_SORTING NAMES address_sorting)
target_link_libraries(${EXE} PRIVATE ${LIB_CARES} ${LIB_ADDRESS_SORTING} ${LIB_GPR} ${LIB_GRPC_UNSECURE})
endif()
find_package(gRPC CONFIG REQUIRED)
target_link_libraries(${EXE} PRIVATE gRPC::gpr gRPC::grpc gRPC::grpc++)

# Find Protobuf
include(FindProtobuf)
Expand Down
101 changes: 33 additions & 68 deletions Editors/SettingsEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SettingsEditor.h"
#include "Models/SystemsModel.h"
#include "MainWindow.h"
#include "ui_SettingsEditor.h"

Expand All @@ -8,85 +9,49 @@

using namespace buffers::resources;

Q_DECLARE_METATYPE(buffers::SystemInfo);
static QMap<QString, SystemsModel*> systemsModels;

static std::string get_combo_system_id(const QComboBox* combo) {
auto data = combo->currentData();
auto subsystem = data.value<buffers::SystemInfo>();
return subsystem.id();
static void initModelCache() {
if (systemsModels.empty()) {
for (const auto& sys : qAsConst(MainWindow::systemCache)) {
systemsModels.insert(QString::fromStdString(sys.name()), new SystemsModel(sys, MainWindow::instance));
}
}
}

SettingsEditor::SettingsEditor(MessageModel* model, QWidget* parent)
: BaseEditor(model, parent), ui(new Ui::SettingsEditor) {
ui->setupUi(this);

QPushButton* saveButton = ui->buttonBox->button(QDialogButtonBox::Save);
saveButton->setIcon(QIcon(":/actions/accept.png"));
connect(saveButton, &QPushButton::clicked, [=]() {
Settings settings;
auto* api = settings.mutable_api();
api->set_target_audio(get_combo_system_id(ui->audioCombo));
api->set_target_collision(get_combo_system_id(ui->collisionCombo));
api->set_target_compiler(get_combo_system_id(ui->compilerCombo));
api->set_target_graphics(get_combo_system_id(ui->graphicsCombo));
api->set_target_network(get_combo_system_id(ui->networkCombo));
api->set_target_platform(get_combo_system_id(ui->platformCombo));
api->set_target_widgets(get_combo_system_id(ui->widgetsCombo));
api->add_extensions("Paths");

emit MainWindow::setCurrentConfig(settings);
});
QPushButton* discardButton = ui->buttonBox->button(QDialogButtonBox::Discard);
discardButton->setIcon(QIcon(":/actions/cancel.png"));

pageMap = {{"api", ui->apiPage}, {"extensions", ui->extensionsPage}, {"compiler", ui->compilerPage},
{"controls", ui->controlsPage}, {"graphics", ui->graphicsPage}, {"project info", ui->projectInfoPage},
{"version", ui->versionPage}};

const QMap<QString, QWidget*> systemUIMap = {
{QString("Audio"), ui->audioCombo}, {QString("Platform"), ui->platformCombo},
{QString("Graphics"), ui->graphicsCombo}, {QString("Widget"), ui->widgetsCombo},
{QString("Collision"), ui->collisionCombo}, {QString("Compilers"), ui->compilerCombo},
{QString("Network"), ui->networkCombo}, {QString("Extensions"), ui->extensionsList},
};
for (const auto& system : qAsConst(MainWindow::systemCache)) {
const QString systemName = QString::fromStdString(system.name());
auto it = systemUIMap.find(systemName);
if (it == systemUIMap.end()) continue;
auto widget = it.value();
const QString className = widget->metaObject()->className();
QListWidget* listWidget = nullptr;
QComboBox* combo = nullptr;
if (className == "QListWidget") {
listWidget = static_cast<QListWidget*>(widget);
} else if (className == "QComboBox") {
combo = static_cast<QComboBox*>(widget);
connect(combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=]() {
auto data = combo->currentData();
auto subsystem = data.value<buffers::SystemInfo>();
const QString subsystemDesc = QString::fromStdString(subsystem.description());
const QString subsystemAuthor = QString::fromStdString(subsystem.author());
ui->authorName->setText(subsystemAuthor);
ui->systemDesc->setPlainText(subsystemDesc);
});
}
for (const auto &subsystem : system.subsystems()) {
const QString subsystemName = QString::fromStdString(subsystem.name());
const QString subsystemId = QString::fromStdString(subsystem.id());
const QString subsystemDesc = QString::fromStdString(subsystem.description());
if (combo) {
QVariant data;
data.setValue(subsystem);
combo->addItem(subsystemName, data);
} else if (listWidget) {
auto item = new QListWidgetItem(subsystemName, listWidget);
item->setFlags(item->flags() | Qt::ItemFlag::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
item->setToolTip(subsystemDesc);
item->setData(Qt::UserRole, subsystemId);
}
}
}
initModelCache();

ui->audioCombo->setModel(systemsModels["Audio"]);
ui->platformCombo->setModel(systemsModels["Platform"]);
ui->compilerCombo->setModel(systemsModels["Compilers"]);
ui->graphicsCombo->setModel(systemsModels["Graphics"]);
ui->widgetsCombo->setModel(systemsModels["Widget"]);
ui->collisionCombo->setModel(systemsModels["Collision"]);
ui->networkCombo->setModel(systemsModels["Network"]);

SettingsEditor::RebindSubModels();
}

void SettingsEditor::RebindSubModels() {
MessageModel* sm = _model->GetSubModel<MessageModel*>(TreeNode::kSettingsFieldNumber);

ModelMapper* apiMapper = new ModelMapper(sm->GetSubModel<MessageModel*>(Settings::kApiFieldNumber));
apiMapper->addMapping(ui->audioCombo, API::kTargetAudioFieldNumber);
apiMapper->addMapping(ui->platformCombo, API::kTargetPlatformFieldNumber);
apiMapper->addMapping(ui->compilerCombo, API::kTargetCompilerFieldNumber);
apiMapper->addMapping(ui->graphicsCombo, API::kTargetGraphicsFieldNumber);
apiMapper->addMapping(ui->widgetsCombo, API::kTargetWidgetsFieldNumber);
apiMapper->addMapping(ui->networkCombo, API::kTargetNetworkFieldNumber);

BaseEditor::RebindSubModels();
}

SettingsEditor::~SettingsEditor() { delete ui; }
Expand Down
1 change: 1 addition & 0 deletions Editors/SettingsEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SettingsEditor : public BaseEditor {

public:
explicit SettingsEditor(MessageModel* model, QWidget* parent);
void RebindSubModels() override;
~SettingsEditor();

private slots:
Expand Down
9 changes: 6 additions & 3 deletions Editors/SettingsEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>6</number>
</property>
<widget class="QWidget" name="emptyPage"/>
<widget class="QWidget" name="projectInfoPage">
<layout class="QFormLayout" name="formLayout_2">
Expand Down Expand Up @@ -1215,11 +1218,11 @@
</resources>
<connections/>
<buttongroups>
<buttongroup name="inheritIncrementGroup"/>
<buttongroup name="treatLiteralsGroup"/>
<buttongroup name="treatNegativesGroup"/>
<buttongroup name="inheritStringsGroup"/>
<buttongroup name="inheritEscapesGroup"/>
<buttongroup name="inheritEquivalenceGroup"/>
<buttongroup name="inheritIncrementGroup"/>
<buttongroup name="treatNegativesGroup"/>
<buttongroup name="treatLiteralsGroup"/>
</buttongroups>
</ui>
6 changes: 3 additions & 3 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ QList<QString> MainWindow::EnigmaSearchPaths = {QDir::currentPath(), "./enigma-d
"../RadialGM/Submodules/enigma-dev"};
QFileInfo MainWindow::EnigmaRoot = MainWindow::getEnigmaRoot();
QList<buffers::SystemType> MainWindow::systemCache;
MainWindow *MainWindow::_instance = nullptr;
MainWindow *MainWindow::instance = nullptr;
ResourceModelMap *MainWindow::resourceMap = nullptr;
TreeModel *MainWindow::treeModel = nullptr;
std::unique_ptr<EventData> MainWindow::_event_data;
Expand Down Expand Up @@ -117,7 +117,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _ui(new Ui::MainW

ArtManager::Init();

_instance = this;
instance = this;

setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
Expand Down Expand Up @@ -191,7 +191,7 @@ MainWindow::~MainWindow() {
}

void MainWindow::setCurrentConfig(const buffers::resources::Settings &settings) {
emit _instance->CurrentConfigChanged(settings);
emit instance->CurrentConfigChanged(settings);
}

void MainWindow::readSettings() {
Expand Down
3 changes: 1 addition & 2 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MainWindow : public QMainWindow {
static MessageModel* resourceModel;
static TreeModel* treeModel;
static QList<buffers::SystemType> systemCache;
static MainWindow *instance;

explicit MainWindow(QWidget *parent);
~MainWindow();
Expand Down Expand Up @@ -111,8 +112,6 @@ class MainWindow : public QMainWindow {
private:
void closeEvent(QCloseEvent *event) override;

static MainWindow *_instance;

QHash<const MessageModel *, QMdiSubWindow *> _subWindows;

Ui::MainWindow *_ui;
Expand Down
2 changes: 1 addition & 1 deletion Models/MessageModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int MessageModel::rowCount(const QModelIndex &parent) const {
int MessageModel::columnCount(const QModelIndex & /*parent*/) const { return 1; }

bool MessageModel::setData(const QModelIndex &index, const QVariant &value, int role) {
R_EXPECT(index.isValid(), false) << "Supplied index was invalid:" << index;
R_EXPECT(index.isValid(), false) << DebugName() << "Supplied index was invalid:" << index;

const Descriptor *desc = _protobuf->GetDescriptor();
const Reflection *refl = _protobuf->GetReflection();
Expand Down
6 changes: 5 additions & 1 deletion Models/ModelMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ ModelMapper::ModelMapper(MessageModel *model, BaseEditor *parent) : QObject(pare
parent->connect(model, &ProtoModel::DataChanged, parent, &BaseEditor::dataChanged);
}

// mapper
ModelMapper::ModelMapper(MessageModel *model) : QObject(model), _model(model) {
_mapper = new ImmediateDataWidgetMapper(this);
_mapper->setOrientation(Qt::Vertical);
_mapper->setModel(model);
}

MessageModel *ModelMapper::GetModel() { return _model; }

Expand Down
1 change: 1 addition & 0 deletions Models/ModelMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BaseEditor;
class ModelMapper : public QObject {
public:
ModelMapper(MessageModel *_model, BaseEditor *parent);
ModelMapper(MessageModel *_model);

// mapper
void addMapping(QWidget *widget, int section, QByteArray propName = "");
Expand Down
24 changes: 24 additions & 0 deletions Models/SystemsModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "SystemsModel.h"

SystemsModel::SystemsModel(buffers::SystemType system, QObject *parent) : QAbstractListModel(parent), system_(system)
{

}

QVariant SystemsModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) return QVariant();

switch (role) {
case Qt::DisplayRole: return QString::fromStdString(system_.subsystems(index.row()).name());
//case Qt::ToolTipRole: return QString::fromStdString(system_.subsystems(index.row()).description());
default: return QVariant();
}
}

int SystemsModel::columnCount(const QModelIndex &/*parent*/) const {
return 1;
}

int SystemsModel::rowCount(const QModelIndex& /*parent*/) const {
return system_.subsystems_size();
}
23 changes: 23 additions & 0 deletions Models/SystemsModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef SYSTEMSMODEL_H
#define SYSTEMSMODEL_H

#include "compiler.pb.h"
#include "Settings.pb.h"

#include <QAbstractListModel>

using namespace buffers::resources;

class SystemsModel : public QAbstractListModel
{
public:
SystemsModel(buffers::SystemType system, QObject* parent = nullptr);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;

private:
buffers::SystemType system_;
};

#endif // SYSTEMSMODEL_H
4 changes: 3 additions & 1 deletion Models/TreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int rol
MessageModel* model = siblings->GetSubModel(node->row_in_parent)->TryCastAsMessageModel();
QString oldName = model->Data(FieldPath::Of<buffers::TreeNode>(buffers::TreeNode::kNameFieldNumber)).toString();
buffers::TreeNode::TypeCase type = (buffers::TreeNode::TypeCase)model->OneOfType("type");
R_EXPECT(MainWindow::resourceMap->ValidName(type, value.toString()), false) << "Invalid resource name";
if (value.toString() == oldName) return false;
R_EXPECT(MainWindow::resourceMap->ValidName(type, value.toString()), false) << "Invalid resource name: " <<
value.toString();
bool ret = model->SetData(FieldPath::Of<buffers::TreeNode>(buffers::TreeNode::kNameFieldNumber), value);
if (!ret) return false;
node->DataChanged();
Expand Down
3 changes: 3 additions & 0 deletions Plugins/ServerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QFileDialog>
#include <QList>
#include <QTemporaryFile>
#include <QThread>

#include <thread>
#include <memory>
Expand Down Expand Up @@ -324,6 +325,8 @@ ServerPlugin::ServerPlugin(MainWindow& mainWindow) : RGMPlugin(mainWindow) {
process->start(program, arguments);
process->waitForStarted();

QThread::sleep(5);

// construct the channel and connect to the server running in the process
// Note: gRPC is too dumb to resolve localhost on linux
std::shared_ptr<Channel> channel = CreateChannel("127.0.0.1:37818", InsecureChannelCredentials());
Expand Down
2 changes: 2 additions & 0 deletions RadialGM.pro
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SOURCES += \
Models/RepeatedMessageModel.cpp \
Models/RepeatedModel.cpp \
Models/RepeatedSortFilterProxyModel.cpp \
Models/SystemsModel.cpp \
Utils/FieldPath.cpp \
Utils/ProtoManip.cpp \
Widgets/AssetScrollAreaBackground.cpp \
Expand Down Expand Up @@ -141,6 +142,7 @@ HEADERS += \
Models/RepeatedModel.h \
Models/RepeatedPrimitiveModel.h \
Models/RepeatedSortFilterProxyModel.h \
Models/SystemsModel.h \
Utils/FieldPath.h \
Utils/ProtoManip.h \
Utils/QBoilerplate.h \
Expand Down