Skip to content

Commit 3876c25

Browse files
committed
Improve UX for TreeView
* Show only last part for namespaced keys * Show namespaces first * Remove ignored option from Global Settings * Fix namespace rendering with multichar ns separators Fix RedisInsight#4962
1 parent 2857f12 commit 3876c25

File tree

12 files changed

+186
-138
lines changed

12 files changed

+186
-138
lines changed

src/modules/connections-tree/items/abstractnamespaceitem.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,32 @@ QWeakPointer<TreeItem> AbstractNamespaceItem::parent() const {
4242
return m_parent;
4343
}
4444

45+
bool compareNamespaces(QSharedPointer<TreeItem> first,
46+
QSharedPointer<TreeItem> second) {
47+
48+
if (first->type() != second->type())
49+
return first->type() > second->type();
50+
51+
return first->getDisplayName() < second->getDisplayName();
52+
}
53+
54+
void AbstractNamespaceItem::appendNamespace(QSharedPointer<AbstractNamespaceItem> item) {
55+
m_childNamespaces[item->getName()] = item;
56+
m_childItems.append(item.staticCast<TreeItem>());
57+
58+
std::sort(m_childItems.begin(), m_childItems.end(), compareNamespaces);
59+
}
60+
4561
uint AbstractNamespaceItem::childCount(bool recursive) const {
46-
if (!recursive) {
47-
if (m_rawChildKeys.size() > 0) {
48-
return 0;
49-
}
62+
if (!recursive) {
63+
if (m_rawChildKeys.size() > 0) {
64+
return 0;
65+
}
5066

51-
return m_childItems.size();
52-
}
67+
return m_childItems.size();
68+
}
5369

54-
if (m_rawChildKeys.size() > 0) {
70+
if (m_rawChildKeys.size() > 0) {
5571
return m_rawChildKeys.size();
5672
}
5773

src/modules/connections-tree/items/abstractnamespaceitem.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ class AbstractNamespaceItem : public QObject, public TreeItem, public MemoryUsag
4141
m_rawChildKeys.append(k);
4242
}
4343

44-
virtual void appendNamespace(QSharedPointer<AbstractNamespaceItem> item) {
45-
m_childNamespaces[item->getName()] = item;
46-
m_childItems.append(item.staticCast<TreeItem>());
47-
}
44+
virtual void appendNamespace(QSharedPointer<AbstractNamespaceItem> item);
4845

4946
virtual QSharedPointer<AbstractNamespaceItem> findChildNamespace(
5047
const QByteArray& name) {

src/modules/connections-tree/items/keyitem.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QCoreApplication>
44
#include <QMenu>
55
#include <QMessageBox>
6+
#include <QSettings>
67

78
#include "app/apputils.h"
89
#include "connections-tree/items/abstractnamespaceitem.h"
@@ -26,10 +27,25 @@ KeyItem::KeyItem(const QByteArray& fullPath, QWeakPointer<TreeItem> parent,
2627
: TreeItem(model),
2728
m_fullPath(fullPath),
2829
m_parent(parent),
29-
m_removed(false) {}
30+
m_removed(false) {
31+
QSettings settings;
32+
m_shortRendering =
33+
settings.value("app/namespacedKeysShortName", true).toBool();
34+
}
3035

3136
QString KeyItem::getDisplayName() const {
32-
QString title = printableString(getFullPath(), true);
37+
QString title;
38+
39+
if (m_parent && m_parent.toStrongRef()->type() == "namespace" &&
40+
m_shortRendering) {
41+
auto parent = parentTreeItemToNs(m_parent);
42+
43+
title = printableString(getFullPath().mid(
44+
parent->getFullPath().size() +
45+
parent->operations()->getNamespaceSeparator().size()));
46+
} else {
47+
title = printableString(getFullPath(), true);
48+
}
3349

3450
if (m_usedMemory > 0) {
3551
title.append(QString(" <b>[%1]</b>").arg(humanReadableSize(m_usedMemory)));

src/modules/connections-tree/items/keyitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class KeyItem : public TreeItem, public MemoryUsage {
4646
QByteArray m_fullPath;
4747
QWeakPointer<TreeItem> m_parent;
4848
bool m_removed;
49+
bool m_shortRendering;
4950
};
5051

5152
} // namespace ConnectionsTree

src/modules/connections-tree/items/namespaceitem.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ QString NamespaceItem::getDisplayName() const {
3232
}
3333

3434
QByteArray NamespaceItem::getName() const {
35-
return m_fullPath.mid(
36-
m_fullPath.lastIndexOf(m_operations->getNamespaceSeparator()) + 1);
35+
qsizetype pos = m_fullPath.lastIndexOf(m_operations->getNamespaceSeparator());
36+
37+
if (pos >= 0) {
38+
return m_fullPath.mid(pos + m_operations->getNamespaceSeparator().size());
39+
} else {
40+
return m_fullPath;
41+
}
3742
}
3843

3944
bool NamespaceItem::isEnabled() const { return m_removed == false; }

src/qml/GlobalSettings.qml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@ Dialog {
180180
}
181181

182182
BoolOption {
183-
id: keySorting
183+
id: namespacedKeysShortName
184184

185185
Layout.fillWidth: true
186186
Layout.preferredHeight: 30
187187

188188
value: true
189-
label: qsTranslate("RDM","Enable key sorting in tree")
190-
description: qsTranslate("RDM","(Disable to improve treeview performance)")
189+
label: qsTranslate("RDM","Show only last part for namespaced keys")
191190
}
192191

193192
IntOption {
@@ -296,8 +295,8 @@ Dialog {
296295
id: globalSettings
297296
category: "app"
298297

299-
property alias reopenNamespacesOnReload: nsReload.value
300-
property alias enableKeySortingInTree: keySorting.value
298+
property alias reopenNamespacesOnReload: nsReload.value
299+
property alias namespacedKeysShortName: namespacedKeysShortName.value
301300
property alias liveUpdateKeysLimit: liveKeyLimit.value
302301
property alias liveUpdateInterval: liveUpdateInterval.value
303302
property alias appFont: appFont.value

src/resources/translations/rdm.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<context>
144144
<name>GlobalSettings</name>
145145
<message>
146-
<location filename="../../qml/GlobalSettings.qml" line="286"/>
146+
<location filename="../../qml/GlobalSettings.qml" line="285"/>
147147
<source>Cancel</source>
148148
<translation type="unfinished"></translation>
149149
</message>
@@ -312,7 +312,7 @@
312312
</message>
313313
<message>
314314
<location filename="../../modules/connections-tree/items/databaseitem.cpp" line="247"/>
315-
<location filename="../../modules/connections-tree/items/namespaceitem.cpp" line="136"/>
315+
<location filename="../../modules/connections-tree/items/namespaceitem.cpp" line="141"/>
316316
<source>Key was added</source>
317317
<translation type="unfinished"></translation>
318318
</message>
@@ -414,7 +414,7 @@
414414
</message>
415415
<message>
416416
<location filename="../../qml/value-editor/ValueTabs.qml" line="304"/>
417-
<location filename="../../modules/connections-tree/items/keyitem.cpp" line="130"/>
417+
<location filename="../../modules/connections-tree/items/keyitem.cpp" line="146"/>
418418
<source>Do you really want to delete this key?</source>
419419
<translation type="unfinished"></translation>
420420
</message>
@@ -858,10 +858,10 @@
858858
</message>
859859
<message>
860860
<location filename="../../qml/ConnectionSettignsDialog.qml" line="573"/>
861-
<location filename="../../qml/GlobalSettings.qml" line="274"/>
861+
<location filename="../../qml/GlobalSettings.qml" line="273"/>
862862
<location filename="../../qml/QuickStartDialog.qml" line="62"/>
863863
<location filename="../../qml/common/SaveToFileButton.qml" line="108"/>
864-
<location filename="../../qml/value-editor/editors/MultilineEditor.qml" line="606"/>
864+
<location filename="../../qml/value-editor/editors/MultilineEditor.qml" line="614"/>
865865
<source>OK</source>
866866
<translation type="unfinished"></translation>
867867
</message>
@@ -907,6 +907,11 @@
907907
<source>Size in bytes</source>
908908
<translation type="unfinished"></translation>
909909
</message>
910+
<message>
911+
<location filename="../../qml/GlobalSettings.qml" line="189"/>
912+
<source>Show only last part for namespaced keys</source>
913+
<translation type="unfinished"></translation>
914+
</message>
910915
<message>
911916
<location filename="../../qml/GlobalSettings.qml" line="81"/>
912917
<source>Use system proxy settings</source>
@@ -934,42 +939,36 @@
934939
</message>
935940
<message>
936941
<location filename="../../qml/GlobalSettings.qml" line="179"/>
937-
<location filename="../../qml/GlobalSettings.qml" line="190"/>
938942
<source>(Disable to improve treeview performance)</source>
939943
<translation type="unfinished"></translation>
940944
</message>
941945
<message>
942-
<location filename="../../qml/GlobalSettings.qml" line="189"/>
943-
<source>Enable key sorting in tree</source>
944-
<translation type="unfinished"></translation>
945-
</message>
946-
<message>
947-
<location filename="../../qml/GlobalSettings.qml" line="202"/>
946+
<location filename="../../qml/GlobalSettings.qml" line="201"/>
948947
<source>Live update maximum allowed keys</source>
949948
<translation type="unfinished"></translation>
950949
</message>
951950
<message>
952-
<location filename="../../qml/GlobalSettings.qml" line="214"/>
951+
<location filename="../../qml/GlobalSettings.qml" line="213"/>
953952
<source>Live update interval (in seconds)</source>
954953
<translation type="unfinished"></translation>
955954
</message>
956955
<message>
957-
<location filename="../../qml/GlobalSettings.qml" line="222"/>
956+
<location filename="../../qml/GlobalSettings.qml" line="221"/>
958957
<source>External Value View Formatters</source>
959958
<translation type="unfinished"></translation>
960959
</message>
961960
<message>
962-
<location filename="../../qml/GlobalSettings.qml" line="227"/>
961+
<location filename="../../qml/GlobalSettings.qml" line="226"/>
963962
<source>Formatters path: %0</source>
964963
<translation type="unfinished"></translation>
965964
</message>
966965
<message>
967-
<location filename="../../qml/GlobalSettings.qml" line="243"/>
966+
<location filename="../../qml/GlobalSettings.qml" line="242"/>
968967
<source>Name</source>
969968
<translation type="unfinished"></translation>
970969
</message>
971970
<message>
972-
<location filename="../../qml/GlobalSettings.qml" line="248"/>
971+
<location filename="../../qml/GlobalSettings.qml" line="247"/>
973972
<source>Version</source>
974973
<translation type="unfinished"></translation>
975974
</message>
@@ -1167,7 +1166,7 @@
11671166
<translation type="unfinished"></translation>
11681167
</message>
11691168
<message>
1170-
<location filename="../../qml/GlobalSettings.qml" line="258"/>
1169+
<location filename="../../qml/GlobalSettings.qml" line="257"/>
11711170
<location filename="../../qml/console/RedisConsole.qml" line="209"/>
11721171
<source>Description</source>
11731172
<translation type="unfinished"></translation>
@@ -1268,7 +1267,7 @@
12681267
<translation type="unfinished"></translation>
12691268
</message>
12701269
<message>
1271-
<location filename="../../qml/GlobalSettings.qml" line="252"/>
1270+
<location filename="../../qml/GlobalSettings.qml" line="251"/>
12721271
<location filename="../../qml/server-info/ServerInfoTabs.qml" line="424"/>
12731272
<source>Command</source>
12741273
<translation type="unfinished"></translation>
@@ -1396,12 +1395,12 @@
13961395
<translation type="unfinished"></translation>
13971396
</message>
13981397
<message>
1399-
<location filename="../../qml/value-editor/editors/MultilineEditor.qml" line="602"/>
1398+
<location filename="../../qml/value-editor/editors/MultilineEditor.qml" line="610"/>
14001399
<source>Binary value is too large to display</source>
14011400
<translation type="unfinished"></translation>
14021401
</message>
14031402
<message>
1404-
<location filename="../../qml/value-editor/editors/MultilineEditor.qml" line="614"/>
1403+
<location filename="../../qml/value-editor/editors/MultilineEditor.qml" line="622"/>
14051404
<source>Save value to file: </source>
14061405
<translation type="unfinished"></translation>
14071406
</message>
@@ -1482,12 +1481,12 @@
14821481
<translation type="unfinished"></translation>
14831482
</message>
14841483
<message>
1485-
<location filename="../../modules/connections-tree/items/abstractnamespaceitem.cpp" line="129"/>
1484+
<location filename="../../modules/connections-tree/items/abstractnamespaceitem.cpp" line="145"/>
14861485
<source>Your redis-server doesn&apos;t support &lt;a href=&apos;https://redis.io/commands/memory-usage&apos;&gt;&lt;b&gt;MEMORY&lt;/b&gt;&lt;/a&gt; commands.</source>
14871486
<translation type="unfinished"></translation>
14881487
</message>
14891488
<message>
1490-
<location filename="../../modules/connections-tree/items/namespaceitem.cpp" line="131"/>
1489+
<location filename="../../modules/connections-tree/items/namespaceitem.cpp" line="136"/>
14911490
<source>Key was added. Do you want to reload keys in selected namespace?</source>
14921491
<translation type="unfinished"></translation>
14931492
</message>

0 commit comments

Comments
 (0)