1 /**********************************************************************************************
2 Copyright (C) 2018 Oliver Eichler <oliver.eichler@gmx.de>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 **********************************************************************************************/
18
19 #include "CMainWindow.h"
20 #include "helpers/CSettings.h"
21 #include "items/CItemMap.h"
22 #include "tool/CToolExport.h"
23
24 #include <QtWidgets>
25
CToolExport(QWidget * parent)26 CToolExport::CToolExport(QWidget* parent)
27 : IToolGui(parent)
28 {
29 setupUi(this);
30 setObjectName(tr("Export Maps"));
31 lineTragetFile->addAction(actionTargetFilename, QLineEdit::TrailingPosition);
32
33 labelHelp->setText(tr("To use the maps on your device you have to export them to the proprietary "
34 "format supported by the device. Depending on the device this can vary from "
35 "a single layer map to a map stack with maps of different scale."
36 ));
37
38 labelHelp->setVisible(CMainWindow::self().showToolHelp()->isChecked());
39 connect(CMainWindow::self().showToolHelp(), &QAction::toggled, labelHelp, &QLabel::setVisible);
40
41 labelNote->setText(tr("Note: This tool will use all files in the list as a input. "
42 "This will only work if all files have the same projection."
43 ));
44 labelNote->setVisible(CMainWindow::self().showToolHelp()->isChecked());
45 connect(CMainWindow::self().showToolHelp(), &QAction::toggled, labelNote, &QLabel::setVisible);
46
47 connect(itemTree, &CItemTreeWidget::sigSelectionChanged, this, &CToolExport::slotMapSelectionChanged);
48 connect(itemTree, &CItemTreeWidget::sigChanged, this, &CToolExport::slotSomethingChanged);
49 connect(lineTragetFile, &QLineEdit::textChanged, this, &CToolExport::slotSomethingChanged);
50 connect(actionTargetFilename, &QAction::triggered, this, &CToolExport::slotSelectFilename);
51 connect(comboExport, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), stackedWidget, &QStackedWidget::setCurrentIndex);
52
53 connect(pushStart, &QPushButton::clicked, this, &CToolExport::slotStart);
54 connect(pushCancel, &QPushButton::clicked, &CShell::self(), &CShell::slotCancel);
55 connect(&CShell::self(), &CShell::sigFinishedJob, this, &CToolExport::slotFinished);
56
57
58 CToolExport::setupChanged();
59
60 SETTINGS;
61 cfg.beginGroup("ToolExport");
62 itemTree->loadSettings(cfg);
63
64 comboExport->setCurrentIndex(cfg.value("current", 0).toInt());
65 lineTragetFile->setText(cfg.value("targetFile", "").toString());
66 cfg.endGroup();
67 }
68
~CToolExport()69 CToolExport::~CToolExport()
70 {
71 SETTINGS;
72 cfg.beginGroup("ToolExport");
73 cfg.remove("");
74 itemTree->saveSettings(cfg);
75 cfg.setValue("current", comboExport->currentIndex());
76 cfg.setValue("targetFile", lineTragetFile->text());
77 cfg.endGroup();
78 }
79
80
setupChanged()81 void CToolExport::setupChanged()
82 {
83 bool hasMap2jnx = !IAppSetup::self().getQmtmap2jnx().isEmpty();
84 labelNoMap2jnx->setVisible(!hasMap2jnx);
85
86 frame->setVisible(hasMap2jnx);
87 }
88
slotMapSelectionChanged()89 void CToolExport::slotMapSelectionChanged()
90 {
91 CMainWindow::self().getCanvas()->slotTriggerCompleteUpdate(CCanvas::eRedrawAll);
92 slotSomethingChanged();
93 }
94
95
slotSomethingChanged()96 void CToolExport::slotSomethingChanged()
97 {
98 bool ok = true;
99 if(itemTree->topLevelItemCount() == 0)
100 {
101 ok = false;
102 }
103 if(lineTragetFile->text().isEmpty())
104 {
105 ok = false;
106 }
107 pushStart->setEnabled(ok);
108 }
109
slotSelectFilename()110 void CToolExport::slotSelectFilename()
111 {
112 SETTINGS;
113 QString path = cfg.value("Path/mapInput", QDir::homePath()).toString();
114 QString filename = QFileDialog::getSaveFileName(this, tr("Select filename..."), path);
115 if(filename.isEmpty())
116 {
117 return;
118 }
119 cfg.setValue("Path/mapInput", QFileInfo(filename).absolutePath());
120
121 lineTragetFile->setText(filename);
122 }
123
124
buildCmd(QList<CShellCmd> & cmds,const IItem * iitem)125 void CToolExport::buildCmd(QList<CShellCmd>& cmds, const IItem* iitem)
126 {
127 inputFiles << iitem->getFilename();
128 }
129
buildCmdFinal(QList<CShellCmd> & cmds)130 void CToolExport::buildCmdFinal(QList<CShellCmd>& cmds)
131 {
132 switch(comboExport->currentIndex())
133 {
134 case eTypeJnx:
135 buildCmdFinalJnx(cmds);
136 break;
137
138 case eTypeRmap:
139 buildCmdFinalRmap(cmds);
140 break;
141 }
142 }
143
buildCmdFinalJnx(QList<CShellCmd> & cmds)144 void CToolExport::buildCmdFinalJnx(QList<CShellCmd>& cmds)
145 {
146 QStringList args;
147 args << "-q" << pageBirdsEyeJnx->getJpegQuality();
148 args << "-s" << pageBirdsEyeJnx->getJpegSubsampling();
149 args << "-p" << pageBirdsEyeJnx->getProductId();
150 args << "-m" << pageBirdsEyeJnx->getProductName();
151 args << "-n" << pageBirdsEyeJnx->getDescription();
152 args << "-c" << pageBirdsEyeJnx->getCopyright();
153 args << "-z" << pageBirdsEyeJnx->getZOrder();
154 args += inputFiles;
155
156 QString targetFile = lineTragetFile->text();
157 QFileInfo fi(targetFile);
158 if(fi.suffix().toUpper() != "JNX")
159 {
160 targetFile += ".jnx";
161 }
162 args << targetFile;
163 cmds << CShellCmd(IAppSetup::self().getQmtmap2jnx(), args);
164 }
165
buildCmdFinalRmap(QList<CShellCmd> & cmds)166 void CToolExport::buildCmdFinalRmap(QList<CShellCmd>& cmds)
167 {
168 }
169
170
slotStart()171 void CToolExport::slotStart()
172 {
173 inputFiles.clear();
174
175 start(itemTree);
176 if(jobId > 0)
177 {
178 itemTree->setEnabled(false);
179 pushStart->setEnabled(false);
180 pushCancel->setEnabled(true);
181 }
182 }
183
slotFinished(qint32 id)184 void CToolExport::slotFinished(qint32 id)
185 {
186 if(finished(id))
187 {
188 itemTree->setEnabled(true);
189 pushStart->setEnabled(true);
190 pushCancel->setEnabled(false);
191 }
192 }
193
194