diff options
Diffstat (limited to 'core')
27 files changed, 462 insertions, 21 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c4751a5..040eaac 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -41,9 +41,9 @@ add_source_group(MODEL_MODULE_SOURCES ) add_source_group(MODEL_TEMPLATE_SOURCES + src/Model/Template/TableTemplate.cpp src/Model/Template/Template_Main.cpp src/Model/Template/Template_RTTI.cpp - src/Model/Template/TableTemplate.cpp ) add_source_group(MODEL_WORKFLOW_MODULE_SOURCES @@ -62,7 +62,8 @@ add_source_group(MODEL_WORKFLOW_NODES_MODULE_SOURCES ) add_source_group(MODEL_WORKFLOW_VALUES_MODULE_SOURCES - src/Model/Workflow/Values/BasicValues.cpp + src/Model/Workflow/Values/Basic.cpp + src/Model/Workflow/Values/Database.cpp ) set(UI_MODULE_SOURCES diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp index b8444b7..28a4d6e 100644 --- a/core/src/Model/Template/TableTemplate.cpp +++ b/core/src/Model/Template/TableTemplate.cpp @@ -58,6 +58,16 @@ const TableTemplate& TableInstanciationParameters::GetTable() const return *mTable; } +bool TableTemplate::IsInstance(const Template* tmpl) +{ + return tmpl->GetKind() == KD_Table; +} + +TableTemplate::TableTemplate() + : Template(KD_Table) +{ +} + int TableTemplate::GetTableWidth() const { return mColumnWidths.size(); diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp index f7a79e9..ed1a96f 100644 --- a/core/src/Model/Template/TableTemplate.hpp +++ b/core/src/Model/Template/TableTemplate.hpp @@ -137,6 +137,9 @@ private: std::vector<int> mColumnWidths; public: + static bool IsInstance(const Template* tmpl); + TableTemplate(); + int GetTableWidth() const; int GetTableHeight() const; void Resize(int newWidth, int newHeight); diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp index f7dd898..131a6ac 100644 --- a/core/src/Model/Template/Template.hpp +++ b/core/src/Model/Template/Template.hpp @@ -18,12 +18,20 @@ public: KindCount = InvalidKind, }; +private: + Kind mKind; + public: static const char* FormatKind(Kind kind); static std::unique_ptr<Template> CreateByKind(Kind kind); + static bool IsInstance(const Template* tmpl); + + Template(Kind kind); virtual ~Template() = default; + Kind GetKind() const; + enum class ReadResult { RR_Success, diff --git a/core/src/Model/Template/Template_Main.cpp b/core/src/Model/Template/Template_Main.cpp index 08437b7..35da52b 100644 --- a/core/src/Model/Template/Template_Main.cpp +++ b/core/src/Model/Template/Template_Main.cpp @@ -1,5 +1,15 @@ #include "Template.hpp" +Template::Template(Kind kind) + : mKind{ kind } +{ +} + +Template::Kind Template::GetKind() const +{ + return mKind; +} + std::unique_ptr<Template> TemplateInfo::LoadFromDisk() const { // TODO diff --git a/core/src/Model/Template/Template_RTTI.cpp b/core/src/Model/Template/Template_RTTI.cpp index 042aaec..1475e02 100644 --- a/core/src/Model/Template/Template_RTTI.cpp +++ b/core/src/Model/Template/Template_RTTI.cpp @@ -2,20 +2,27 @@ #include "Model/Template/TableTemplate.hpp" -inline const char* Template::FormatKind(Kind kind) +const char* Template::FormatKind(Kind kind) { switch (kind) { case KD_Table: return "Table template"; - case InvalidKind: return "<invalid kind>"; + case InvalidKind: break; } + return "<invalid kind>"; } -inline std::unique_ptr<Template> Template::CreateByKind(Kind kind) +std::unique_ptr<Template> Template::CreateByKind(Kind kind) { switch (kind) { case KD_Table: return std::make_unique<TableTemplate>(); - case InvalidKind: return nullptr; + case InvalidKind: break; } + return nullptr; +} + +bool Template::IsInstance(const Template* tmpl) +{ + return true; } diff --git a/core/src/Model/TransactionsModel.hpp b/core/src/Model/TransactionsModel.hpp index cd19241..c9b33f1 100644 --- a/core/src/Model/TransactionsModel.hpp +++ b/core/src/Model/TransactionsModel.hpp @@ -6,6 +6,16 @@ #include <SQLiteCpp/Statement.h> #include <cstdint> +enum class TableKind +{ + Sales, + SalesItems, + Purchases, + PurchasesItems, + Deliveries, + DeliveriesItems, +}; + class SalesTable { public: diff --git a/core/src/Model/Workflow/Nodes/DocumentNodes.cpp b/core/src/Model/Workflow/Nodes/DocumentNodes.cpp index 3925dec..6729c63 100644 --- a/core/src/Model/Workflow/Nodes/DocumentNodes.cpp +++ b/core/src/Model/Workflow/Nodes/DocumentNodes.cpp @@ -1,7 +1,7 @@ #include "DocumentNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" bool DocumentTemplateExpansionNode::IsInstance(const WorkflowNode* node) { diff --git a/core/src/Model/Workflow/Nodes/NumericNodes.cpp b/core/src/Model/Workflow/Nodes/NumericNodes.cpp index ad51fb4..f0d28b1 100644 --- a/core/src/Model/Workflow/Nodes/NumericNodes.cpp +++ b/core/src/Model/Workflow/Nodes/NumericNodes.cpp @@ -1,7 +1,7 @@ #include "NumericNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" #include "Utils/Macros.hpp" #include "Utils/RTTI.hpp" diff --git a/core/src/Model/Workflow/Nodes/TextNodes.cpp b/core/src/Model/Workflow/Nodes/TextNodes.cpp index e67b033..4628dd3 100644 --- a/core/src/Model/Workflow/Nodes/TextNodes.cpp +++ b/core/src/Model/Workflow/Nodes/TextNodes.cpp @@ -1,7 +1,7 @@ #include "TextNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" #include "Utils/Macros.hpp" #include "Utils/RTTI.hpp" #include "Utils/Variant.hpp" diff --git a/core/src/Model/Workflow/Nodes/UserInputNodes.cpp b/core/src/Model/Workflow/Nodes/UserInputNodes.cpp index f8d3e01..0b6d471 100644 --- a/core/src/Model/Workflow/Nodes/UserInputNodes.cpp +++ b/core/src/Model/Workflow/Nodes/UserInputNodes.cpp @@ -1,7 +1,7 @@ #include "UserInputNodes.hpp" #include "Model/Workflow/Evaluation.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" bool FormInputNode::IsInstance(const WorkflowNode* node) { diff --git a/core/src/Model/Workflow/Value.hpp b/core/src/Model/Workflow/Value.hpp index 8b3e63a..ff62d43 100644 --- a/core/src/Model/Workflow/Value.hpp +++ b/core/src/Model/Workflow/Value.hpp @@ -5,6 +5,7 @@ #include <iosfwd> #include <memory> +#include <string> class BaseValue { @@ -14,6 +15,12 @@ public: KD_Numeric, KD_Text, KD_DateTime, + KD_DatabaseRowId, + + KD_BaseObject, + KD_SaleDatabaseRow, + KD_PurchaseDatabaseRow, + KD_BaseObjectLast = KD_PurchaseDatabaseRow, /// An unspecified type, otherwise known as "any" in some contexts. InvalidKind, @@ -34,6 +41,8 @@ public: static const char* Format(Kind kind); static std::unique_ptr<BaseValue> CreateByKind(Kind kind); + static bool IsInstance(const BaseValue* value); + BaseValue(Kind kind); virtual ~BaseValue() = default; @@ -51,3 +60,32 @@ public: virtual void ReadFrom(std::istream& stream); virtual void WriteTo(std::ostream& stream); }; + +class BaseObjectDescription +{ +public: + struct Property + { + std::string Name; + BaseValue::Kind Kind; + bool Mutatable = true; + }; + +public: + std::vector<Property> Properties; +}; + +class BaseObjectValue : public BaseValue +{ +public: + /// \param kind A value kind enum, within the range of KD_BaseObject and KD_BaseObjectLast (both inclusive). + static const BaseObjectDescription& QueryObjectInfo(Kind kind); + + static bool IsInstance(const BaseValue* value); + BaseObjectValue(Kind kind); + + const BaseObjectDescription& GetObjectDescription() const; + + virtual const BaseValue* GetProperty(int idx) const = 0; + virtual bool SetProperty(int idx, std::unique_ptr<BaseValue> value) = 0; +}; diff --git a/core/src/Model/Workflow/ValueInternals.hpp b/core/src/Model/Workflow/ValueInternals.hpp new file mode 100644 index 0000000..49981f0 --- /dev/null +++ b/core/src/Model/Workflow/ValueInternals.hpp @@ -0,0 +1,21 @@ +// This file contains utility classes and macros for implementing values +// As consumers, you should not include this header as it contains unnecessary symbols and can pollute your files +// for this reason, classes here aren't forward-declared in fwd.hpp either. + +#pragma once + +#include "Utils/RTTI.hpp" + +#include <utility> + +#define CHECK_VALUE_TYPE(Type, value) \ + if (!is_a<Type>(value)) { \ + return false; \ + } + +#define CHECK_VALUE_TYPE_AND_MOVE(Type, dest, value) \ + if (auto ptr = dyn_cast<Type>(value)) { \ + dest = std::move(*ptr); \ + } else { \ + return false; \ + } diff --git a/core/src/Model/Workflow/Value_Main.cpp b/core/src/Model/Workflow/Value_Main.cpp index fdd2fd5..ca972c4 100644 --- a/core/src/Model/Workflow/Value_Main.cpp +++ b/core/src/Model/Workflow/Value_Main.cpp @@ -22,3 +22,14 @@ void BaseValue::ReadFrom(std::istream& stream) void BaseValue::WriteTo(std::ostream& stream) { } + +BaseObjectValue::BaseObjectValue(Kind kind) + : BaseValue(kind) +{ + assert(kind >= KD_BaseObject && kind <= KD_BaseObjectLast); +} + +const BaseObjectDescription& BaseObjectValue::GetObjectDescription() const +{ + return QueryObjectInfo(this->GetKind()); +} diff --git a/core/src/Model/Workflow/Value_RTTI.cpp b/core/src/Model/Workflow/Value_RTTI.cpp index 5e24ed7..44b047c 100644 --- a/core/src/Model/Workflow/Value_RTTI.cpp +++ b/core/src/Model/Workflow/Value_RTTI.cpp @@ -1,6 +1,7 @@ #include "Value.hpp" -#include "Model/Workflow/Values/BasicValues.hpp" +#include "Model/Workflow/Values/Basic.hpp" +#include "Model/Workflow/Values/Database.hpp" #include "UI/UI.hpp" constexpr BaseValue::KindInfo kNumericInfo{ @@ -13,19 +14,42 @@ constexpr BaseValue::KindInfo kTextInfo{ .PinColor = RgbaColor(124, 21, 153), }; -constexpr BaseValue::KindInfo kDateTimeInfo{ - .PinIcon = ImGui::IconType::Diamond, +constexpr BaseValue::KindInfo kDateTimeInfo{ + .PinIcon = ImGui::IconType::Circle, .PinColor = RgbaColor(147, 226, 74), }; +constexpr BaseValue::KindInfo kDatabaseRowIdInfo{ + .PinIcon = ImGui::IconType::Circle, + .PinColor = RgbaColor(216, 42, 221), +}; + +constexpr BaseValue::KindInfo kDatabaseRowInfo{ + .PinIcon = ImGui::IconType::Square, + .PinColor = RgbaColor(15, 124, 196), +}; + +constexpr BaseValue::KindInfo kObjectinfo{ + .PinIcon = ImGui::IconType::Square, + .PinColor = RgbaColor(161, 161, 161), +}; + const BaseValue::KindInfo& BaseValue::QueryInfo(BaseValue::Kind kind) { switch (kind) { case KD_Numeric: return kNumericInfo; - case KD_Text: break; - case KD_DateTime: break; + case KD_Text: return kTextInfo; + case KD_DateTime: return kDateTimeInfo; + case KD_DatabaseRowId: return kDatabaseRowIdInfo; + + case KD_BaseObject: return kObjectinfo; + case KD_SaleDatabaseRow: + case KD_PurchaseDatabaseRow: + return kDatabaseRowInfo; + case InvalidKind: break; } + // TODO provide info here } const char* BaseValue::Format(Kind kind) @@ -34,8 +58,15 @@ const char* BaseValue::Format(Kind kind) case KD_Numeric: return "Numeric"; case KD_Text: return "Text"; case KD_DateTime: return "Date/time"; - case InvalidKind: return "<invalid kind>"; + case KD_DatabaseRowId: return "Row id"; + + case KD_BaseObject: return "Object"; + case KD_SaleDatabaseRow: return "Sale record"; + case KD_PurchaseDatabaseRow: return "Purchase record"; + + case InvalidKind: break; } + return "<invalid kind>"; } std::unique_ptr<BaseValue> BaseValue::CreateByKind(BaseValue::Kind kind) @@ -44,6 +75,76 @@ std::unique_ptr<BaseValue> BaseValue::CreateByKind(BaseValue::Kind kind) case KD_Numeric: return std::make_unique<NumericValue>(); case KD_Text: return std::make_unique<TextValue>(); case KD_DateTime: return std::make_unique<DateTimeValue>(); - case InvalidKind: return nullptr; + case KD_DatabaseRowId: return std::make_unique<DatabaseRowIdValue>(); + + case KD_BaseObject: return nullptr; + case KD_SaleDatabaseRow: return std::make_unique<SaleDatabaseRowValue>(); + case KD_PurchaseDatabaseRow: return std::make_unique<PurchaseDatabaseRowValue>(); + + case InvalidKind: break; + } + return nullptr; +} + +bool BaseValue::IsInstance(const BaseValue* value) +{ + return true; +} + +const BaseObjectDescription kEmptyObjectInfo{ + .Properties = {}, +}; + +const BaseObjectDescription kSaleDbRowObject{ + .Properties = { + { + .Name = "Customer", + .Kind = BaseValue::KD_Text, + .Mutatable = false, + }, + { + .Name = "Deadline", + .Kind = BaseValue::KD_DateTime, + }, + { + .Name = "Completion time", + .Kind = BaseValue::KD_DateTime, + }, + }, +}; + +const BaseObjectDescription kPurchaseDbRowObject{ + .Properties = { + { + .Name = "Factory", + .Kind = BaseValue::KD_Text, + .Mutatable = false, + }, + { + .Name = "Order time", + .Kind = BaseValue::KD_DateTime, + }, + { + .Name = "Arrival time", + .Kind = BaseValue::KD_DateTime, + }, + }, +}; + +const BaseObjectDescription& BaseObjectValue::QueryObjectInfo(Kind kind) +{ + switch (kind) { + case KD_BaseObject: return kEmptyObjectInfo; + case KD_SaleDatabaseRow: return kSaleDbRowObject; + case KD_PurchaseDatabaseRow: return kPurchaseDbRowObject; + + default: break; } + return kEmptyObjectInfo; +} + +bool BaseObjectValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() >= KD_BaseObject && + value->GetKind() <= KD_BaseObjectLast; } diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/Basic.cpp index 748c652..d6a2395 100644 --- a/core/src/Model/Workflow/Values/BasicValues.cpp +++ b/core/src/Model/Workflow/Values/Basic.cpp @@ -1,4 +1,4 @@ -#include "BasicValues.hpp" +#include "Basic.hpp" #include <charconv> #include <cmath> diff --git a/core/src/Model/Workflow/Values/BasicValues.hpp b/core/src/Model/Workflow/Values/Basic.hpp index 795876e..38e0531 100644 --- a/core/src/Model/Workflow/Values/BasicValues.hpp +++ b/core/src/Model/Workflow/Values/Basic.hpp @@ -15,6 +15,11 @@ public: static bool IsInstance(const BaseValue* value); NumericValue(); + NumericValue(const NumericValue&) = delete; + NumericValue& operator=(const NumericValue&) = delete; + NumericValue(NumericValue&&) = default; + NumericValue& operator=(NumericValue&&) = default; + std::string GetTruncatedString() const; std::string GetRoundedString() const; std::string GetString() const; @@ -33,6 +38,11 @@ public: static bool IsInstance(const BaseValue* value); TextValue(); + TextValue(const TextValue&) = delete; + TextValue& operator=(const TextValue&) = delete; + TextValue(TextValue&&) = default; + TextValue& operator=(TextValue&&) = default; + const std::string& GetValue() const; void SetValue(const std::string& value); }; @@ -46,6 +56,11 @@ public: static bool IsInstance(const BaseValue* value); DateTimeValue(); + DateTimeValue(const DateTimeValue&) = delete; + DateTimeValue& operator=(const DateTimeValue&) = delete; + DateTimeValue(DateTimeValue&&) = default; + DateTimeValue& operator=(DateTimeValue&&) = default; + std::string GetString() const; const std::chrono::time_point<std::chrono::system_clock>& GetValue() const; void SetValue(const std::chrono::time_point<std::chrono::system_clock>& value); diff --git a/core/src/Model/Workflow/Values/Database.cpp b/core/src/Model/Workflow/Values/Database.cpp new file mode 100644 index 0000000..12d2b80 --- /dev/null +++ b/core/src/Model/Workflow/Values/Database.cpp @@ -0,0 +1,88 @@ +#include "Database.hpp" + +#include "Model/TransactionsModel.hpp" +#include "Model/Workflow/ValueInternals.hpp" + +#include <limits> + +TableKind DatabaseRowIdValue::GetTable() const +{ + return mTable; +} + +int64_t DatabaseRowIdValue::GetRowId() const +{ + return mRowId; +} + +bool DatabaseRowIdValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_DatabaseRowId; +} + +DatabaseRowIdValue::DatabaseRowIdValue() + : BaseValue(KD_DatabaseRowId) + , mTable{ TableKind::Sales } + , mRowId{ std::numeric_limits<int64_t>::max() } +{ +} + +bool SaleDatabaseRowValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_SaleDatabaseRow; +} + +SaleDatabaseRowValue::SaleDatabaseRowValue() + : BaseObjectValue(KD_SaleDatabaseRow) +{ +} + +const BaseValue* SaleDatabaseRowValue::GetProperty(int idx) const +{ + switch (idx) { + case 0: return &mCustomerName; + case 1: return &mDeadline; + case 2: return &mDeliveryTime; + default: return nullptr; + } +} + +bool SaleDatabaseRowValue::SetProperty(int idx, std::unique_ptr<BaseValue> value) +{ + switch (idx) { + case 0: return false; + case 1: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mDeadline, value.get()); break; + case 2: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mDeliveryTime, value.get()); break; + } + return true; +} + +bool PurchaseDatabaseRowValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_PurchaseDatabaseRow; +} + +PurchaseDatabaseRowValue::PurchaseDatabaseRowValue() + : BaseObjectValue(KD_PurchaseDatabaseRow) +{ +} + +const BaseValue* PurchaseDatabaseRowValue::GetProperty(int idx) const +{ + switch (idx) { + case 0: return &mFactoryName; + case 1: return &mOrderTime; + case 2: return &mDeliveryTime; + default: return nullptr; + } +} + +bool PurchaseDatabaseRowValue::SetProperty(int idx, std::unique_ptr<BaseValue> value) +{ + switch (idx) { + case 0: return false; + case 1: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mOrderTime, value.get()); break; + case 2: CHECK_VALUE_TYPE_AND_MOVE(DateTimeValue, mDeliveryTime, value.get()); break; + } + return true; +} diff --git a/core/src/Model/Workflow/Values/Database.hpp b/core/src/Model/Workflow/Values/Database.hpp new file mode 100644 index 0000000..e8a4f83 --- /dev/null +++ b/core/src/Model/Workflow/Values/Database.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "Model/Workflow/Value.hpp" +#include "Model/Workflow/Values/Basic.hpp" +#include "cplt_fwd.hpp" + +class DatabaseRowIdValue : public BaseValue +{ +private: + TableKind mTable; + int64_t mRowId; + +public: + static bool IsInstance(const BaseValue* value); + DatabaseRowIdValue(); + + TableKind GetTable() const; + int64_t GetRowId() const; +}; + +class SaleDatabaseRowValue : public BaseObjectValue +{ +private: + int mCustomerId; + TextValue mCustomerName; + DateTimeValue mDeadline; + DateTimeValue mDeliveryTime; + +public: + static bool IsInstance(const BaseValue* value); + SaleDatabaseRowValue(); + + virtual const BaseValue* GetProperty(int idx) const; + virtual bool SetProperty(int idx, std::unique_ptr<BaseValue> value); +}; + +class PurchaseDatabaseRowValue : public BaseObjectValue +{ +private: + int mFactoryId; + TextValue mFactoryName; + DateTimeValue mOrderTime; + DateTimeValue mDeliveryTime; + +public: + static bool IsInstance(const BaseValue* value); + PurchaseDatabaseRowValue(); + + virtual const BaseValue* GetProperty(int idx) const; + virtual bool SetProperty(int idx, std::unique_ptr<BaseValue> value); +}; diff --git a/core/src/Model/Workflow/Values/fwd.hpp b/core/src/Model/Workflow/Values/fwd.hpp index 24f8119..de26226 100644 --- a/core/src/Model/Workflow/Values/fwd.hpp +++ b/core/src/Model/Workflow/Values/fwd.hpp @@ -1,6 +1,14 @@ #pragma once -// BasicValues.hpp +// Basic.hpp class NumericValue; class TextValue; class DateTimeValue; + +// Database.hpp +class DatabaseRowIdValue; +class SaleDatabaseRowValue; +class PurchaseDatabaseRowValue; + +// List.hpp +class ListValue; diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp index 161400e..c57ac31 100644 --- a/core/src/Model/Workflow/Workflow.hpp +++ b/core/src/Model/Workflow/Workflow.hpp @@ -111,6 +111,8 @@ public: static const char* FormatType(Type type); static std::unique_ptr<WorkflowNode> CreateByKind(Kind kind); + static bool IsInstance(const WorkflowNode* node); + WorkflowNode(Kind kind, bool locked); virtual ~WorkflowNode() = default; diff --git a/core/src/Model/Workflow/Workflow_RTTI.cpp b/core/src/Model/Workflow/Workflow_RTTI.cpp index 34347b1..10659d0 100644 --- a/core/src/Model/Workflow/Workflow_RTTI.cpp +++ b/core/src/Model/Workflow/Workflow_RTTI.cpp @@ -21,8 +21,9 @@ const char* WorkflowNode::FormatKind(Kind kind) case KD_FormInput: return "FormInput"; case KD_DatabaseRowsInput: return "DatabaseRowsInput"; - case InvalidKind: return "<invalid kind>"; + case InvalidKind: break; } + return "<invalid kind>"; } const char* WorkflowNode::FormatType(Type type) @@ -32,6 +33,7 @@ const char* WorkflowNode::FormatType(Type type) case TransformType: return "transform"; case OutputType: return "output"; } + return ""; } std::unique_ptr<WorkflowNode> WorkflowNode::CreateByKind(WorkflowNode::Kind kind) @@ -48,6 +50,12 @@ std::unique_ptr<WorkflowNode> WorkflowNode::CreateByKind(WorkflowNode::Kind kind case KD_FormInput: return std::make_unique<FormInputNode>(); case KD_DatabaseRowsInput: return std::make_unique<DatabaseRowsInputNode>(); - case InvalidKind: return nullptr; + case InvalidKind: break; } + return nullptr; +} + +bool WorkflowNode::IsInstance(const WorkflowNode* node) +{ + return true; } diff --git a/core/src/Model/Workflow/fwd.hpp b/core/src/Model/Workflow/fwd.hpp index b541e52..d118fe8 100644 --- a/core/src/Model/Workflow/fwd.hpp +++ b/core/src/Model/Workflow/fwd.hpp @@ -13,6 +13,7 @@ class SavedWorkflow; // Value.hpp class BaseValue; +class BaseObjectValue; // Workflow.hpp class WorkflowConnection; diff --git a/core/src/Model/fwd.hpp b/core/src/Model/fwd.hpp index 09b0c75..8f6fc73 100644 --- a/core/src/Model/fwd.hpp +++ b/core/src/Model/fwd.hpp @@ -24,6 +24,7 @@ class CustomerItem; class Project; // TransactionDatabase.hpp +enum class TableKind; class SalesTable; class PurchasesTable; class DeliveryTable; diff --git a/core/src/UI/UI.hpp b/core/src/UI/UI.hpp index dfce713..0a80b4c 100644 --- a/core/src/UI/UI.hpp +++ b/core/src/UI/UI.hpp @@ -31,6 +31,8 @@ enum class IconType void DrawIcon(ImDrawList* drawList, const ImVec2& a, const ImVec2& b, IconType type, bool filled, ImU32 color, ImU32 innerColor); void Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& color = ImVec4(1, 1, 1, 1), const ImVec4& innerColor = ImVec4(0, 0, 0, 0)); +bool Splitter(bool splitVertically, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterLongAxisSize = -1.0f); + } // namespace ImGui namespace UI { diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp index 082b72a..cf53461 100644 --- a/core/src/UI/UI_Templates.cpp +++ b/core/src/UI/UI_Templates.cpp @@ -29,6 +29,8 @@ class TableTemplateUI : public TemplateUI private: std::unique_ptr<TableTemplate> mTable; + TableCell* mSelectedCell = nullptr; + public: TableTemplateUI(std::unique_ptr<TableTemplate> table) : mTable{ std::move(table) } @@ -51,6 +53,31 @@ public: private: void DrawInspector() { + if (ImGui::BeginTabBar("Inspector")) { + if (ImGui::BeginTabItem("Table")) { + DrawTableInspector(); + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Cell")) { + DrawCellInspector(); + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); + } + } + + void DrawTableInspector() + { + // TODO + } + + void DrawCellInspector() + { + if (mSelectedCell) { + + } else { + ImGui::Text("Select a cell to edit"); + } } void DrawTable() @@ -300,4 +327,8 @@ void UI::TemplatesTab() ImGui::EndPopup(); } + + if (openTemplate) { + openTemplate->Draw(); + } } diff --git a/core/src/UI/UI_Utils.cpp b/core/src/UI/UI_Utils.cpp index d662d2c..e3ac097 100644 --- a/core/src/UI/UI_Utils.cpp +++ b/core/src/UI/UI_Utils.cpp @@ -296,3 +296,17 @@ void ImGui::Icon(const ImVec2& size, IconType type, bool filled, const ImVec4& c ImGui::Dummy(size); } + +bool ImGui::Splitter(bool splitVertically, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterLongAxisSize) +{ + // Taken from https://github.com/thedmd/imgui-node-editor/blob/master/examples/blueprints-example/blueprints-example.cpp + // ::Splitter + + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; + ImGuiID id = window->GetID("##Splitter"); + ImRect bb; + bb.Min = window->DC.CursorPos + (splitVertically ? ImVec2(*size1, 0.0f) : ImVec2(0.0f, *size1)); + bb.Max = bb.Min + CalcItemSize(splitVertically ? ImVec2(thickness, splitterLongAxisSize) : ImVec2(splitterLongAxisSize, thickness), 0.0f, 0.0f); + return SplitterBehavior(bb, id, splitVertically ? ImGuiAxis_X : ImGuiAxis_Y, size1, size2, minSize1, minSize2, 0.0f); +} |