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
This commit is contained in:
mgrojo
2019-12-22 18:37:56 +01:00
parent 99bc7536ed
commit 34c15538b2
6 changed files with 73 additions and 12 deletions

View File

@@ -20,6 +20,7 @@
#include <QClipboard>
#include <QTextDocument>
#include <QDesktopServices>
#include <QMenu>
#include <Qsci/qsciscintilla.h>
#include <json.hpp>
@@ -66,6 +67,16 @@ EditDialog::EditDialog(QWidget* parent)
ui->editorBinary->addAction(ui->actionPrint);
ui->editorBinary->addAction(ui->actionCopyHexAscii);
// Set up popup menus
QMenu* popupImportFileMenu = new QMenu(this);
popupImportFileMenu->addAction(ui->actionImportInMenu);
popupImportFileMenu->addAction(ui->actionImportAsLink);
ui->actionImport->setMenu(popupImportFileMenu);
connect(ui->actionImportAsLink, &QAction::triggered, this, [&]() {
importData(/* asLink */ true);
});
connect(ui->actionOpenInApp, &QAction::triggered, this, [&]() {
QUrl url;
switch (dataSource) {
@@ -330,7 +341,7 @@ void EditDialog::loadData(const QByteArray& bArrdata)
}
}
void EditDialog::importData()
void EditDialog::importData(bool asLink)
{
// Get list of supported image file formats to include them in the file dialog filter
QString image_formats;
@@ -383,16 +394,22 @@ void EditDialog::importData()
);
if(QFile::exists(fileName))
{
QFile file(fileName);
if(file.open(QIODevice::ReadOnly))
{
QByteArray d = file.readAll();
loadData(d);
file.close();
if(asLink) {
QByteArray fileNameBa = fileName.toUtf8();
loadData(fileNameBa);
updateCellInfoAndMode(fileNameBa);
} else {
QFile file(fileName);
if(file.open(QIODevice::ReadOnly))
{
QByteArray d = file.readAll();
loadData(d);
file.close();
// Update the cell data info in the bottom left of the Edit Cell
// and update mode (if required) to the just imported data type.
updateCellInfoAndMode(d);
// Update the cell data info in the bottom left of the Edit Cell
// and update mode (if required) to the just imported data type.
updateCellInfoAndMode(d);
}
}
}
}

View File

@@ -32,7 +32,7 @@ protected:
void showEvent(QShowEvent* ev) override;
private slots:
void importData();
void importData(bool asLink = false);
void exportData();
void setNull();
void updateApplyButton();

View File

@@ -421,6 +421,33 @@ Errors are indicated with a red squiggle underline.</string>
<string>The value is interpreted as a file or URL and opened in the default application or web browser.</string>
</property>
</action>
<action name="actionImportAsLink">
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/document_link</normaloff>:/icons/document_link</iconset>
</property>
<property name="text">
<string>Save file reference...</string>
</property>
<property name="toolTip">
<string>Save reference to file</string>
</property>
</action>
<action name="actionImportInMenu">
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/document_open</normaloff>:/icons/document_open</iconset>
</property>
<property name="text">
<string>&amp;Import...</string>
</property>
<property name="toolTip">
<string>Import from file</string>
</property>
<property name="whatsThis">
<string>Opens a file dialog used to import any kind of data to this database cell.</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>comboMode</tabstop>
@@ -623,6 +650,22 @@ Errors are indicated with a red squiggle underline.</string>
</hint>
</hints>
</connection>
<connection>
<sender>actionImportInMenu</sender>
<signal>triggered()</signal>
<receiver>EditDialog</receiver>
<slot>importData()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
<y>190</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>importData()</slot>

View File

@@ -42,7 +42,7 @@ TableBrowser::TableBrowser(QWidget* parent) :
ui->editGlobalFilter->setPlaceholderText(tr("Filter in all columns"));
ui->editGlobalFilter->setConditionFormatContextMenuEnabled(false);
// Set uo popup menus
// Set up popup menus
popupNewRecordMenu = new QMenu(this);
popupNewRecordMenu->addAction(ui->newRecordAction);
popupNewRecordMenu->addAction(ui->insertValuesAction);

BIN
src/icons/document-link.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 853 B

View File

@@ -99,5 +99,6 @@
<file alias="clear_cond_formats">style_delete.png</file>
<file alias="add_cond_format">style_add.png</file>
<file alias="open_in_app">application_link.png</file>
<file alias="document_link">document-link.png</file>
</qresource>
</RCC>