у меня есть три файла: main. cpp, lnflogi c. cpp и listmodel. cpp это конструкторы listlogi c. cpp
я создаю экземпляр lnflogi c как это в моем основном. cpp
LnfLogic logic;
Я хочу получить доступ к классу в m_lnflistmodel под названием themesinfo (он в его заголовке создан как QList под названием m_themes)
когда Отладка я вижу, что m_themes уже создана (показано на рисунке ниже, как мне получить к ней доступ? вот файлы созданный лог c
LnfLogi c. cpp
#include "lnflogic.h"
#include "lnflistmodel.h"
LnfLogic::LnfLogic()
: m_themeName(QStringLiteral("org.kde.breeze.desktop")),
m_lnfListModel(new LnfListModel(this)),
m_needsSave(false)
{
m_package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel"));
}
LnfLogic::~LnfLogic()
{
}
LnfListModel *LnfLogic::lnfList()
{
return m_lnfListModel;
}
** Конструкторы listmodel он имеет два класса themesinfo и lnflistmodel **
#include "lnflistmodel.h"
LnfListModel::LnfListModel( QObject *parent )
: QAbstractListModel( parent )
{
m_roleNames.insert(Qt::DisplayRole, "displayRole");
m_roleNames.insert(PackageNameRole, "packageNameRole");
m_roleNames.insert(PackageDescriptionRole, "packageDescriptionRole");
m_roleNames.insert(PackageAuthorRole, "packageAuthorRole");
m_roleNames.insert(PackageVersionRole, "packageVersionRole");
reload();
}
LnfListModel::~LnfListModel()
{
clearThemeList();
}
Это заголовочный файл для listmodel
#ifndef LNFLISTMODEL_H
#define LNFLISTMODEL_H
#include <QAbstractItemView>
namespace Plasma
{
}
//Theme selector code by Andre Duffeck (modified to add package description)
//not sure if i would need this
class ThemeInfo
{
public:
QString name;
QString package;
QString description;
QString author;
QString version;
QString themeRoot;
};
class LnfListModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum { PackageNameRole = Qt::UserRole,
PackageDescriptionRole = Qt::UserRole + 1,
PackageAuthorRole = Qt::UserRole + 2,
PackageVersionRole = Qt::UserRole + 3
};
explicit LnfListModel(QObject *parent = nullptr);
~LnfListModel() override;
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QModelIndex indexOf(const QString &path) const;
bool themeExists(const QString &name) const;
void reload();
void clearThemeList();
int count() const
{
return rowCount();
}
Q_INVOKABLE QVariantMap get(int index) const;
Q_SIGNALS:
void countChanged();
private:
QHash<int, QByteArray> m_roleNames;
QList<ThemeInfo> m_themes;
};
Заголовочный файл lnflogi c
#define LNFLOGIC_H
#include <QAbstractListModel>
#include <kpackage/package.h>
class LnfListModel;
class LnfLogic : public QObject
{
Q_OBJECT
Q_PROPERTY(LnfListModel *lnfList READ lnfList CONSTANT)
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(bool isWritable READ isWritable NOTIFY themeChanged)
Q_PROPERTY(QString themeFolder READ themeFolder NOTIFY themeChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString comment READ comment WRITE setComment NOTIFY commentChanged)
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
Q_PROPERTY(QString version READ version WRITE setVersion NOTIFY versionChanged)
Q_PROPERTY(QString website READ website WRITE setWebsite NOTIFY websiteChanged)
Q_PROPERTY(QString license READ license WRITE setLicense NOTIFY licenseChanged)
Q_PROPERTY(QString thumbnailPath READ thumbnailPath NOTIFY themeChanged)
Q_PROPERTY(bool performLayoutDump READ performLayoutDump WRITE setPerformLayoutDump NOTIFY performLayoutDumpChanged)
Q_PROPERTY(bool performDefaultsDump READ performDefaultsDump WRITE setPerformDefaultsDump NOTIFY performDefaultsDumpChanged)
Q_PROPERTY(bool needsSave READ needsSave NOTIFY needsSaveChanged)
public:
enum ErrorLevel
{
Info,
Error
};
Q_ENUMS(ErrorLevel)
LnfLogic();
~LnfLogic() override;
LnfListModel *lnfList();
bool themeExists(const QString &plugin);
void setTheme(const QString &theme);
QString theme() const;
bool isWritable() const;
QString themeFolder() const;
QString name() const;
void setName(const QString &name);
QString comment() const;
void setComment(const QString &comment);
QString author() const;
void setAuthor(const QString &author);
QString email() const;
void setEmail(const QString &email);
QString version() const;
void setVersion(const QString &version);
QString website() const;
void setWebsite(const QString &website);
QString license() const;
void setLicense(const QString &license);
bool performLayoutDump() const;
void setPerformLayoutDump(bool dump);
bool performDefaultsDump() const;
void setPerformDefaultsDump(bool dump);
QString thumbnailPath() const;
void dumpPlasmaLayout(const QString &pluginName);
bool needsSave();
Q_INVOKABLE void save();
Q_INVOKABLE void createNewTheme(const QString &pluginName, const QString &name, const QString &comment, const QString &author, const QString &email, const QString &license, const QString &website);
Q_INVOKABLE void processThumbnail(const QString &path);
Q_INVOKABLE QString openFile();
void dumpCurrentPlasmaLayout();
void dumpDefaultsConfigFile(const QString &pluginName);
Q_SIGNALS:
void themeChanged();
void messageRequested(ErrorLevel level, const QString &message);
void needsSaveChanged();
void nameChanged();
void commentChanged();
void authorChanged();
void emailChanged();
void versionChanged();
void websiteChanged();
void licenseChanged();
void performLayoutDumpChanged();
void performDefaultsDumpChanged();
private:
QString m_themeName;
KPackage::Package m_package;
LnfListModel *m_lnfListModel;
QHash<QString, QString> m_tempMetadata;
bool m_performLayoutDump : 1;
bool m_performDefaultsDump : 1;
bool m_needsSave;
};
#endif // LNFLOGIC_H