Even if all the assistants have a very different structure compared to each other, they all have common attributes. All the assistants have handles(the circles on each assistant in the image above)which give the individual assistants their shape and have only x-coordinates and y-coordinates as their attributes and type, which tells the program which type of assistant is being created.
Saving of assistants their important attributes had to be saved. Each assistant has the Type and Handles as its attribute. So, in order to save the assistants these attributes had to be saved. “How to save the assistants so that it is easy to load them back?” One big question which made me change my implementation of saving around three times. Well, now the assistants are saved in the following manner:
Following are the modifications which are done in the end of file/folder structure for saving of the assistants.
- There is a list of assistants in the maindoc.xml file which tells the program the type of the assistants and the filenames in which the assistants are saved. The list has a n xml style formatting.
- Whenever there is at least an assistant to be saved, the program creates a new folder called “assistants” inside the folder having the name same as the name of the created document. Inside this folder are the files with the filenames as given in the list in maindoc.xml. These files individually contain the information of an assistant of the type as described in the list. The name of these files are of the form ‘typecount.assistant’ where count is between 0 and n-1(n = total number of that type of assistant), for e.g. ellipse0.assistant, ellipse1.assistant, perspective0.assistant, etc.
- Now, these files store data of an assistant each. These files also have xml format. they store the type and handles, where each handle then stores attributes like handle id(for using in shared pointer), x-coordinate and y-coordinate.
Now, the whole process of saving of the assistants is done in a systematic manner.
First, the list of assistants is stored in the maindoc.xml and then the assistants are saved in their respecitve files.
Because of the way assistants are saved, the loading part was rather simpler to implement.
First, the list of assistants is fetched from the maindoc.xml and stored in a QMap of filename -> type.
Second, The blank assistants are created on basis of the type using the Factory and once created the assistant is given its handles and inserted into a Qlist.
Finally, the Assistants are added to the Manager which is at last set to visible, making it possible to see the saved assistants.
Well, that is how the current implementation of the saving and loading of assistants is done and I have a request the wonderful artists who use Krita to use the assistants and help in making them better by the day.