Commit de5b2db9 authored by Alexander Semke's avatar Alexander Semke
Browse files

When saving the results, use the file extension and not the mime-type in the...

When saving the results, use the file extension and not the mime-type in the QFileDialog to show the relevant files only.
parent 4efa9889
Pipeline #206715 passed with stage
in 7 minutes and 43 seconds
......@@ -110,9 +110,8 @@ void AnimationResultItem::updateSize(QSize size)
void AnimationResultItem::saveResult()
{
Cantor::Result* res = result();
const QString& filename=QFileDialog::getSaveFileName(worksheet()->worksheetView(), i18n("Save result"), QString(), res->mimeType());
res->save(filename);
const QString& filename = QFileDialog::getSaveFileName(worksheet()->worksheetView(), i18n("Save animation result"), QString(), i18n("Animations (*.gif)"));
result()->save(filename);
}
void AnimationResultItem::stopMovie()
......
......@@ -13,6 +13,7 @@
#include <KLocalizedString>
#include <QFileDialog>
#include <QImageReader>
ImageResultItem::ImageResultItem(QGraphicsObject* parent, Cantor::Result* result)
: WorksheetImageItem(parent), ResultItem(result)
......@@ -84,9 +85,20 @@ double ImageResultItem::height() const
void ImageResultItem::saveResult()
{
Cantor::Result* res = result();
const QString& filename = QFileDialog::getSaveFileName(worksheet()->worksheetView(), i18n("Save result"), QString(), res->mimeType());
res->save(filename);
QString formats;
for (const auto& format : QImageReader::supportedImageFormats()) {
QString f = QLatin1String("*.") + QLatin1String(format.constData());
if (f == QLatin1String("*.svg")) // TODO: add SVG after we've switched internally to PDF/SVG for backend's output
continue;
formats += f + QLatin1Char(' ');
}
const auto& fileName = QFileDialog::getSaveFileName(worksheet()->worksheetView(),
i18n("Save image result"),
/*dir*/ QString(),
i18n("Images (%1)", formats));
if (!fileName.isEmpty())
result()->save(fileName);
}
void ImageResultItem::deleteLater()
......
......@@ -159,11 +159,9 @@ void ImageResult::saveAdditionalData(KZip* archive)
void ImageResult::save(const QString& filename)
{
//load into memory and let Qt save it, instead of just copying d->url
//to give possibility to convert file format
QImage img=data().value<QImage>();
img.save(filename);
bool rc = d->img.save(filename);
if (!rc)
qDebug()<<"saving to " << filename << " failed.";
}
QSize Cantor::ImageResult::displaySize()
......
......@@ -40,7 +40,7 @@ TextResultItem::TextResultItem(WorksheetEntry* parent, Cantor::Result* result)
// We do it here, because we need it one
if (document()->characterCount() && document()->characterAt(0) == QChar::ParagraphSeparator)
{
Cantor::HtmlResult* hr = static_cast<Cantor::HtmlResult*>(m_result);
auto* hr = static_cast<Cantor::HtmlResult*>(m_result);
hr->setFormat(Cantor::HtmlResult::PlainAlternative);
setHtml(hr->toHtml());
}
......@@ -60,7 +60,7 @@ void TextResultItem::populateMenu(QMenu* menu, QPointF pos)
menu->addAction(copy);
ResultItem::addCommonActions(this, menu);
Cantor::Result* res = result();
auto* res = result();
if (res->type() == Cantor::LatexResult::Type) {
QAction* showCodeAction = nullptr;
Cantor::LatexResult* lres = static_cast<Cantor::LatexResult*>(res);
......@@ -149,7 +149,7 @@ void TextResultItem::setLatex(Cantor::LatexResult* result)
else
{
QString uuid = Cantor::LatexRenderer::genUuid();
Cantor::Renderer* renderer = qobject_cast<Worksheet*>(scene())->renderer();;
auto* renderer = qobject_cast<Worksheet*>(scene())->renderer();;
format = renderer->render(cursor.document(), Cantor::Renderer::EPS, result->url(), uuid);
format.setProperty(Cantor::Renderer::CantorFormula,
Cantor::Renderer::LatexFormula);
......@@ -178,7 +178,7 @@ double TextResultItem::height() const
void TextResultItem::toggleLatexCode()
{
Cantor::LatexResult* lr = static_cast<Cantor::LatexResult*>(result());
auto* lr = static_cast<Cantor::LatexResult*>(result());
if(lr->isCodeShown())
lr->showRendered();
else
......@@ -189,34 +189,30 @@ void TextResultItem::toggleLatexCode()
void TextResultItem::showHtml()
{
Cantor::HtmlResult* hr = static_cast<Cantor::HtmlResult*>(result());
auto* hr = static_cast<Cantor::HtmlResult*>(result());
hr->setFormat(Cantor::HtmlResult::Html);
parentEntry()->updateEntry();
}
void TextResultItem::showHtmlSource()
{
Cantor::HtmlResult* hr = static_cast<Cantor::HtmlResult*>(result());
auto* hr = static_cast<Cantor::HtmlResult*>(result());
hr->setFormat(Cantor::HtmlResult::HtmlSource);
parentEntry()->updateEntry();
}
void TextResultItem::showPlain()
{
Cantor::HtmlResult* hr = static_cast<Cantor::HtmlResult*>(result());
auto* hr = static_cast<Cantor::HtmlResult*>(result());
hr->setFormat(Cantor::HtmlResult::PlainAlternative);
parentEntry()->updateEntry();
}
void TextResultItem::saveResult()
{
auto* res = result();
const QString& filename = QFileDialog::getSaveFileName(worksheet()->worksheetView(), i18n("Save result"), QString(), res->mimeType());
if (!filename.isEmpty())
{
qDebug() << "saving result to " << filename;
res->save(filename);
}
const auto& fileName = QFileDialog::getSaveFileName(worksheet()->worksheetView(), i18n("Save text result"), QString(), i18n("Text Files (*.txt)"));
if (!fileName.isEmpty())
result()->save(fileName);
}
void TextResultItem::deleteLater()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment