mirror of
				https://github.com/YACReader/yacreader
				synced 2025-11-04 01:05:06 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			86 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include "actions_groups_model.h"
 | 
						|
 | 
						|
ActionsGroupsModel::ActionsGroupsModel(QObject *parent)
 | 
						|
    : QAbstractItemModel(parent)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
int ActionsGroupsModel::rowCount(const QModelIndex &parent) const
 | 
						|
{
 | 
						|
    Q_UNUSED(parent);
 | 
						|
 | 
						|
    return groups.length();
 | 
						|
}
 | 
						|
 | 
						|
int ActionsGroupsModel::columnCount(const QModelIndex &parent) const
 | 
						|
{
 | 
						|
    Q_UNUSED(parent);
 | 
						|
 | 
						|
    return 1;
 | 
						|
}
 | 
						|
 | 
						|
QModelIndex ActionsGroupsModel::index(int row, int column, const QModelIndex &parent) const
 | 
						|
{
 | 
						|
    if (!hasIndex(row, column, parent))
 | 
						|
        return QModelIndex();
 | 
						|
 | 
						|
    return createIndex(row, column);
 | 
						|
}
 | 
						|
 | 
						|
QVariant ActionsGroupsModel::data(const QModelIndex &index, int role) const
 | 
						|
{
 | 
						|
    if (!index.isValid())
 | 
						|
        return QVariant();
 | 
						|
 | 
						|
    if (role == Qt::DecorationRole)
 | 
						|
        return QVariant(groups.at(index.row()).getIcon());
 | 
						|
 | 
						|
    if (role != Qt::DisplayRole)
 | 
						|
        return QVariant();
 | 
						|
 | 
						|
    return QVariant(groups[index.row()].getName());
 | 
						|
}
 | 
						|
 | 
						|
QModelIndex ActionsGroupsModel::parent(const QModelIndex &index) const
 | 
						|
{
 | 
						|
    Q_UNUSED(index);
 | 
						|
 | 
						|
    return QModelIndex();
 | 
						|
}
 | 
						|
 | 
						|
void ActionsGroupsModel::addActionsGroup(const ActionsGroup &group)
 | 
						|
{
 | 
						|
    beginInsertRows(QModelIndex(), groups.length(), groups.length());
 | 
						|
    groups.push_back(group);
 | 
						|
    endInsertRows();
 | 
						|
}
 | 
						|
 | 
						|
QList<QAction *> ActionsGroupsModel::getActions(const QModelIndex &mi)
 | 
						|
{
 | 
						|
    if (mi.isValid())
 | 
						|
        return groups[mi.row()].getActions();
 | 
						|
    return QList<QAction *>();
 | 
						|
}
 | 
						|
 | 
						|
//-------------------------------------------------------------------
 | 
						|
 | 
						|
ActionsGroup::ActionsGroup(const QString &name, const QIcon &icon, QList<QAction *> &actions)
 | 
						|
    : name(name), icon(icon), actions(actions)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
QString ActionsGroup::getName() const
 | 
						|
{
 | 
						|
    return name;
 | 
						|
}
 | 
						|
 | 
						|
QIcon ActionsGroup::getIcon() const
 | 
						|
{
 | 
						|
    return icon;
 | 
						|
}
 | 
						|
 | 
						|
QList<QAction *> ActionsGroup::getActions() const
 | 
						|
{
 | 
						|
    return actions;
 | 
						|
}
 |