mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
update forcely in VFileList to repaint
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
6b59886847
commit
c7e631fa02
@ -3,6 +3,7 @@
|
||||
#include "vfilelist.h"
|
||||
#include "vconfigmanager.h"
|
||||
#include "dialog/vnewfiledialog.h"
|
||||
#include "vnote.h"
|
||||
|
||||
VFileList::VFileList(QWidget *parent)
|
||||
: QListWidget(parent)
|
||||
@ -96,14 +97,19 @@ QListWidgetItem* VFileList::insertFileListItem(QJsonObject fileJson, bool atFron
|
||||
} else {
|
||||
addItem(item);
|
||||
}
|
||||
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
||||
update();
|
||||
qDebug() << "add new list item:" << fileJson["name"].toString();
|
||||
return item;
|
||||
}
|
||||
|
||||
void VFileList::removeFileListItem(QListWidgetItem *item)
|
||||
{
|
||||
// Qt ensures it will be removed from QListWidget automatically
|
||||
setCurrentRow(-1);
|
||||
removeItemWidget(item);
|
||||
delete item;
|
||||
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
||||
update();
|
||||
}
|
||||
|
||||
void VFileList::newFile()
|
||||
@ -125,13 +131,15 @@ void VFileList::newFile()
|
||||
}
|
||||
QListWidgetItem *newItem = createFileAndUpdateList(name, description);
|
||||
if (newItem) {
|
||||
this->setCurrentItem(newItem);
|
||||
setCurrentItem(newItem);
|
||||
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
||||
update();
|
||||
|
||||
// Open this file in edit mode
|
||||
QJsonObject itemJson = newItem->data(Qt::UserRole).toJsonObject();
|
||||
Q_ASSERT(!itemJson.isEmpty());
|
||||
itemJson["path"] = QDir::cleanPath(QDir(rootPath).filePath(relativePath));
|
||||
itemJson["mode"] = 1;
|
||||
itemJson["mode"] = OpenFileMode::Edit;
|
||||
emit fileCreated(itemJson);
|
||||
}
|
||||
}
|
||||
@ -277,9 +285,12 @@ void VFileList::handleItemClicked(QListWidgetItem *currentItem)
|
||||
emit fileClicked(QJsonObject());
|
||||
return;
|
||||
}
|
||||
// Qt seems not to update the QListWidget correctly. Manually force it to repaint.
|
||||
update();
|
||||
QJsonObject itemJson = currentItem->data(Qt::UserRole).toJsonObject();
|
||||
Q_ASSERT(!itemJson.isEmpty());
|
||||
itemJson["path"] = QDir::cleanPath(QDir(rootPath).filePath(relativePath));
|
||||
itemJson["mode"] = OpenFileMode::Read;
|
||||
emit fileClicked(itemJson);
|
||||
}
|
||||
|
||||
|
2
vnote.h
2
vnote.h
@ -8,6 +8,8 @@
|
||||
#include <QObject>
|
||||
#include "vnotebook.h"
|
||||
|
||||
enum OpenFileMode {Read = 0, Edit};
|
||||
|
||||
class VNote : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -49,7 +49,7 @@ void VTabWidget::openFile(QJsonObject fileJson)
|
||||
|
||||
QString path = fileJson["path"].toString();
|
||||
QString name = fileJson["name"].toString();
|
||||
int mode = 0;
|
||||
int mode = OpenFileMode::Read;
|
||||
if (fileJson.contains("mode")) {
|
||||
mode = fileJson["mode"].toInt();
|
||||
}
|
||||
@ -64,7 +64,7 @@ void VTabWidget::openFile(QJsonObject fileJson)
|
||||
|
||||
out:
|
||||
setCurrentIndex(idx);
|
||||
if (mode == 1) {
|
||||
if (mode == OpenFileMode::Edit) {
|
||||
VEditor *editor = dynamic_cast<VEditor *>(currentWidget());
|
||||
Q_ASSERT(editor);
|
||||
editor->editFile();
|
||||
|
Loading…
x
Reference in New Issue
Block a user