mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
refs #506, filter for status messages
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3c8056c838
commit
67125a1ecc
51
src/blackgui/models/statusmessagefilter.cpp
Normal file
51
src/blackgui/models/statusmessagefilter.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackgui/models/statusmessagefilter.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
CStatusMessageFilter::CStatusMessageFilter(CStatusMessage::StatusSeverity severity, const QString &text, const QString &category) :
|
||||
m_severity(severity), m_msgText(text.trimmed()), m_category(category.trimmed())
|
||||
{
|
||||
// info or debug are treated like no filter
|
||||
this->m_valid = !((severity == CStatusMessage::SeverityInfo || severity == CStatusMessage::SeverityDebug) && m_msgText.isEmpty() && m_category.isEmpty());
|
||||
}
|
||||
|
||||
CStatusMessageList CStatusMessageFilter::filter(const CStatusMessageList &inContainer) const
|
||||
{
|
||||
if (!this->isValid()) { return inContainer; }
|
||||
CStatusMessageList outContainer;
|
||||
for (const CStatusMessage &msg : inContainer)
|
||||
{
|
||||
if (!(m_severity == CStatusMessage::SeverityInfo || m_severity == CStatusMessage::SeverityDebug))
|
||||
{
|
||||
if (!msg.isSeverityHigherOrEqual(this->m_severity)) { continue; }
|
||||
}
|
||||
|
||||
if (!this->m_msgText.isEmpty())
|
||||
{
|
||||
if (!this->stringMatchesFilterExpression(msg.getMessage(), this->m_msgText)) { continue; }
|
||||
}
|
||||
|
||||
if (!this->m_category.isEmpty())
|
||||
{
|
||||
if (!this->stringMatchesFilterExpression(msg.getHumanOrTechnicalCategoriesAsString(), this->m_category)) { continue; }
|
||||
}
|
||||
|
||||
outContainer.push_back(msg);
|
||||
}
|
||||
return outContainer;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
42
src/blackgui/models/statusmessagefilter.h
Normal file
42
src/blackgui/models/statusmessagefilter.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_STATUSMESSAGEFILTER_H
|
||||
#define BLACKGUI_STATUSMESSAGEFILTER_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/models/modelfilter.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include <QString>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Models
|
||||
{
|
||||
//! Filter for status messages
|
||||
class BLACKGUI_EXPORT CStatusMessageFilter : public IModelFilter<BlackMisc::CStatusMessageList>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CStatusMessageFilter(BlackMisc::CStatusMessage::StatusSeverity severity, const QString &text, const QString &category);
|
||||
|
||||
//! \copydoc IModelFilter::filter
|
||||
virtual BlackMisc::CStatusMessageList filter(const BlackMisc::CStatusMessageList &inContainer) const override;
|
||||
|
||||
private:
|
||||
BlackMisc::CStatusMessage::StatusSeverity m_severity = BlackMisc::CStatusMessage::SeverityError;
|
||||
QString m_msgText;
|
||||
QString m_category;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user