Skip to content

Added file utility class for easier save file handling. (#304)

Thorwin Vogt requested to merge devel_file_utils into master

Added a utility class for easier save file handling. As of right now, code to open a file dialog is duplicated throughout Met.3D. Instead of duplicating it, this MR adds a utility class to easily handle file dialogs to save and open files. The class manages several things that are currently done manually in throughout Met.3D. If an existing file is selected, it automatically asks, whether to overwrite it. If an invalid extension is provided, the dialog automatically appends the selected file type extension, making it valid. In essence, the File utils make it redundant to check, whether the file dialog returns an existing file, as it already asks the user if they want to overwrite it. Additionally, it manages file extensions in a way, that after accepting the file dialog, the filename will always have a valid file extension.

The utility class allows the programmer to specify one or multiple allowed file types using the MFileType struct. It automatically constructs the filter string required by Qt for the file dialog window. If no filter is requested, a wildcard filter is used. The MFileType struct can also be used to check, whether a file is of that file type. It can also return the default extension of that file type if needed.

All currently used file types are defined in mfiletypes.h

Edited by Thorwin Vogt

Merge request reports