3#include <QtCore/QGlobalStatic>
4#include <QtCore/QSettings>
17 for (
int i=0; i<model->
count(); i++) {
18 auto existingItem = qobject_cast<QGCLoggingCategoryItem*>(model->
get(i));
19 if (item->fullCategory < existingItem->fullCategory) {
31 QString parentCategory;
32 QString childCategory(fullCategory);
33 auto currentParentModel = &_treeCategoryModel;
35 auto hierarchyIndex = fullCategory.
indexOf(
".");
36 if (hierarchyIndex != -1) {
37 parentCategory = fullCategory.left(hierarchyIndex);
38 childCategory = fullCategory.mid(hierarchyIndex + 1);
39 QString fullParentCategory = parentCategory +
".";
43 for (
int j=0; j<currentParentModel->count(); j++) {
44 auto item = qobject_cast<QGCLoggingCategoryItem*>(currentParentModel->get(j));
45 if (item->fullCategory == fullParentCategory && item->children) {
47 currentParentModel = item->children;
53 auto newParentItem =
new QGCLoggingCategoryItem(parentCategory, fullParentCategory,
false , currentParentModel);
55 _insertSorted(&_flatCategoryModel, newParentItem);
56 _insertSorted(currentParentModel, newParentItem);
57 currentParentModel = newParentItem->children;
63 _insertSorted(&_flatCategoryModel, categoryItem);
64 _insertSorted(currentParentModel, categoryItem);
70 qCDebug(QGCLoggingCategoryRegisterLog) <<
"Set category logging" << fullCategoryName << enable;
73 settings.beginGroup(kFilterRulesSettingsGroup);
75 settings.setValue(fullCategoryName, enable);
77 settings.remove(fullCategoryName);
87 settings.beginGroup(kFilterRulesSettingsGroup);
88 return settings.value(fullCategoryName,
false).toBool();
94 QString filterRuleFormat(
"%1.debug=true\n");
97 settings.beginGroup(kFilterRulesSettingsGroup);
98 for (
const QString &fullCategoryName : settings.childKeys()) {
99 QString parentCategory;
100 QString childCategory;
101 _splitFullCategoryName(fullCategoryName, parentCategory, childCategory);
103 qCDebug(QGCLoggingCategoryRegisterLog) <<
"Setting filter rule for saved settings" << fullCategoryName << parentCategory << childCategory << settings.value(fullCategoryName).toBool();
105 auto categoryItem = _findLoggingCategory(fullCategoryName);
107 categoryItem->setEnabled(settings.value(fullCategoryName).toBool());
108 if (categoryItem->enabled()) {
109 if (childCategory.isEmpty()) {
111 filterRules += filterRuleFormat.arg(fullCategoryName +
"*");
113 filterRules += filterRuleFormat.arg(fullCategoryName);
117 qCWarning(QGCLoggingCategoryRegisterLog) <<
"Category not found for saved settings" << fullCategoryName;
122 if (!commandLineLoggingOptions.isEmpty()) {
123 const QStringList categoryList = commandLineLoggingOptions.split(
",");
125 if (categoryList[0] == QStringLiteral(
"full")) {
126 filterRules += filterRuleFormat.arg(
"*");
128 for (
const QString &category: categoryList) {
129 filterRules += filterRuleFormat.arg(category);
134 filterRules += QStringLiteral(
"qt.qml.connections=false");
136 qCDebug(QGCLoggingCategoryRegisterLog) <<
"Filter rules" << filterRules;
137 QLoggingCategory::setFilterRules(filterRules);
140void QGCLoggingCategoryManager::_splitFullCategoryName(
const QString &fullCategoryName, QString &parentCategory, QString &childCategory)
142 const int hierarchyIndex = fullCategoryName.indexOf(
".");
143 if (hierarchyIndex == -1) {
144 parentCategory = QString();
145 childCategory = fullCategoryName;
147 parentCategory = fullCategoryName.left(hierarchyIndex);
148 childCategory = fullCategoryName.mid(hierarchyIndex + 1);
155 settings.beginGroup(kFilterRulesSettingsGroup);
158 for (
int i=0; i<_flatCategoryModel.
count(); i++) {
159 auto item = qobject_cast<QGCLoggingCategoryItem*>(_flatCategoryModel.
get(i));
160 item->setEnabled(
false);
168 for (
int i=0; i<_flatCategoryModel.
count(); i++) {
169 auto item = qobject_cast<QGCLoggingCategoryItem*>(_flatCategoryModel.
get(i));
170 if (item->fullCategory == fullCategoryName) {
178QGCLoggingCategoryItem::QGCLoggingCategoryItem(
const QString& shortCategory_,
const QString& fullCategory_,
bool enabled_, QObject* parent)
180 , shortCategory(shortCategory_)
181 , fullCategory(fullCategory_)
189void QGCLoggingCategoryItem::setEnabled(
bool enabled)
191 if (enabled != _enabled) {
Q_GLOBAL_STATIC(FirmwarePluginFactoryRegister, _firmwarePluginFactoryRegisterInstance)
_QGCLoggingCategoryManagerInstance
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void registerCategory(const QString &category)
Registers the specified logging category to the system.
static bool categoryLoggingOn(const QString &fullCategroryName)
Returns true if logging is turned on for the specified category.
static QGCLoggingCategoryManager * instance()
void setCategoryLoggingOn(const QString &fullCategoryName, bool enable)
Turns on/off logging for the specified category. State is saved in app settings.
void disableAllCategories()
void setFilterRulesFromSettings(const QString &commandLineLoggingOptions)
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
int count() const override final
void insert(int index, QObject *object)
int indexOf(const QObject *object)