Skip to content

Commit 34c1553

Browse files
committed
Action to select a file to be inserted as a reference
The "Import file" in the Edit Dialog dock is converted to a menu (after long click) with a new action for selecting a file to be imported as a reference in the cell. Then this filename reference can be used to open the file using the default application with the present "Open in Application" action. (In Linux, paths containing non-US-ASCII are known not to work. This seems a bug in Qt QUrl class). New icon composed from our document-open.png and link.png from Silk icon set. Related issue #1597
1 parent 99bc753 commit 34c1553

File tree

6 files changed

+74
-13
lines changed

6 files changed

+74
-13
lines changed

src/EditDialog.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <QClipboard>
2121
#include <QTextDocument>
2222
#include <QDesktopServices>
23+
#include <QMenu>
2324

2425
#include <Qsci/qsciscintilla.h>
2526
#include <json.hpp>
@@ -66,6 +67,16 @@ EditDialog::EditDialog(QWidget* parent)
6667
ui->editorBinary->addAction(ui->actionPrint);
6768
ui->editorBinary->addAction(ui->actionCopyHexAscii);
6869

70+
// Set up popup menus
71+
QMenu* popupImportFileMenu = new QMenu(this);
72+
popupImportFileMenu->addAction(ui->actionImportInMenu);
73+
popupImportFileMenu->addAction(ui->actionImportAsLink);
74+
ui->actionImport->setMenu(popupImportFileMenu);
75+
76+
connect(ui->actionImportAsLink, &QAction::triggered, this, [&]() {
77+
importData(/* asLink */ true);
78+
});
79+
6980
connect(ui->actionOpenInApp, &QAction::triggered, this, [&]() {
7081
QUrl url;
7182
switch (dataSource) {
@@ -330,7 +341,7 @@ void EditDialog::loadData(const QByteArray& bArrdata)
330341
}
331342
}
332343

333-
void EditDialog::importData()
344+
void EditDialog::importData(bool asLink)
334345
{
335346
// Get list of supported image file formats to include them in the file dialog filter
336347
QString image_formats;
@@ -383,16 +394,22 @@ void EditDialog::importData()
383394
);
384395
if(QFile::exists(fileName))
385396
{
386-
QFile file(fileName);
387-
if(file.open(QIODevice::ReadOnly))
388-
{
389-
QByteArray d = file.readAll();
390-
loadData(d);
391-
file.close();
392-
393-
// Update the cell data info in the bottom left of the Edit Cell
394-
// and update mode (if required) to the just imported data type.
395-
updateCellInfoAndMode(d);
397+
if(asLink) {
398+
QByteArray fileNameBa = fileName.toUtf8();
399+
loadData(fileNameBa);
400+
updateCellInfoAndMode(fileNameBa);
401+
} else {
402+
QFile file(fileName);
403+
if(file.open(QIODevice::ReadOnly))
404+
{
405+
QByteArray d = file.readAll();
406+
loadData(d);
407+
file.close();
408+
409+
// Update the cell data info in the bottom left of the Edit Cell
410+
// and update mode (if required) to the just imported data type.
411+
updateCellInfoAndMode(d);
412+
}
396413
}
397414
}
398415
}

src/EditDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public slots:
3232
void showEvent(QShowEvent* ev) override;
3333

3434
private slots:
35-
void importData();
35+
void importData(bool asLink = false);
3636
void exportData();
3737
void setNull();
3838
void updateApplyButton();

src/EditDialog.ui

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,33 @@ Errors are indicated with a red squiggle underline.</string>
421421
<string>The value is interpreted as a file or URL and opened in the default application or web browser.</string>
422422
</property>
423423
</action>
424+
<action name="actionImportAsLink">
425+
<property name="icon">
426+
<iconset resource="icons/icons.qrc">
427+
<normaloff>:/icons/document_link</normaloff>:/icons/document_link</iconset>
428+
</property>
429+
<property name="text">
430+
<string>Save file reference...</string>
431+
</property>
432+
<property name="toolTip">
433+
<string>Save reference to file</string>
434+
</property>
435+
</action>
436+
<action name="actionImportInMenu">
437+
<property name="icon">
438+
<iconset resource="icons/icons.qrc">
439+
<normaloff>:/icons/document_open</normaloff>:/icons/document_open</iconset>
440+
</property>
441+
<property name="text">
442+
<string>&amp;Import...</string>
443+
</property>
444+
<property name="toolTip">
445+
<string>Import from file</string>
446+
</property>
447+
<property name="whatsThis">
448+
<string>Opens a file dialog used to import any kind of data to this database cell.</string>
449+
</property>
450+
</action>
424451
</widget>
425452
<tabstops>
426453
<tabstop>comboMode</tabstop>
@@ -623,6 +650,22 @@ Errors are indicated with a red squiggle underline.</string>
623650
</hint>
624651
</hints>
625652
</connection>
653+
<connection>
654+
<sender>actionImportInMenu</sender>
655+
<signal>triggered()</signal>
656+
<receiver>EditDialog</receiver>
657+
<slot>importData()</slot>
658+
<hints>
659+
<hint type="sourcelabel">
660+
<x>-1</x>
661+
<y>-1</y>
662+
</hint>
663+
<hint type="destinationlabel">
664+
<x>308</x>
665+
<y>190</y>
666+
</hint>
667+
</hints>
668+
</connection>
626669
</connections>
627670
<slots>
628671
<slot>importData()</slot>

src/TableBrowser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ TableBrowser::TableBrowser(QWidget* parent) :
4242
ui->editGlobalFilter->setPlaceholderText(tr("Filter in all columns"));
4343
ui->editGlobalFilter->setConditionFormatContextMenuEnabled(false);
4444

45-
// Set uo popup menus
45+
// Set up popup menus
4646
popupNewRecordMenu = new QMenu(this);
4747
popupNewRecordMenu->addAction(ui->newRecordAction);
4848
popupNewRecordMenu->addAction(ui->insertValuesAction);

src/icons/document-link.png

853 Bytes
Loading

src/icons/icons.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@
9999
<file alias="clear_cond_formats">style_delete.png</file>
100100
<file alias="add_cond_format">style_add.png</file>
101101
<file alias="open_in_app">application_link.png</file>
102+
<file alias="document_link">document-link.png</file>
102103
</qresource>
103104
</RCC>

0 commit comments

Comments
 (0)