Skip to content

Commit

Permalink
Stable views
Browse files Browse the repository at this point in the history
  • Loading branch information
topilski committed Oct 12, 2018
1 parent cd3192b commit e5b682d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 37 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.20.1 /
1.20.1 / October 12, 2018
[Alexandr Topilski]
- Auto revert views after queries
- FastoViewer for values

1.20.0 / October 8, 2018
[Alexandr Topilski]
Expand Down
3 changes: 2 additions & 1 deletion FASTOREDIS_CHANELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.19.1 /
1.19.1 / October 12, 2018
[Alexandr Topilski]
- Auto revert views after queries
- FastoViewer for values

1.19.0 / October 8, 2018
[Alexandr Topilski]
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/dbkey_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void DbKeyDialog::changeType(common::Value::Type type) {
resize(kPrefHashSize);
} else if (type == core::StreamValue::TYPE_STREAM) {
resize(kPrefStreamSize);
} else if (type == core::JsonValue::TYPE_JSON) {
} else if (type == core::JsonValue::TYPE_JSON || type == core::JsonValue::TYPE_STRING) {
resize(kPrefJsonSize);
} else {
resize(min_dialog_size);
Expand Down
15 changes: 14 additions & 1 deletion src/gui/widgets/fasto_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ FastoViewer::FastoViewer(QWidget* parent) : QWidget(parent), view_method_(RAW_VI
text_json_editor_ = new FastoEditor;
json_lexer_ = new QsciLexerJSON;
xml_lexer_ = new QsciLexerXML;
VERIFY(connect(text_json_editor_, &FastoEditor::textChanged, this, &FastoViewer::textChanged));
VERIFY(connect(text_json_editor_, &FastoEditor::textChanged, this, &FastoViewer::textChange));
VERIFY(connect(text_json_editor_, &FastoEditor::readOnlyChanged, this, &FastoViewer::readOnlyChanged));

QVBoxLayout* main = new QVBoxLayout;
Expand Down Expand Up @@ -183,6 +183,14 @@ void FastoViewer::syncEditors() {
}
}

void FastoViewer::setView(int view_method) {
views_combo_box_->setCurrentIndex(view_method);
}

void FastoViewer::setViewChangeEnabled(bool enable) {
views_combo_box_->setEnabled(enable);
}

void FastoViewer::setReadOnly(bool ro) {
text_json_editor_->setReadOnly(ro);
}
Expand All @@ -195,6 +203,11 @@ void FastoViewer::viewChange(int view_method) {
emit viewChanged(view_method);
}

void FastoViewer::textChange() {
clearError();
emit textChanged();
}

void FastoViewer::clear() {
text_json_editor_->clear();
clearError();
Expand Down
7 changes: 6 additions & 1 deletion src/gui/widgets/fasto_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ class FastoViewer : public QWidget {
void viewChanged(int view_method);

public Q_SLOTS:
void setView(int view_method);
void setViewChangeEnabled(bool enable);
void setReadOnly(bool ro);
void viewChange(int view_method);
void clear();

private Q_SLOTS:
void viewChange(int view_method);
void textChange();

protected:
virtual void changeEvent(QEvent* ev) override;

Expand Down
70 changes: 40 additions & 30 deletions src/gui/widgets/key_edit_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <QLabel>
#include <QLineEdit>

#include <Qsci/qscilexerjson.h>

#include <common/convert2string.h>
#include <common/qt/convert2string.h> // for ConvertToString

Expand All @@ -34,7 +32,6 @@
#include "gui/gui_factory.h" // for GuiFactory
#include "gui/hash_table_model.h"

#include "gui/widgets/fasto_editor.h"
#include "gui/widgets/fasto_viewer.h"
#include "gui/widgets/hash_type_widget.h"
#include "gui/widgets/list_type_widget.h"
Expand Down Expand Up @@ -72,18 +69,16 @@ KeyEditWidget::KeyEditWidget(const std::vector<common::Value::Type>& availible_t
// value layout
value_label_ = new QLabel;
kvLayout->addWidget(value_label_, 2, 0);
value_edit_ = new FastoViewer;
// value_edit_->setPlaceholderText("[value]");
value_edit_ = new QLineEdit;
value_edit_->setPlaceholderText("[value]");
kvLayout->addWidget(value_edit_, 2, 1);
value_edit_->setVisible(true);
VERIFY(connect(value_edit_, &FastoViewer::textChanged, this, &KeyEditWidget::keyChanged));
VERIFY(connect(value_edit_, &QLineEdit::textChanged, this, &KeyEditWidget::keyChanged));

json_value_edit_ = new FastoEditor;
QsciLexerJSON* json_lexer = new QsciLexerJSON;
json_value_edit_->setLexer(json_lexer);
json_value_edit_ = new FastoViewer;
kvLayout->addWidget(json_value_edit_, 2, 1);
json_value_edit_->setVisible(false);
VERIFY(connect(json_value_edit_, &FastoEditor::textChanged, this, &KeyEditWidget::keyChanged));
VERIFY(connect(json_value_edit_, &FastoViewer::textChanged, this, &KeyEditWidget::keyChanged));

bool_value_edit_ = new QComboBox;
bool_value_edit_->addItem("true");
Expand Down Expand Up @@ -163,12 +158,19 @@ common::Value* KeyEditWidget::createItem() const {
return value_table_edit_->hashValue();
} else if (type == core::StreamValue::TYPE_STREAM) {
return stream_table_edit_->streamValue();
} else if (type == core::JsonValue::TYPE_JSON) {
const std::string text_str = common::ConvertToString(json_value_edit_->text());
if (!core::JsonValue::IsValidJson(text_str)) {
} else if (type == core::JsonValue::TYPE_JSON || type == common::Value::TYPE_STRING) {
const std::string json_or_text_str = json_value_edit_->text();
if (type == common::Value::TYPE_STRING) {
if (json_or_text_str.empty()) {
return nullptr;
}
return common::Value::CreateStringValue(json_or_text_str);
}

if (!core::JsonValue::IsValidJson(json_or_text_str)) {
return nullptr;
}
return new core::JsonValue(text_str);
return new core::JsonValue(json_or_text_str);
} else if (type == common::Value::TYPE_BOOLEAN) {
int index = bool_value_edit_->currentIndex();
return common::Value::CreateBooleanValue(index == 0);
Expand Down Expand Up @@ -205,7 +207,8 @@ common::Value* KeyEditWidget::createItem() const {
return common::Value::CreateDoubleValue(res);
}

return common::Value::CreateStringValue(text_str);
NOTREACHED() << "Not handled type: " << type;
return nullptr;
}

void KeyEditWidget::changeEvent(QEvent* e) {
Expand Down Expand Up @@ -253,7 +256,7 @@ void KeyEditWidget::changeType(int index) {
json_value_edit_->setVisible(false);
bool_value_edit_->setVisible(false);
value_list_edit_->setVisible(false);
} else if (type == core::JsonValue::TYPE_JSON) {
} else if (type == core::JsonValue::TYPE_JSON || type == common::Value::TYPE_STRING) {
value_table_edit_->setVisible(false);
stream_table_edit_->setVisible(false);
value_edit_->setVisible(false);
Expand All @@ -267,14 +270,14 @@ void KeyEditWidget::changeType(int index) {
value_list_edit_->setVisible(false);
value_table_edit_->setVisible(false);
stream_table_edit_->setVisible(false);
/*if (type == common::Value::TYPE_INTEGER || type == common::Value::TYPE_UINTEGER) {
if (type == common::Value::TYPE_INTEGER || type == common::Value::TYPE_UINTEGER) {
value_edit_->setValidator(new QIntValidator(this));
} else if (type == common::Value::TYPE_DOUBLE) {
value_edit_->setValidator(new QDoubleValidator(this));
} else {
QRegExp rx(".*");
value_edit_->setValidator(new QRegExpValidator(rx, this));
}*/
}
}

emit typeChanged(type);
Expand All @@ -291,8 +294,8 @@ void KeyEditWidget::syncControls(const core::NValue& item) {
stream_table_edit_->clear();
value_list_edit_->clear();

common::Value::Type t = item->GetType();
if (t == common::Value::TYPE_ARRAY) {
common::Value::Type type = item->GetType();
if (type == common::Value::TYPE_ARRAY) {
common::ArrayValue* arr = nullptr;
if (item->GetAsList(&arr)) {
for (auto it = arr->begin(); it != arr->end(); ++it) {
Expand All @@ -307,7 +310,7 @@ void KeyEditWidget::syncControls(const core::NValue& item) {
}
}
}
} else if (t == common::Value::TYPE_SET) {
} else if (type == common::Value::TYPE_SET) {
common::SetValue* set = nullptr;
if (item->GetAsSet(&set)) {
for (auto it = set->begin(); it != set->end(); ++it) {
Expand All @@ -322,7 +325,7 @@ void KeyEditWidget::syncControls(const core::NValue& item) {
}
}
}
} else if (t == common::Value::TYPE_ZSET) {
} else if (type == common::Value::TYPE_ZSET) {
common::ZSetValue* zset = nullptr;
if (item->GetAsZSet(&zset)) {
for (auto it = zset->begin(); it != zset->end(); ++it) {
Expand All @@ -346,7 +349,7 @@ void KeyEditWidget::syncControls(const core::NValue& item) {
}
}
}
} else if (t == common::Value::TYPE_HASH) {
} else if (type == common::Value::TYPE_HASH) {
common::HashValue* hash = nullptr;
if (item->GetAsHash(&hash)) {
for (auto it = hash->begin(); it != hash->end(); ++it) {
Expand All @@ -370,30 +373,37 @@ void KeyEditWidget::syncControls(const core::NValue& item) {
}
}
}
} else if (t == core::StreamValue::TYPE_STREAM) {
} else if (type == core::StreamValue::TYPE_STREAM) {
core::StreamValue* stream = static_cast<core::StreamValue*>(item.get());
auto entr = stream->GetStreams();
for (size_t i = 0; i != entr.size(); ++i) {
auto ent = entr[i];
stream_table_edit_->insertStream(ent);
}
} else if (t == core::JsonValue::TYPE_JSON) {
} else if (type == core::JsonValue::TYPE_JSON || type == common::Value::TYPE_STRING) {
std::string text;
if (item->GetAsString(&text)) {
QString qval;
if (common::ConvertFromString(text, &qval)) {
json_value_edit_->setText(qval);
if (type == core::JsonValue::TYPE_JSON) {
json_value_edit_->setView(JSON_VIEW);
json_value_edit_->setViewChangeEnabled(false);
} else {
json_value_edit_->setView(RAW_VIEW);
json_value_edit_->setViewChangeEnabled(true);
}
json_value_edit_->setText(text);
}
} else if (t == common::Value::TYPE_BOOLEAN) {
} else if (type == common::Value::TYPE_BOOLEAN) {
bool val;
if (item->GetAsBoolean(&val)) {
bool_value_edit_->setCurrentIndex(val ? 0 : 1);
}
} else {
std::string text;
if (item->GetAsString(&text)) {
value_edit_->setText(text);
QString qval;
if (common::ConvertFromString(text, &qval)) {
value_edit_->setText(qval);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/widgets/key_edit_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class KeyEditWidget : public QGroupBox {
QLineEdit* key_edit_;
QComboBox* types_combo_box_;
QLabel* value_label_;
FastoViewer* value_edit_;
FastoEditor* json_value_edit_;
QLineEdit* value_edit_;
FastoViewer* json_value_edit_;
QComboBox* bool_value_edit_;
ListTypeWidget* value_list_edit_;
HashTypeWidget* value_table_edit_;
Expand Down

0 comments on commit e5b682d

Please sign in to comment.