Skip to content

Commit 7bf03d3

Browse files
authored
Merge pull request #871 from deXol/developBLEImplementNodes
[BLE] Adjust Notes UI, fix infinite loop after delete on Windows
2 parents e4b1c73 + 9cea55c commit 7bf03d3

File tree

5 files changed

+73
-26
lines changed

5 files changed

+73
-26
lines changed

img/note.png

2.67 KB
Loading

src/FilesManagement.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,18 @@ void FilesManagement::onFileDeleted(bool success, const QString& file)
354354
updateButtonsUI();
355355
if (success)
356356
{
357-
wsClient->sendListFilesCacheRequest();
357+
// Remove delete file from cache and reload model
358+
auto& fileCache = wsClient->getFilesCache();
359+
for (int i = 0; i < fileCache.size(); ++i)
360+
{
361+
QJsonObject jsonObject = fileCache[i].toObject();
362+
if (jsonObject.value("name").toString() == file)
363+
{
364+
fileCache.removeAt(i);
365+
break;
366+
}
367+
}
368+
loadFilesCacheModel(true);
358369
QMessageBox::information(this, tr("File Deleted"), tr("'%1' file was deleted successfully!").arg(file));
359370
}
360371
else

src/NotesManagement.cpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ NotesManagement::~NotesManagement()
3737
void NotesManagement::setWsClient(WSClient *c)
3838
{
3939
wsClient = c;
40-
connect(wsClient, &WSClient::notesFetched, this, &NotesManagement::loadNodes);
40+
connect(wsClient, &WSClient::notesFetched, this, &NotesManagement::loadNotes);
4141
connect(wsClient, &WSClient::noteSaved, this, &NotesManagement::onNoteSaved);
4242
connect(wsClient, &WSClient::noteDeleted, this, &NotesManagement::onNoteDeleted);
4343
}
4444

45-
void NotesManagement::loadNodes(const QJsonArray &notes)
45+
void NotesManagement::loadNotes(const QJsonArray &notes)
4646
{
4747
clearNotes();
4848
for (auto noteObj : notes)
@@ -51,17 +51,28 @@ void NotesManagement::loadNodes(const QJsonArray &notes)
5151
QString noteName = jsonObject.value("name").toString();
5252

5353
addNewIcon(noteName);
54+
m_noteList.append(noteName);
55+
}
56+
}
57+
58+
void NotesManagement::refreshNotes()
59+
{
60+
clearNotes(false);
61+
for (const auto& noteName : m_noteList)
62+
{
63+
addNewIcon(noteName);
5464
}
5565
}
5666

5767
void NotesManagement::addNewIcon(const QString &name)
5868
{
59-
auto* vertLayout = new QVBoxLayout();
69+
70+
auto* vertIconNameLayout = new QVBoxLayout();
6071
auto* labelIcon = new ClickableLabel();
6172
labelIcon->setAlignment(Qt::AlignCenter);
6273
labelIcon->setPixmap(QString::fromUtf8(":/note.png"));
63-
labelIcon->setMaximumSize(200,200);
64-
labelIcon->setPixmap(labelIcon->pixmap()->scaled(200,200, Qt::KeepAspectRatio));
74+
labelIcon->setMaximumSize(160,200);
75+
labelIcon->setPixmap(labelIcon->pixmap()->scaled(160,200, Qt::KeepAspectRatio));
6576
labelIcon->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
6677
labelIcon->setAlignment(Qt::AlignCenter);
6778

@@ -71,8 +82,17 @@ void NotesManagement::addNewIcon(const QString &name)
7182
emit changeNote();
7283
});
7384

85+
vertIconNameLayout->addWidget(labelIcon);
86+
87+
auto* labelName = new QLabel();
88+
labelName->setAlignment(Qt::AlignCenter);
89+
labelName->setText(name);
90+
91+
vertIconNameLayout->addWidget(labelName);
92+
vertIconNameLayout->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
93+
7494
auto* iconHorizontalLayout = new QHBoxLayout();
75-
iconHorizontalLayout->addWidget(labelIcon);
95+
iconHorizontalLayout->addItem(vertIconNameLayout);
7696

7797
QToolButton *buttonRemove = new QToolButton;
7898
buttonRemove->setToolButtonStyle(Qt::ToolButtonIconOnly);
@@ -90,36 +110,36 @@ void NotesManagement::addNewIcon(const QString &name)
90110

91111
auto* removeLayout = new QVBoxLayout();
92112
removeLayout->addWidget(buttonRemove);
93-
removeLayout->addItem(new QSpacerItem(20, 120, QSizePolicy::Minimum, QSizePolicy::Preferred));
94-
iconHorizontalLayout->addItem(removeLayout);
95-
96-
vertLayout->addItem(iconHorizontalLayout);
113+
removeLayout->addItem(new QSpacerItem(20, 60, QSizePolicy::Minimum, QSizePolicy::Expanding));
114+
iconHorizontalLayout->addLayout(removeLayout);
97115

98-
auto* labelName = new QLabel();
99-
labelName->setAlignment(Qt::AlignCenter);
100-
labelName->setText(name);
101-
102-
vertLayout->addWidget(labelName);
103-
vertLayout->addItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));
116+
auto* vertLayout = new QVBoxLayout();
117+
vertLayout->addLayout(iconHorizontalLayout);
104118

105119
int row = ui->gridLayoutNotes->rowCount() - 1;
106120
if (m_actColumn == 4)
107121
{
108122
m_actColumn = 0;
109123
++row;
110124
}
111-
ui->gridLayoutNotes->addLayout(vertLayout, row, m_actColumn++, 1, 1);
112-
m_noteList.append(name);
125+
126+
QWidget *iconWidget = new QWidget();
127+
iconWidget->setLayout(vertLayout);
128+
iconWidget->setMaximumWidth(190);
129+
ui->gridLayoutNotes->addWidget(iconWidget, row, m_actColumn++, 1, 1);
113130
}
114131

115-
void NotesManagement::clearNotes()
132+
void NotesManagement::clearNotes(bool clearNoteList /*= true*/)
116133
{
117134
for (int i = 0; i < ui->gridLayoutNotes->rowCount(); ++i)
118135
{
119136
GridLayoutUtil::removeRow(ui->gridLayoutNotes, i);
120137
}
121138
m_actColumn = 0;
122-
m_noteList.clear();
139+
if (clearNoteList)
140+
{
141+
m_noteList.clear();
142+
}
123143
}
124144

125145
void NotesManagement::on_pushButtonAddNote_clicked()
@@ -192,6 +212,7 @@ void NotesManagement::onNoteSaved(const QString &note, bool success)
192212
if (m_isNewFile)
193213
{
194214
addNewIcon(note);
215+
m_noteList.append(note);
195216
}
196217
}
197218
else
@@ -238,7 +259,7 @@ void NotesManagement::onEditingFinished()
238259
void NotesManagement::on_textEditNote_textChanged()
239260
{
240261
QString note = ui->textEditNote->toPlainText();
241-
if (note == m_noteContentClone || note.isEmpty() || !m_validNoteName)
262+
if (note == m_noteContentClone || note.isEmpty() || (m_isNewFile && !m_validNoteName))
242263
{
243264
ui->pushButtonSave->hide();
244265
}
@@ -254,8 +275,8 @@ void NotesManagement::onNoteDeleted(bool success, const QString &note)
254275
emit updateTabs();
255276
if (success)
256277
{
257-
clearNotes();
258-
wsClient->sendFetchNotes();
278+
m_noteList.removeOne(note);
279+
refreshNotes();
259280
QMessageBox::information(this, tr("Note Deleted"), tr("'%1' note was deleted successfully!").arg(note));
260281
}
261282
else

src/NotesManagement.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ private slots:
4545
void onNoteDeleted(bool success, const QString& note);
4646

4747
private:
48-
void loadNodes(const QJsonArray& notes);
48+
void loadNotes(const QJsonArray& notes);
49+
void refreshNotes();
4950
void addNewIcon(const QString& name);
50-
void clearNotes();
51+
void clearNotes(bool clearNoteList = true);
5152

5253

5354
int m_actColumn = 0;

src/NotesManagement.ui

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ border-right: none;
8787
</rect>
8888
</property>
8989
<layout class="QVBoxLayout" name="verticalLayout_4">
90+
<property name="leftMargin">
91+
<number>0</number>
92+
</property>
93+
<property name="rightMargin">
94+
<number>0</number>
95+
</property>
9096
<item>
9197
<layout class="QGridLayout" name="gridLayoutNotes"/>
9298
</item>
@@ -138,9 +144,17 @@ border-right: none;
138144
<height>16777215</height>
139145
</size>
140146
</property>
147+
<property name="font">
148+
<font>
149+
<pointsize>16</pointsize>
150+
</font>
151+
</property>
141152
<property name="frame">
142153
<bool>false</bool>
143154
</property>
155+
<property name="alignment">
156+
<set>Qt::AlignCenter</set>
157+
</property>
144158
<property name="readOnly">
145159
<bool>true</bool>
146160
</property>

0 commit comments

Comments
 (0)