GUI: added lambda support for the AbstractTableView::addAction functions
This commit is contained in:
		
							parent
							
								
									a2082e4586
								
							
						
					
					
						commit
						1ca296e237
					
				| 
						 | 
				
			
			@ -11,6 +11,7 @@
 | 
			
		|||
#include "StringUtil.h"
 | 
			
		||||
#include "Configuration.h"
 | 
			
		||||
#include "MenuBuilder.h"
 | 
			
		||||
#include "QActionLambda.h"
 | 
			
		||||
 | 
			
		||||
//Hacky class that fixes a really annoying cursor problem
 | 
			
		||||
class AbstractTableScrollBar : public QScrollBar
 | 
			
		||||
| 
						 | 
				
			
			@ -225,6 +226,13 @@ private:
 | 
			
		|||
        return action;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* connectAction(QAction* action, QActionLambda::TriggerCallback callback)
 | 
			
		||||
    {
 | 
			
		||||
        auto lambda = new QActionLambda(action->parent(), callback);
 | 
			
		||||
        connect(action, SIGNAL(triggered(bool)), lambda, SLOT(triggeredSlot()));
 | 
			
		||||
        return action;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* connectShortcutAction(QAction* action, const char* shortcut)
 | 
			
		||||
    {
 | 
			
		||||
        actionShortcutPairs.push_back(ActionShortcut(action, shortcut));
 | 
			
		||||
| 
						 | 
				
			
			@ -253,42 +261,50 @@ protected:
 | 
			
		|||
        return menu;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeAction(const QString & text, const char* slot)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeAction(const QString & text, T slot)
 | 
			
		||||
    {
 | 
			
		||||
        return connectAction(new QAction(text, this), slot);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeAction(const QIcon & icon, const QString & text, const char* slot)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeAction(const QIcon & icon, const QString & text, T slot)
 | 
			
		||||
    {
 | 
			
		||||
        return connectAction(new QAction(icon, text, this), slot);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeShortcutAction(const QString & text, const char* slot, const char* shortcut)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeShortcutAction(const QString & text, T slot, const char* shortcut)
 | 
			
		||||
    {
 | 
			
		||||
        return connectShortcutAction(makeAction(text, slot), shortcut);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeShortcutAction(const QIcon & icon, const QString & text, const char* slot, const char* shortcut)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeShortcutAction(const QIcon & icon, const QString & text, T slot, const char* shortcut)
 | 
			
		||||
    {
 | 
			
		||||
        return connectShortcutAction(makeAction(icon, text, slot), shortcut);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeMenuAction(QMenu* menu, const QString & text, const char* slot)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeMenuAction(QMenu* menu, const QString & text, T slot)
 | 
			
		||||
    {
 | 
			
		||||
        return connectMenuAction(menu, makeAction(text, slot));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeMenuAction(QMenu* menu, const QIcon & icon, const QString & text, const char* slot)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeMenuAction(QMenu* menu, const QIcon & icon, const QString & text, T slot)
 | 
			
		||||
    {
 | 
			
		||||
        return connectMenuAction(menu, makeAction(icon, text, slot));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeShortcutMenuAction(QMenu* menu, const QString & text, const char* slot, const char* shortcut)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeShortcutMenuAction(QMenu* menu, const QString & text, T slot, const char* shortcut)
 | 
			
		||||
    {
 | 
			
		||||
        return connectShortcutAction(makeMenuAction(menu, text, slot), shortcut);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    inline QAction* makeShortcutMenuAction(QMenu* menu, const QIcon & icon, const QString & text, const char* slot, const char* shortcut)
 | 
			
		||||
    template<typename T>
 | 
			
		||||
    inline QAction* makeShortcutMenuAction(QMenu* menu, const QIcon & icon, const QString & text, T slot, const char* shortcut)
 | 
			
		||||
    {
 | 
			
		||||
        return connectShortcutAction(makeMenuAction(menu, icon, text, slot), shortcut);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,31 @@
 | 
			
		|||
#ifndef QACTIONLAMBDA
 | 
			
		||||
#define QACTIONLAMBDA
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <functional>
 | 
			
		||||
 | 
			
		||||
class QActionLambda : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    typedef std::function<void()> TriggerCallback;
 | 
			
		||||
 | 
			
		||||
    QActionLambda(QObject* parent, TriggerCallback callback)
 | 
			
		||||
        : QObject(parent),
 | 
			
		||||
          _callback(callback)
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void triggeredSlot()
 | 
			
		||||
    {
 | 
			
		||||
        if(_callback)
 | 
			
		||||
            _callback();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    TriggerCallback _callback;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // QACTIONLAMBDA
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -217,7 +217,8 @@ HEADERS += \
 | 
			
		|||
    Src/Gui/EntropyDialog.h \
 | 
			
		||||
    Src/Gui/NotesManager.h \
 | 
			
		||||
    Src/Gui/NotepadView.h \
 | 
			
		||||
    Src/Utils/MenuBuilder.h
 | 
			
		||||
    Src/Utils/MenuBuilder.h \
 | 
			
		||||
    Src/Utils/QActionLambda.h
 | 
			
		||||
 | 
			
		||||
FORMS += \
 | 
			
		||||
    Src/Gui/MainWindow.ui \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue