#pragma once #include "config.h" #include // interface class ButtonManagerItem : public QTreeWidgetItem { protected: ButtonManagerItem(QTreeWidgetItem* parent, int type, uint8_t pos); public: virtual ~ButtonManagerItem(); virtual bool hasEdit() const; virtual bool hasRemove() const; virtual bool hasMoveUp() const; virtual bool hasMoveDown() const; virtual void edit(); virtual void remove(); virtual void moveUp(); virtual void moveDown(); template T* getParent() const; template T* getChild(int index) const; template T* getLastChild() const; template T* getSibling(int index) const; template T* getItemAbove() const; template T* getItemBelow() const; void reenumerateAllSiblings(); void expandTree(); // expand this and every parent item protected: QTreeWidgetItem* mparent = nullptr; uint8_t pos = 0; void updateAllPosBellow(int8_t diff, uint8_t size); virtual void updatePosition(); }; class RowItem : public ButtonManagerItem { public: RowItem(QTreeWidgetItem* parent, uint8_t rownr, Config::RootConfig& conf); const static int TYPE = 1000; virtual bool hasRemove() const override; virtual bool hasMoveUp() const override; virtual bool hasMoveDown() const override; virtual void remove() override; virtual void moveUp() override; virtual void moveDown() override; uint8_t getRow() const; // returns the number of this row std::vector& getConfig(); private: Config::RootConfig& conf; //called when the row was moved void updatePosition() override; }; class ButtonItem : public ButtonManagerItem { public: ButtonItem(RowItem* parent, uint8_t buttonnr, Config::RootConfig& conf); const static int TYPE = 1001; virtual bool hasEdit() const override; virtual bool hasRemove() const override; virtual bool hasMoveUp() const override; virtual bool hasMoveDown() const override; virtual void edit() override; virtual void remove() override; virtual void moveUp() override; virtual void moveDown() override; // triggered from the view when the name was changed void nameWasChanged(); void keyWasChanged(); Config::ButtonConfig& getConfig(); private: Config::RootConfig& conf; void moveToRowAbove(); void moveToRowBelow(); }; class SampleItem : public ButtonManagerItem { public: SampleItem(ButtonItem* parent, uint8_t samplenr, Config::RootConfig& conf); const static int TYPE = 1002; virtual bool hasEdit() const override; virtual bool hasRemove() const override; virtual bool hasMoveUp() const override; virtual bool hasMoveDown() const override; virtual void edit() override; virtual void remove() override; virtual void moveUp() override; virtual void moveDown() override; Config::SampleConfig& getConfig(); private: Config::RootConfig& conf; //called when a sample was moved void updatePosition() override; void moveToButtonAbove(); void moveToButtonBelow(); };