valuetreeeditor drag&drop abd recent files support
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QActionGroup>
|
||||
#include <QFileInfo>
|
||||
#include <QMetaEnum>
|
||||
#include <QMimeData>
|
||||
#include <pifile.h>
|
||||
#include <pijson.h>
|
||||
#include <pivaluetree.h>
|
||||
@@ -14,6 +15,8 @@
|
||||
|
||||
MainWindow::MainWindow(QWidget * parent): EMainWindow(parent), Ui::MainWindow() {
|
||||
setupUi(this);
|
||||
setRecentMenu(menuOpen_recent);
|
||||
setAcceptDrops(true);
|
||||
session.setFile(QAD::userPath(QAD::ltConfig, "session_valuetreeeditor"));
|
||||
session.addEntry(this);
|
||||
session.load();
|
||||
@@ -91,6 +94,34 @@ void MainWindow::changeEvent(QEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::dragEnterEvent(QDragEnterEvent * e) {
|
||||
if (!e->mimeData()) return;
|
||||
QString str = e->mimeData()->text();
|
||||
if (str.isEmpty()) return;
|
||||
static QStringList exts({"conf", "ini", "json", "bin"});
|
||||
if (exts.contains(QFileInfo(str).suffix().toLower().trimmed())) {
|
||||
e->accept();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::dropEvent(QDropEvent * e) {
|
||||
if (!e->mimeData()) return;
|
||||
auto path = QUrl(e->mimeData()->text()).toLocalFile();
|
||||
if (load(path)) addToRecent(path);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadingSession(QPIConfig & conf) {
|
||||
setRecentFiles(conf.getValue("recent files").toStringList());
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::savingSession(QPIConfig & conf) {
|
||||
conf.setValue("recent files", recentFiles());
|
||||
}
|
||||
|
||||
|
||||
QString MainWindow::loadFilter() {
|
||||
return "All types(*.conf *.ini *.json *.bin);;INI format(*.conf *.ini);;JSON(*.json);;Binary(*.bin)";
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ public:
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e) override;
|
||||
void dragEnterEvent(QDragEnterEvent * e) override;
|
||||
void dropEvent(QDropEvent * e) override;
|
||||
|
||||
void loadingSession(QPIConfig & conf) override;
|
||||
void savingSession(QPIConfig & conf) override;
|
||||
QString loadFilter() override;
|
||||
QString saveFilter() override { return loadFilter(); }
|
||||
|
||||
|
||||
@@ -44,12 +44,12 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>444</height>
|
||||
<height>437</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="PIValueTreeEdit" name="widget" native="true"/>
|
||||
<widget class="PIValueTreeEdit" name="widget"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
@@ -91,15 +91,25 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>780</width>
|
||||
<height>31</height>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuOpen_recent">
|
||||
<property name="title">
|
||||
<string>Open recent</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../libs/widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/document-open-recent.png</normaloff>:/icons/document-open-recent.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="actionNew"/>
|
||||
<addaction name="actionOpen"/>
|
||||
<addaction name="menuOpen_recent"/>
|
||||
<addaction name="actionSave"/>
|
||||
<addaction name="actionSaveAs"/>
|
||||
</widget>
|
||||
@@ -152,7 +162,7 @@
|
||||
</action>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
<iconset resource="../../libs/widgets/qad_widgets.qrc">
|
||||
<iconset resource="../../libs/qglview/qglview.qrc">
|
||||
<normaloff>:/icons/document-new.png</normaloff>:/icons/document-new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -164,7 +174,7 @@
|
||||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="icon">
|
||||
<iconset resource="../../../cd/utils/pult/cdpult.qrc">
|
||||
<iconset resource="../../libs/graphic_analysis/qad_graphic_analysis.qrc">
|
||||
<normaloff>:/icons/dialog-information.png</normaloff>:/icons/dialog-information.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
@@ -201,8 +211,9 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../cd/utils/pult/cdpult.qrc"/>
|
||||
<include location="../../libs/blockview/qad_blockview.qrc"/>
|
||||
<include location="../../libs/graphic_analysis/qad_graphic_analysis.qrc"/>
|
||||
<include location="../../libs/qglview/qglview.qrc"/>
|
||||
<include location="../../libs/widgets/qad_widgets.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
|
||||
Reference in New Issue
Block a user