mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 11:39:42 +00:00
Merge branch 'timeout_table_filter' into 'master'
Restore !613 See merge request OpenMW/openmw!3990
This commit is contained in:
commit
3a1d0a9649
6 changed files with 48 additions and 5 deletions
|
@ -452,7 +452,10 @@ std::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseText()
|
|||
return std::shared_ptr<Node>();
|
||||
}
|
||||
|
||||
return std::make_shared<TextNode>(columnId, text);
|
||||
auto node = std::make_shared<TextNode>(columnId, text);
|
||||
if (!node->isValid())
|
||||
error();
|
||||
return node;
|
||||
}
|
||||
|
||||
std::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue()
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace CSMFilter
|
|||
///< Return a string that represents this node.
|
||||
///
|
||||
/// \param numericColumns Use numeric IDs instead of string to represent columns.
|
||||
|
||||
bool isValid() { return mRegExp.isValid(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,7 @@ void CSMPrefs::State::declare()
|
|||
.setTooltip(
|
||||
"When editing a record, open the view in a new window,"
|
||||
" rather than docked in the main view.");
|
||||
declareInt(mValues->mIdTables.mFilterDelay, "Delay before applying a filter (in miliseconds)");
|
||||
|
||||
declareCategory("ID Dialogues");
|
||||
declareBool(mValues->mIdDialogues.mToolbar, "Show toolbar");
|
||||
|
|
|
@ -138,6 +138,7 @@ namespace CSMPrefs
|
|||
EnumSettingValue mJumpToAdded{ mIndex, sName, "jump-to-added", sJumpAndSelectValues, 0 };
|
||||
Settings::SettingValue<bool> mExtendedConfig{ mIndex, sName, "extended-config", false };
|
||||
Settings::SettingValue<bool> mSubviewNewWindow{ mIndex, sName, "subview-new-window", false };
|
||||
Settings::SettingValue<int> mFilterDelay{ mIndex, sName, "filter-delay", 500 };
|
||||
};
|
||||
|
||||
struct IdDialoguesCategory : Settings::WithIndex
|
||||
|
|
|
@ -63,9 +63,18 @@ bool CSMWorld::IdTableProxyModel::filterAcceptsRow(int sourceRow, const QModelIn
|
|||
|
||||
CSMWorld::IdTableProxyModel::IdTableProxyModel(QObject* parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
, mFilterTimer{ new QTimer(this) }
|
||||
, mSourceModel(nullptr)
|
||||
{
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
mFilterTimer->setSingleShot(true);
|
||||
int intervalSetting = CSMPrefs::State::get()["ID Tables"]["filter-delay"].toInt();
|
||||
mFilterTimer->setInterval(intervalSetting);
|
||||
|
||||
connect(&CSMPrefs::State::get(), &CSMPrefs::State::settingChanged, this,
|
||||
[this](const CSMPrefs::Setting* setting) { this->settingChanged(setting); });
|
||||
connect(mFilterTimer.get(), &QTimer::timeout, this, [this]() { this->timerTimeout(); });
|
||||
}
|
||||
|
||||
QModelIndex CSMWorld::IdTableProxyModel::getModelIndex(const std::string& id, int column) const
|
||||
|
@ -87,10 +96,8 @@ void CSMWorld::IdTableProxyModel::setSourceModel(QAbstractItemModel* model)
|
|||
|
||||
void CSMWorld::IdTableProxyModel::setFilter(const std::shared_ptr<CSMFilter::Node>& filter)
|
||||
{
|
||||
beginResetModel();
|
||||
mFilter = filter;
|
||||
updateColumnMap();
|
||||
endResetModel();
|
||||
mAwaitingFilter = filter;
|
||||
mFilterTimer->start();
|
||||
}
|
||||
|
||||
bool CSMWorld::IdTableProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
||||
|
@ -131,6 +138,26 @@ void CSMWorld::IdTableProxyModel::refreshFilter()
|
|||
}
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::timerTimeout()
|
||||
{
|
||||
if (mAwaitingFilter)
|
||||
{
|
||||
beginResetModel();
|
||||
mFilter = mAwaitingFilter;
|
||||
updateColumnMap();
|
||||
endResetModel();
|
||||
mAwaitingFilter.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::settingChanged(const CSMPrefs::Setting* setting)
|
||||
{
|
||||
if (*setting == "ID Tables/filter-delay")
|
||||
{
|
||||
mFilterTimer->setInterval(setting->toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::sourceRowsInserted(const QModelIndex& parent, int /*start*/, int end)
|
||||
{
|
||||
refreshFilter();
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include <QModelIndex>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../prefs/state.hpp"
|
||||
|
||||
#include "columns.hpp"
|
||||
|
||||
|
@ -29,6 +32,8 @@ namespace CSMWorld
|
|||
Q_OBJECT
|
||||
|
||||
std::shared_ptr<CSMFilter::Node> mFilter;
|
||||
std::unique_ptr<QTimer> mFilterTimer;
|
||||
std::shared_ptr<CSMFilter::Node> mAwaitingFilter;
|
||||
std::map<int, int> mColumnMap; // column ID, column index in this model (or -1)
|
||||
|
||||
// Cache of enum values for enum columns (e.g. Modified, Record Type).
|
||||
|
@ -68,6 +73,10 @@ namespace CSMWorld
|
|||
|
||||
virtual void sourceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
|
||||
void timerTimeout();
|
||||
|
||||
void settingChanged(const CSMPrefs::Setting* setting);
|
||||
|
||||
signals:
|
||||
|
||||
void rowAdded(const std::string& id);
|
||||
|
|
Loading…
Reference in a new issue