File indexing completed on 2024-05-12 04:39:44

0001 /*
0002     SPDX-FileCopyrightText: 2013 Vlas Puhov <vlas.puhov@mail.ru>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef REGISTERSVIEW_H
0008 #define REGISTERSVIEW_H
0009 
0010 #include "ui_registersview.h"
0011 
0012 #include <QVector>
0013 
0014 class QMenu;
0015 
0016 namespace KDevMI {
0017 
0018 class ModelsManager;
0019 
0020 /** @brief Class for displaying registers content */
0021 class RegistersView : public QWidget, private Ui::RegistersView
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     explicit RegistersView(QWidget* p = nullptr);
0027 
0028     void enable(bool enabled);
0029 
0030     void setModel(ModelsManager* m);
0031 
0032 public Q_SLOTS:
0033     ///Updates registers for active views.
0034     void updateRegisters();
0035 
0036 protected:
0037     ///Allows to choose register formats/modes.
0038     void contextMenuEvent(QContextMenuEvent* e) override;
0039 
0040 private:
0041     ///Returns list of active views.
0042     QStringList activeViews();
0043 
0044     ///Adds @p v to the list of views with assigning it a name.
0045     void addView(QTableView* view, int idx);
0046 
0047     ///Clears names of all views.
0048     void clear();
0049 
0050     ///Sets name for the table with index @p idx to the @p name.
0051     void setNameForTable(int idx, const QString& name);
0052 
0053 private Q_SLOTS:
0054     ///Changes register formats/modes to @p formatOrMode.
0055     void menuTriggered(const QString& formatOrMode);
0056 
0057 private:
0058     void setupActions();
0059     ///Adds new action into m_actions and to this widget's list of actions.
0060     void insertAction(const QString& name, Qt::Key k);
0061     ///Returns action for given @p name.
0062     QAction* findAction(const QString& name) const;
0063 private Q_SLOTS:
0064     ///Enables/disables actions based on current view.
0065     void changeAvaliableActions();
0066 
0067 private:
0068     QMenu* m_menu;
0069 
0070     ModelsManager* m_modelsManager = nullptr;
0071 
0072     QVector<QAction*> m_actions;
0073 };
0074 
0075 } // end of namespace KDevMI
0076 
0077 #endif