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