From 34c15538b2c96bdca366675a8fdcb9656155dcf4 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 22 Dec 2019 18:37:56 +0100 Subject: [PATCH] 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 --- src/EditDialog.cpp | 37 ++++++++++++++++++++++--------- src/EditDialog.h | 2 +- src/EditDialog.ui | 43 ++++++++++++++++++++++++++++++++++++ src/TableBrowser.cpp | 2 +- src/icons/document-link.png | Bin 0 -> 853 bytes src/icons/icons.qrc | 1 + 6 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 src/icons/document-link.png diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 9895a49b..e79a26c3 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -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); + } } } } diff --git a/src/EditDialog.h b/src/EditDialog.h index 50a0f2d4..783ed935 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -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(); diff --git a/src/EditDialog.ui b/src/EditDialog.ui index b2c4838c..466fda33 100644 --- a/src/EditDialog.ui +++ b/src/EditDialog.ui @@ -421,6 +421,33 @@ Errors are indicated with a red squiggle underline. The value is interpreted as a file or URL and opened in the default application or web browser. + + + + :/icons/document_link:/icons/document_link + + + Save file reference... + + + Save reference to file + + + + + + :/icons/document_open:/icons/document_open + + + &Import... + + + Import from file + + + Opens a file dialog used to import any kind of data to this database cell. + + comboMode @@ -623,6 +650,22 @@ Errors are indicated with a red squiggle underline. + + actionImportInMenu + triggered() + EditDialog + importData() + + + -1 + -1 + + + 308 + 190 + + + importData() diff --git a/src/TableBrowser.cpp b/src/TableBrowser.cpp index 0f3bfc67..e2a95066 100644 --- a/src/TableBrowser.cpp +++ b/src/TableBrowser.cpp @@ -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); diff --git a/src/icons/document-link.png b/src/icons/document-link.png new file mode 100644 index 0000000000000000000000000000000000000000..06df131a5173c954903c3a099293ac65175a5a30 GIT binary patch literal 853 zcmV-b1FHOqP)3oaG_jEeqnj=&;@T|T z1zV+5iny?drV6tcBdrT1>7*rE8l+81wK_Aoom@$#F%xI*IrkhF$xN{LF1~X(9NzCa z?{|a;^!nIHO+;L4t%wK!j^l`kkVqt!wl-@o=5o2PabG4UCofoQUuzuP`TchKiwj@k zI1VC0!$d^5`1M6*X1@Is>-J7hPj3Kt#+Yn2o851WA&z6tp8J?Wp+LP}2f$iO9LE@A z7(X%2{YvH0{I&et=;-LPxm@laPbp=!)`Ve**1Cbr{MGsYJgvX44}epr-VygR?}^#D zpUwg&cMKF-Ym7072)^$#G&qE{wn^c-ZnMci|A1V{&mIR(dRl9vbxa(`O#;vJxctK< z;y7*+ymVxcD2jHH17nN>;3=hS6h%#gowRx7=&Q}{53X&kZD26~GBGhx9vK;FKQpsI zZ5sd!ShKrt)NO;^TwKQ~d0K0fQdA@O@V#OFPtq*AinQVVbC1_vgdgcZF{Nw`W*)|?c7`ai+!CvU?b}(rHs}J0Zgp9`^)$Aq+O1` z^(NJ7m7ZdeAFs?)6Q4Imv-k;*AP87kSYYqp1$M?5BjRym;VLclkRyZRd~o_af86?+ zuFg(+dwU6jfRE0cW+e#796HRPmcQfzK+5{4n4od1;c;Vhx9aA5yFJP|R*7zA+lq*%GP%)yM}_S{!sVy331NG6j2 zRI63Q8cO+ZNcRm2yE{xC(AM#2pqTU+Ag7oKC!a6jd8ndRkWT3TA@?(U|e zql2w_OtEy6((1aB;iK8l*E7f7-k!0+t*?=)%+l47qSf~SxLM5*JFPs~_8Wqw7DcR- f*G$EK{M~;6{eOW-X@?UM00000NkvXXu0mjfC9RVR literal 0 HcmV?d00001 diff --git a/src/icons/icons.qrc b/src/icons/icons.qrc index 7cd15d40..fb409427 100644 --- a/src/icons/icons.qrc +++ b/src/icons/icons.qrc @@ -99,5 +99,6 @@ style_delete.png style_add.png application_link.png + document-link.png