If you have a segment of code that is copied in multiple places, a function
certainly makes sense. It would make sense to write a function that creates
a default save location if the code is repeated.
If all you need to do is to ask the user to select a file, though, there is
only one function you really need:
http://doc.qt.io/qt-4.8/qfiledialog.html#getOpenFileName
On Wed, Feb 1, 2017 at 8:39 AM Davide Olianas <[email protected]>
wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Hello,
>
>
> some time ago I
>
> wrote an extension that requires the user to input a filename.
>
> I’m writing another extension with the same requirement.
>
>
> As a fast but ugly
>
> solution, I copied the following code from
> libavogadro/src/extensions/quantuminput/gaussianinputdialog.cpp
>
> (lines 240-255)
>
>
> // Fragment copied from InputDialog
>
> // Try to set default save path for dialog using the next sequence:
>
> // 1) directory of current file (if any);
>
> // 2) directory where previous deck was saved;
>
> // 3) $HOME
>
> QFileInfo defaultFile(m_molecule->fileName());
>
> QString defaultPath = defaultFile.canonicalPath();
>
> if(m_savePath == "") {
>
> if (defaultPath.isEmpty())
>
> defaultPath = QDir::homePath();
>
> } else {
>
> defaultPath = m_savePath;
>
> }
>
>
>
> QString defaultFileName = defaultPath + '/' + defaultFile.baseName() +
> "." + ext;
>
> QString fileName = QFileDialog::getSaveFileName(this, tr("Save Input
> Deck"),
>
> defaultFileName, fileType + " (*." + ext + ")");
>
>
>
> As the initial
>
> comment states, even these lines are copied from somewhere else
>
> (libavogadro/src/extensions/quantuminput/inputdialog.cpp).
>
>
> I’d like to
>
> contribute with a pull request on github. I could write a
>
> function askForFileName
>
> that my two extensions, gaussianinputdialog
>
> and abinitinputdialog
>
> would use.
>
>
> Any suggestion is
>
> welcome. Let me know if this makes sense.
>
>
> Regards,
>
>
> Davide
>
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
>
> Check out the vibrant tech community on one of the world's most
>
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
>
> Avogadro-devel mailing list
>
> [email protected]
>
> https://lists.sourceforge.net/lists/listinfo/avogadro-devel
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Avogadro-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/avogadro-devel