[umbrello-devel] [umbrello] [Bug 316095] unable to export class diagram to image

Ralf Habacker ralf.habacker at freenet.de
Sun Sep 22 12:55:29 UTC 2013


https://bugs.kde.org/show_bug.cgi?id=316095

--- Comment #7 from Ralf Habacker <ralf.habacker at freenet.de> ---
(In reply to comment #6)
> Created attachment 82455 [details]
> Fix mapping of file extension to mime type
> 
Thanks for your effort. 
After digging into this stuff I come to the conclusion, that this bug seems to
be have other reasons, because UMLViewImageExporterModel::imageTypeToMimeType()
is intended to process one image type, not multiple. 

/**
 * Returns the mime type for an image type.
 * The supported image types are those that the diagrams can be exported to.
 *
 * @param imageType The type of the image.
 * @return A QString with the equivalent mime type, or QString() if
 *         it's unknown.
 */
QString UMLViewImageExporterModel::imageTypeToMimeType(const QString&
imageType)

instead there is a misconception in 
UMLViewImageExporter::getParametersFromUser() mentioned below: 

/**
 * Shows a save file dialog to the user to get the parameters used
 * to export the view and updates the attributes with the parameters got.
 *
 * @return True if the user wants to save the image,
 *         false if the operation is cancelled.
 */
bool UMLViewImageExporter::getParametersFromUser()
{
    bool success = true;

    // configure & show the file dialog
    KUrl url;
    QPointer<UMLFileDialog> dialog = new UMLFileDialog(url, QString(),
UMLApp::app());
    prepareFileDialog(dialog);
    dialog->exec();

-> dialog has been executed and closed 

    if (dialog->selectedUrl().isEmpty()) {
        success = false;
    }
    else {
        m_scene->clearSelected();   // Thanks to Peter Soetens for the idea

        // update image url and mime type
        m_imageMimeType = dialog->currentMimeFilter();

--> this should return the mime type of the selected file. 

In the called method which handles a single mimetype

QString UMLFileDialog::currentMimeFilter()
{
    QString currentFilter = m_dialog->currentFilter();

this return multiple filters instead of the one of the selected file. 

    #ifdef Q_OS_WIN
    // using native KFileDialog returns empty filter, so we need a workaround
    if (currentFilter.isEmpty()) {
        KUrl url = m_dialog->selectedUrl();
        QFileInfo fi(url.toLocalFile());
        return UMLViewImageExporterModel::imageTypeToMimeType(fi.suffix());

On windows where the native KFileDialog is used it works correctly. 

    }
    #endif
    return
UMLViewImageExporterModel::imageTypeToMimeType(currentFilter.remove("*."));
}

... returning to bool UMLViewImageExporter::getParametersFromUser()

        // update image url and mime type
        m_imageMimeType = dialog->currentMimeFilter();

        UMLApp::app()->setImageMimeType(m_imageMimeType);

the returned (single) mimetype is set as default 

/**
 * Sets the default mime type for all diagrams that are exported as images.
 * @param mimeType   the mime type
 */
void UMLApp::setImageMimeType(const QString& mimeType)


then the url of the selected file is taken 

        m_imageURL = dialog->selectedUrl();


and ...         // check if the extension is the extension of the mime type
        QFileInfo info(m_imageURL.fileName());
        QString ext = info.suffix();
        QString extDef =
UMLViewImageExporterModel::mimeTypeToImageType(m_imageMimeType);
        if (ext != extDef) {
            m_imageURL.setFileName(m_imageURL.fileName() + '.' + extDef);

which takes always the extension based on the mime type of the selected file
extension and not the one returned from currentMimeFilter() ... this looks as
something that could be simplified. 

Returning to the main problem: the usage of dialog->currentMimeFilter(); has
been introduced  with 

commit 13e7b715b4e01f9b18d06d8998278c43c9b07eb4
Date:   Sun Apr 2 10:29:29 2006 +0000

    Apply attachment 15388 by Daniel Calviño Sánchez with minor changes.
    CCBUG:58809

which was at kde3 times. May be that the meaning of currentMimeFilter() has
been changed in the transition from kde3 to kde4.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the umbrello-devel mailing list