mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
Ref T180, functions to access existing values in shared stringlist completer
This commit is contained in:
@@ -8,14 +8,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sharedstringlistcompleter.h"
|
#include "sharedstringlistcompleter.h"
|
||||||
#include <QStringListModel>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
bool CSharedStringListCompleter::updateData(const QStringList &data, int cacheTimeMs)
|
bool CSharedStringListCompleter::updateData(const QStringList &data, int cacheTimeMs)
|
||||||
{
|
{
|
||||||
QStringListModel *model = qobject_cast<QStringListModel *>(m_completer->model());
|
QStringListModel *model = this->getCompleterModel();
|
||||||
Q_ASSERT_X(model, Q_FUNC_INFO, "Model missing");
|
Q_ASSERT_X(model, Q_FUNC_INFO, "Model missing");
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||||
@@ -40,6 +39,23 @@ namespace BlackGui
|
|||||||
return (QDateTime::currentMSecsSinceEpoch() - m_lastUpdated) <= checkTimeMs;
|
return (QDateTime::currentMSecsSinceEpoch() - m_lastUpdated) <= checkTimeMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSharedStringListCompleter::contains(const QString &value, Qt::CaseSensitivity cs) const
|
||||||
|
{
|
||||||
|
return this->stringList().contains(value, cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CSharedStringListCompleter::stringList() const
|
||||||
|
{
|
||||||
|
const QStringListModel *model = this->getCompleterModel();
|
||||||
|
if (!model) { return QStringList(); }
|
||||||
|
return model->stringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringListModel *CSharedStringListCompleter::getCompleterModel() const
|
||||||
|
{
|
||||||
|
return qobject_cast<QStringListModel *>(m_completer->model());
|
||||||
|
}
|
||||||
|
|
||||||
void CompleterUtils::setCompleterParameters(QCompleter *completer)
|
void CompleterUtils::setCompleterParameters(QCompleter *completer)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(completer, Q_FUNC_INFO, "Need completer");
|
Q_ASSERT_X(completer, Q_FUNC_INFO, "Need completer");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include "blackgui/blackguiexport.h"
|
#include "blackgui/blackguiexport.h"
|
||||||
|
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
#include <QStringList>
|
#include <QStringListModel>
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
@@ -39,6 +39,12 @@ namespace BlackGui
|
|||||||
//! Was updated within check time
|
//! Was updated within check time
|
||||||
bool wasUpdatedWithinTime(int checkTimeMs) const;
|
bool wasUpdatedWithinTime(int checkTimeMs) const;
|
||||||
|
|
||||||
|
//! Contains the string completer the given value
|
||||||
|
bool contains(const QString &value, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
|
||||||
|
|
||||||
|
//! Values
|
||||||
|
QStringList stringList() const;
|
||||||
|
|
||||||
//! Completer
|
//! Completer
|
||||||
QCompleter *completer() const { return m_completer.data(); }
|
QCompleter *completer() const { return m_completer.data(); }
|
||||||
|
|
||||||
@@ -48,6 +54,7 @@ namespace BlackGui
|
|||||||
private:
|
private:
|
||||||
qint64 m_lastUpdated = 0;
|
qint64 m_lastUpdated = 0;
|
||||||
QScopedPointer<QCompleter> m_completer { new QCompleter(QStringList()) }; // empty list required to init model
|
QScopedPointer<QCompleter> m_completer { new QCompleter(QStringList()) }; // empty list required to init model
|
||||||
|
QStringListModel *getCompleterModel() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user