mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Ref T171, use a shared completer for callsign completion
* CSharedStringListCompleter utility class supporting timestamp checks * avoid unnecessary DBus transfer * less memory consumption Remark: No totally clear if a QCompleter can be shared, but I have not noticed a problem so far
This commit is contained in:
54
src/blackgui/sharedstringlistcompleter.h
Normal file
54
src/blackgui/sharedstringlistcompleter.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* Copyright (C) 2017
|
||||
* 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_SHAREDSTRINGLISTCOMPLETER_H
|
||||
#define BLACKGUI_SHAREDSTRINGLISTCOMPLETER_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
#include <QCompleter>
|
||||
#include <QStringList>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
/*!
|
||||
* Completer shared among multiple UI elements.
|
||||
* Normally used as static member
|
||||
*/
|
||||
class BLACKGUI_EXPORT CSharedStringListCompleter
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CSharedStringListCompleter() {}
|
||||
|
||||
//! Update data
|
||||
bool updateData(const QStringList &data, int cacheTimeMs);
|
||||
|
||||
//! Clear completer data
|
||||
void clearData();
|
||||
|
||||
//! Was updated within check time
|
||||
bool wasUpdatedWithinTime(int checkTimeMs) const;
|
||||
|
||||
//! Completer
|
||||
QCompleter *completer() const { return m_completer.data(); }
|
||||
|
||||
//! Convert to completer
|
||||
operator QCompleter *() const { return m_completer.data(); }
|
||||
|
||||
private:
|
||||
qint64 m_lastUpdated = 0;
|
||||
QScopedPointer<QCompleter> m_completer { new QCompleter(QStringList()) }; // empty list required to init model
|
||||
};
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user