-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
190 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "bfkey.h" | ||
|
||
#include <QJsonDocument> | ||
|
||
BloomFilterKeyModel::BloomFilterKeyModel( | ||
QSharedPointer<RedisClient::Connection> connection, QByteArray fullPath, | ||
int dbIndex, long long ttl, QString filterFamily) | ||
: KeyModel(connection, fullPath, dbIndex, ttl), m_type(filterFamily) {} | ||
|
||
QString BloomFilterKeyModel::type() { return m_type; } | ||
|
||
QStringList BloomFilterKeyModel::getColumnNames() { | ||
return QStringList() << "value"; | ||
} | ||
|
||
QHash<int, QByteArray> BloomFilterKeyModel::getRoles() { | ||
QHash<int, QByteArray> roles; | ||
roles[Roles::Value] = "value"; | ||
return roles; | ||
} | ||
|
||
QVariant BloomFilterKeyModel::getData(int rowIndex, int dataRole) { | ||
if (rowIndex > 0 || !isRowLoaded(rowIndex)) return QVariant(); | ||
if (dataRole == Roles::Value) | ||
return QJsonDocument::fromVariant(m_rowsCache[rowIndex]) | ||
.toJson(QJsonDocument::Compact); | ||
|
||
return QVariant(); | ||
} | ||
|
||
void BloomFilterKeyModel::addRow(const QVariantMap& row, Callback c) { | ||
QByteArray value = row.value("value").toByteArray(); | ||
|
||
executeCmd({QString("%1.ADD").arg(m_type).toLatin1(), m_keyFullPath, value}, | ||
[this, c](const QString& err) { | ||
m_rowCount++; | ||
return c(err); | ||
}); | ||
} | ||
|
||
void BloomFilterKeyModel::loadRows(QVariant, unsigned long, | ||
LoadRowsCallback callback) { | ||
auto onConnectionError = [callback](const QString& err) { | ||
return callback(err, 0); | ||
}; | ||
|
||
auto responseHandler = [this, callback](RedisClient::Response r, Callback) { | ||
m_rowsCache.clear(); | ||
auto value = r.value().toList(); | ||
|
||
QVariantMap row; | ||
|
||
for (QVariantList::const_iterator item = value.cbegin(); item != value.cend(); | ||
++item) { | ||
auto key = item->toByteArray(); | ||
++item; | ||
|
||
if (item == value.cend()) { | ||
emit m_notifier->error(QCoreApplication::translate( | ||
"RESP", "Data was loaded from server partially.")); | ||
break; | ||
} | ||
|
||
auto keyVal = item->toByteArray(); | ||
row[key] = keyVal; | ||
} | ||
|
||
m_rowsCache.push_back(row); | ||
callback(QString(), 1); | ||
}; | ||
|
||
executeCmd({QString("%1.INFO").arg(m_type).toLatin1(), m_keyFullPath}, | ||
onConnectionError, responseHandler, RedisClient::Response::Array); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
#include "stringkey.h" | ||
|
||
class BloomFilterKeyModel : public KeyModel<QVariant> { | ||
public: | ||
BloomFilterKeyModel(QSharedPointer<RedisClient::Connection> connection, | ||
QByteArray fullPath, int dbIndex, long long ttl, QString filterFamily="bf"); | ||
|
||
QString type() override; | ||
QStringList getColumnNames() override; | ||
QHash<int, QByteArray> getRoles() override; | ||
QVariant getData(int rowIndex, int dataRole) override; | ||
|
||
void addRow(const QVariantMap&, Callback c) override; | ||
virtual void updateRow(int, const QVariantMap&, | ||
Callback) override {} | ||
void loadRows(QVariant, unsigned long, LoadRowsCallback callback) override; | ||
void removeRow(int, Callback) override {} | ||
|
||
virtual unsigned long rowsCount() override { return m_rowCount; } | ||
|
||
protected: | ||
int addLoadedRowsToCache(const QVariantList&, QVariant) override { return 1; } | ||
|
||
private: | ||
enum Roles { Value = Qt::UserRole + 1 }; | ||
QString m_type; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import QtQuick 2.0 | ||
import QtQuick.Layouts 1.1 | ||
import QtQuick.Controls 1.2 | ||
import QtQuick.Controls.Styles 1.1 | ||
|
||
import "." | ||
|
||
AbstractEditor { | ||
id: root | ||
anchors.fill: parent | ||
|
||
property bool active: false | ||
property alias defaultFormatter: textEditor.defaultFormatter | ||
|
||
MultilineEditor { | ||
id: textEditor | ||
Layout.fillWidth: true | ||
Layout.fillHeight: true | ||
value: "" | ||
enabled: false | ||
showToolBar: false | ||
showSaveBtn: false | ||
showFormatters: false | ||
showValueSize: false | ||
objectName: "rdm_key_value_field" | ||
|
||
function validationRule(raw) { | ||
return true; | ||
} | ||
} | ||
|
||
onKeyTypeChanged: { | ||
textEditor.hintFormatter("JSON") | ||
} | ||
|
||
function initEmpty() { | ||
textEditor.initEmpty() | ||
} | ||
|
||
function getValue(validateVal, callback) { | ||
if (!validateVal) { | ||
return callback(true, {"value": ""}); | ||
} | ||
|
||
return textEditor.validate(function (valid, raw) { | ||
return callback(valid, {"value": raw}); | ||
}); | ||
} | ||
|
||
function setValue(rowValue) { | ||
if (!rowValue) | ||
return | ||
|
||
active = true | ||
textEditor.loadFormattedValue(rowValue['value']) | ||
} | ||
|
||
function isEdited() { | ||
return textEditor.isEdited | ||
} | ||
|
||
function reset() { | ||
textEditor.reset() | ||
active = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters