#ifndef MODULE_H #define MODULE_H #include "AbstractCommand.h" #include #include #include #include #include #include class QAction; namespace Leon { class Module; class ModuleRegistry { public: using ModuleContainer = std::unordered_set; using Iterator = ModuleContainer::iterator; Iterator begin() { return modules.begin(); } Iterator end() { return modules.end(); } void registerModule(Module *module); private: ModuleContainer modules; }; ModuleRegistry& GetModuleRegistry(); template class Command: public AbstractCommand { public: Command(QString caption, QString iconpath, Func f); Command& setHint(QString hint); Command& setDescription(QString description); Command& setShortCut(QKeySequence shortcut); Command& addOnToolbar(QString toolbar, QString group); Command& setMenuPath(QString menu); // action = new QAction(QIcon(":/icons/script_save.png"), tr("Save SQL"), this); // action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); // connect(action, &QAction::triggered, this, &QueryTab::save); // actions.push_back(action); private: mutable QAction *action = nullptr; }; /// Abstract interface for retrieving information about a subsystem /// /// Each module should derive a class From ModuleInstance and implement /// the abstract methods declared in this interface. Don't do to much in your constructor /// as it might be called very early in the startup of the program class Module { public: using AbstractCommandSptr = std::shared_ptr; using CommandContainer = std::vector; Module(); // getGlobalActions virtual QString getName() const = 0; virtual CommandContainer getCommands() const = 0; }; /// Adds auto registration to Module so not each /// module has to implement registration class ModuleInstance: public Module { protected: ModuleInstance(); }; class Path { public: explicit Path(QString p) { int ofs = 0; if (p.isEmpty()) return; if (p[0] == '/') ++ofs; while (true) { int i = p.indexOf('/', ofs); if (i >= ofs) { path.push_back(p.mid(ofs, i - ofs)); ofs = i+1; } else { path.push_back(p.right(ofs)); break; } } } int getDepth() const { return path.size(); } QString getElem(int i) const { return path.at(i); } private: using PathContainer = boost::container::small_vector; PathContainer path; }; } #endif // MODULE_H