Skip to content

Commit

Permalink
New TreeModel (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshDreamland committed Sep 6, 2021
1 parent 977fcbe commit 7b5ef37
Show file tree
Hide file tree
Showing 70 changed files with 3,916 additions and 1,645 deletions.
210 changes: 109 additions & 101 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,110 +48,118 @@ include_directories("${CMAKE_BINARY_DIR}/Submodules/enigma-dev/shared/protos/" "

# Populate a CMake variable with the sources
set(RGM_SOURCES
Plugins/RGMPlugin.cpp
main.cpp
MainWindow.cpp
Dialogs/EventArgumentsDialog.cpp
Dialogs/PreferencesDialog.cpp
Dialogs/TimelineChangeMoment.cpp
Components/ArtManager.cpp
Components/Utility.cpp
Components/QMenuView.cpp
Components/RecentFiles.cpp
Models/TreeSortFilterProxyModel.cpp
Models/MessageModel.cpp
Models/RepeatedImageModel.cpp
Models/RepeatedStringModel.cpp
Models/ModelMapper.cpp
Models/ProtoModel.cpp
Models/RepeatedMessageModel.cpp
Models/ImmediateMapper.cpp
Models/ResourceModelMap.cpp
Models/TreeModel.cpp
Models/EventsListModel.cpp
Models/EventTypesListModel.cpp
Models/EventTypesListSortFilterProxyModel.cpp
Editors/ObjectEditor.cpp
Editors/PathEditor.cpp
Editors/CodeEditor.cpp
Editors/SoundEditor.cpp
Editors/FontEditor.cpp
Editors/BackgroundEditor.cpp
Editors/TimelineEditor.cpp
Editors/ShaderEditor.cpp
Editors/ScriptEditor.cpp
Editors/SettingsEditor.cpp
Editors/SpriteEditor.cpp
Editors/BaseEditor.cpp
Editors/RoomEditor.cpp
Editors/IncludeEditor.cpp
Widgets/AssetView.cpp
Widgets/CodeWidget.cpp
Widgets/BackgroundView.cpp
Widgets/StackedCodeWidget.cpp
Widgets/RoomView.cpp
Widgets/PathView.cpp
Widgets/AssetScrollAreaBackground.cpp
Widgets/SpriteSubimageListView.cpp
Widgets/ColorPicker.cpp
Widgets/SpriteView.cpp
Models/RepeatedMessageModel.cpp
Models/TreeSortFilterProxyModel.cpp
Models/PrimitiveModel.cpp
Models/EventsListModel.cpp
Models/ModelMapper.cpp
Models/RepeatedModel.cpp
Models/MessageModel.cpp
Models/TreeModel.cpp
Models/EventTypesListModel.cpp
Models/ResourceModelMap.cpp
Models/ImmediateMapper.cpp
Models/ProtoModel.cpp
Models/EventTypesListSortFilterProxyModel.cpp
Models/RepeatedSortFilterProxyModel.cpp
Components/Utility.cpp
Components/RecentFiles.cpp
Components/QMenuView.cpp
Components/ArtManager.cpp
Editors/PathEditor.cpp
Editors/RoomEditor.cpp
Editors/ObjectEditor.cpp
Editors/FontEditor.cpp
Editors/SpriteEditor.cpp
Editors/BackgroundEditor.cpp
Editors/SettingsEditor.cpp
Editors/ShaderEditor.cpp
Editors/SoundEditor.cpp
Editors/IncludeEditor.cpp
Editors/BaseEditor.cpp
Editors/ScriptEditor.cpp
Editors/CodeEditor.cpp
Editors/TimelineEditor.cpp
main.cpp
Plugins/RGMPlugin.cpp
Plugins/ServerPlugin.cpp
Dialogs/EventArgumentsDialog.cpp
Dialogs/TimelineChangeMoment.cpp
Dialogs/PreferencesDialog.cpp
Utils/ProtoManip.cpp
Utils/FieldPath.cpp
MainWindow.cpp
Widgets/BackgroundView.cpp
Widgets/ColorPicker.cpp
Widgets/AssetView.cpp
Widgets/PathView.cpp
Widgets/RoomView.cpp
Widgets/SpriteView.cpp
Widgets/CodeWidget.cpp
Widgets/SpriteSubimageListView.cpp
Widgets/StackedCodeWidget.cpp
Widgets/AssetScrollAreaBackground.cpp
)

set(RGM_HEADERS
Plugins/RGMPlugin.h
MainWindow.h
main.h
Dialogs/EventArgumentsDialog.h
Dialogs/PreferencesDialog.h
Dialogs/PreferencesKeys.h
Dialogs/TimelineChangeMoment.h
Components/Logger.h
Components/RecentFiles.h
Components/QMenuView.h
Components/ArtManager.h
Components/QMenuView_p.h
Components/Utility.h
Models/TreeModel.h
Models/RepeatedStringModel.h
Models/ResourceModelMap.h
Models/ModelMapper.h
Models/TreeSortFilterProxyModel.h
Models/RepeatedImageModel.h
Models/MessageModel.h
Models/ImmediateMapper.h
Models/RepeatedMessageModel.h
Models/ProtoModel.h
Models/RepeatedModel.h
Models/EventsListModel.h
Models/EventTypesListModel.h
Models/EventTypesListSortFilterProxyModel.h
Editors/FontEditor.h
Editors/PathEditor.h
Editors/SpriteEditor.h
Editors/SettingsEditor.h
Editors/SoundEditor.h
Editors/TimelineEditor.h
Editors/BackgroundEditor.h
Editors/ObjectEditor.h
Editors/RoomEditor.h
Editors/BaseEditor.h
Editors/ScriptEditor.h
Editors/CodeEditor.h
Editors/ShaderEditor.h
Editors/IncludeEditor.h
Widgets/AssetScrollArea.h
Widgets/StackedCodeWidget.h
Widgets/AssetScrollAreaBackground.h
Widgets/PathView.h
Widgets/ResourceSelector.h
Widgets/RoomView.h
Widgets/AssetView.h
Widgets/ColorPicker.h
Widgets/SpriteSubimageListView.h
Widgets/CodeWidget.h
Widgets/SpriteView.h
Widgets/BackgroundView.h

Models/MessageModel.h
Models/ProtoModel.h
Models/TreeModel.h
Models/PrimitiveModel.h
Models/RepeatedMessageModel.h
Models/EventTypesListSortFilterProxyModel.h
Models/ResourceModelMap.h
Models/EventTypesListModel.h
Models/ImmediateMapper.h
Models/RepeatedModel.h
Models/EventsListModel.h
Models/ModelMapper.h
Models/RepeatedSortFilterProxyModel.h
Models/TreeSortFilterProxyModel.h
main.h
Components/RecentFiles.h
Components/QMenuView_p.h
Components/Utility.h
Components/QMenuView.h
Components/Logger.h
Components/ArtManager.h
Editors/ObjectEditor.h
Editors/PathEditor.h
Editors/ScriptEditor.h
Editors/CodeEditor.h
Editors/SoundEditor.h
Editors/IncludeEditor.h
Editors/TimelineEditor.h
Editors/SettingsEditor.h
Editors/ShaderEditor.h
Editors/RoomEditor.h
Editors/BaseEditor.h
Editors/FontEditor.h
Editors/SpriteEditor.h
Editors/BackgroundEditor.h
Plugins/ServerPlugin.h
Plugins/RGMPlugin.h
MainWindow.h
Dialogs/EventArgumentsDialog.h
Dialogs/PreferencesDialog.h
Dialogs/PreferencesKeys.h
Dialogs/TimelineChangeMoment.h
Utils/SafeCasts.h
Utils/ProtoManip.h
Utils/FieldPath.h
Utils/QBoilerplate.h
Widgets/BackgroundView.h
Widgets/CodeWidget.h
Widgets/ResourceSelector.h
Widgets/ColorPicker.h
Widgets/AssetScrollArea.h
Widgets/SpriteView.h
Widgets/AssetView.h
Widgets/PathView.h
Widgets/StackedCodeWidget.h
Widgets/SpriteSubimageListView.h
Widgets/AssetScrollAreaBackground.h
Widgets/RoomView.h
)

set(RGM_UI
Expand Down
5 changes: 4 additions & 1 deletion Components/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class LogAndReturn {

template <typename T>
LogAndReturn& operator<<(T t) {
logger << t;
if constexpr(std::is_same<T, std::string>::value)
logger << QString::fromStdString(t);
else
logger << t;
return *this;
}
struct Void {
Expand Down
2 changes: 1 addition & 1 deletion Components/QMenuView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ QMenuView::QMenuView(QWidget * parent) : QMenu(parent), d(new QMenuViewPrivate(t
//! Destroy the menu.
QMenuView::~QMenuView()
{
setModel(0);
QMenuView::setModel(0);
}

/*!
Expand Down
4 changes: 2 additions & 2 deletions Components/QMenuView.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class COMPONENTSEXPORT QMenuView : public QMenu
virtual void postPopulated();
void createMenu(const QModelIndex &parent, QMenu *parentMenu = 0, QMenu *menu = 0);
signals:
void hovered(const QString &text) const;
void triggered(const QModelIndex & index) const;
void hovered(const QString &text);
void triggered(const QModelIndex & index);
private:
QScopedPointer<QMenuViewPrivate> d;
friend class QMenuViewPrivate;
Expand Down
2 changes: 1 addition & 1 deletion Components/RecentFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void RecentFiles::updateActions() {
const QString fileName = QFileInfo(recentFiles.at(i)).fileName();
QString numberString = QString::number(i + 1);
numberString = numberString.insert(numberString.length() - 1, '&');
QString text = tr("%1 %2").arg(numberString).arg(fileName);
QString text = tr("%1 %2").arg(numberString, fileName);
recentFileActs[i]->setText(text);
recentFileActs[i]->setData(recentFiles.at(i));
recentFileActs[i]->setVisible(true);
Expand Down
13 changes: 7 additions & 6 deletions Dialogs/EventArgumentsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ EventArgumentsDialog::EventArgumentsDialog(QWidget *parent, const QStringList &a

QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setReadOnly(true);
QModelIndex firstObjIdx = treeProxy
->match(treeProxy->index(0, 0), TreeModel::UserRoles::TypeCaseRole,
TypeCase::kObject, 1, Qt::MatchRecursive)
.first();
auto object_message_name = QString::fromStdString(buffers::resources::Object::descriptor()->full_name());
auto search = treeProxy->match(treeProxy->index(0, 0), TreeModel::UserRoles::MessageTypeRole, object_message_name,
1, Qt::MatchRecursive);
QModelIndex firstObjIdx = search.first();

QString firstObj = firstObjIdx.data(Qt::DisplayRole).toString();
objButton->setIcon(firstObjIdx.data(Qt::DecorationRole).value<QIcon>());
lineEdit->setText(firstObj);
Expand All @@ -69,7 +70,7 @@ EventArgumentsDialog::EventArgumentsDialog(QWidget *parent, const QStringList &a
} else {
QComboBox *combo = new QComboBox(this);
auto argList = MainWindow::GetEventData()->value_names_for_type(name->text().toStdString());
for (auto a : argList) {
for (auto& a : argList) {
combo->addItem(QString::fromStdString(a.first));
}
value = combo;
Expand All @@ -93,7 +94,7 @@ EventArgumentsDialog::EventArgumentsDialog(QWidget *parent, const QStringList &a
const QStringList &EventArgumentsDialog::GetArguments() const { return arguments_; }

void EventArgumentsDialog::done(int r) {
for (const QWidget *w : widgets_) {
for (const QWidget *w : qAsConst(widgets_)) {
QVariant argument = w->metaObject()->userProperty().read(w);
QString argstr = "";
if (argument.isValid())
Expand Down
11 changes: 6 additions & 5 deletions Editors/BackgroundEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BackgroundEditor::BackgroundEditor(MessageModel* model, QWidget* parent)
_resMapper->addMapping(_ui->verticalSpacingSpinBox, Background::kVerticalSpacingFieldNumber);
_resMapper->toFirst();

RebindSubModels();
BackgroundEditor::RebindSubModels();
}

BackgroundEditor::~BackgroundEditor() { delete _ui; }
Expand Down Expand Up @@ -75,7 +75,7 @@ void BackgroundEditor::on_actionLoadImage_triggered() {
FileDialog* dialog = new FileDialog(this, FileDialog_t::BackgroundLoad, false);

if (dialog->exec() && dialog->selectedFiles().size() > 0) {
QString fName = dialog->selectedFiles()[0];
QString fName = dialog->selectedFiles().at(0);
if (fName.endsWith("Background.gmx") || fName.endsWith(".bkg")) {
std::optional<Background> bkg = egm::LoadResource<Background>(fName.toStdString());
if (bkg.has_value()) {
Expand All @@ -89,7 +89,8 @@ void BackgroundEditor::on_actionLoadImage_triggered() {
}
} else {
// TODO: Copy data into our egm
_backgroundModel->SetData(fName, Background::kImageFieldNumber);
_backgroundModel->SetData(FieldPath::Of<Background>(Background::kImageFieldNumber), fName);
_ui->backgroundView->SetImage(fName);
}
}
}
Expand All @@ -98,13 +99,13 @@ void BackgroundEditor::on_actionSaveImage_triggered() {
FileDialog* dialog = new FileDialog(this, FileDialog_t::BackgroundSave, true);

if (dialog->exec() && dialog->selectedFiles().size() > 0) {
QString fName = dialog->selectedFiles()[0];
QString fName = dialog->selectedFiles().at(0);
_ui->backgroundView->WriteImage(fName, dialog->selectedMimeTypeFilter());
}
}

void BackgroundEditor::on_actionEditImage_triggered() {
QString fName = _backgroundModel->Data(Background::kImageFieldNumber).toString();
QString fName = _backgroundModel->Data(FieldPath::Of<Background>(Background::kImageFieldNumber)).toString();
QDesktopServices::openUrl(QUrl::fromLocalFile(fName));
// TODO: file watcher reload
// TODO: editor settings
Expand Down

0 comments on commit 7b5ef37

Please sign in to comment.