2022-01-15 00:17:41 +00:00
|
|
|
#include "BootableModelProxy.h"
|
|
|
|
#include "BootableModel.h"
|
2023-03-08 13:13:19 -05:00
|
|
|
#include "QStringUtils.h"
|
2022-01-15 00:17:41 +00:00
|
|
|
#include <regex>
|
2023-03-08 13:13:19 -05:00
|
|
|
|
2022-01-15 00:17:41 +00:00
|
|
|
BootableModelProxy::BootableModelProxy(QObject* parent)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-02-19 00:03:53 +00:00
|
|
|
void BootableModelProxy::setFilterState(const QString& state)
|
|
|
|
{
|
|
|
|
if(state == "All")
|
|
|
|
{
|
|
|
|
m_state.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_state = state.toStdString();
|
|
|
|
}
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
2024-10-17 21:40:04 +01:00
|
|
|
void BootableModelProxy::setBootableTypeFilterState(int bitIndex, bool value)
|
|
|
|
{
|
|
|
|
if(value)
|
|
|
|
m_bootableType |= bitIndex;
|
|
|
|
else
|
|
|
|
m_bootableType &= ~bitIndex;
|
|
|
|
|
|
|
|
invalidateFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
int BootableModelProxy::getBootableTypeFilterState()
|
|
|
|
{
|
|
|
|
return m_bootableType;
|
|
|
|
}
|
|
|
|
|
2022-01-15 00:17:41 +00:00
|
|
|
bool BootableModelProxy::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
|
|
|
|
|
|
QVariant data = sourceModel()->data(index);
|
2022-01-18 16:47:28 +00:00
|
|
|
if(data.canConvert<BootableCoverQVariant>())
|
2022-01-15 00:17:41 +00:00
|
|
|
{
|
2022-01-18 16:47:28 +00:00
|
|
|
BootableCoverQVariant bootablecover = qvariant_cast<BootableCoverQVariant>(data);
|
2022-01-15 00:17:41 +00:00
|
|
|
QString key = QString::fromStdString(bootablecover.GetKey());
|
|
|
|
QString title = QString::fromStdString(bootablecover.GetTitle());
|
2023-03-08 13:13:19 -05:00
|
|
|
QString path = PathToQString(bootablecover.GetPath());
|
2024-10-17 21:40:04 +01:00
|
|
|
auto bootableType = bootablecover.GetBootableType();
|
2022-01-15 00:17:41 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
QRegularExpression regex = filterRegularExpression();
|
|
|
|
regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
|
|
|
#else
|
|
|
|
// QRegExp is deprecated in Qt6, while QRegularExpression is recommended over QRegExp since Qt5
|
|
|
|
// however QRegularExpression is producing incorrect results in Qt5
|
|
|
|
QRegExp regex = filterRegExp();
|
|
|
|
regex.setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
#endif
|
|
|
|
|
2022-02-19 00:03:53 +00:00
|
|
|
bool res = (key.contains(regex) || title.contains(regex) || path.contains(regex));
|
|
|
|
if(!m_state.empty())
|
|
|
|
{
|
|
|
|
res &= bootablecover.HasState(m_state);
|
|
|
|
}
|
2024-10-17 21:40:04 +01:00
|
|
|
|
|
|
|
if(m_bootableType != 0)
|
|
|
|
{
|
|
|
|
res &= (bootableType & m_bootableType) != 0;
|
|
|
|
}
|
2022-02-19 00:03:53 +00:00
|
|
|
return res;
|
2022-01-15 00:17:41 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|