Disclosure of Invention
Aiming at the technical problems, the invention adopts the following technical scheme: a method of generating a target source file for a user interface, the method comprising:
s100, acquiring a header file h which is generated according to a user interface created by a user and accords with QT specification0 Said h is0 A first sentence comprising a preprocessing area, a second sentence comprising a class common control member definition area, and a third sentence comprising a function body area, wherein each first sentence is a sentence comprising h0 Each second statement defines a statement for class members including class names and object pointer names, and the third statement includes class names and object pointer names.
S200, identifying h according to regular expression0 The first sentence, the second sentence and the third sentence, the first sentence is stored in the first container, the second sentence is stored in the second container, and the third sentence is stored in the second container according to h0 Is stored in a third container.
S300, traversing a first sentence stored in a first container, and respectively replacing first elements with first target elements according to an element dictionary to obtain an updated first sentence; the element dictionary includes h0 A mapping relationship between the first element of the target source file and the first target element of the target source file.
S400, traversing the second container and the third container respectively, and respectively converting h according to the class name dictionary and the object pointer name dictionary0 Class names of (a) are replaced by target class names, h respectively0 The object pointer name of the (2) is replaced by the target object pointer name, so that updated second sentences and third sentences are obtained; the class name dictionary includes h0 Mapping relationship between class name of object pointer and object class name of object source file, said object pointer name dictionary includes h0 A mapping relationship between the object pointer name of the target source file and the target object pointer name of the target source file.
S500, assembling the updated first statement, second statement and third statement into a target source file h0 The target source file h0 For generating a user interface.
The invention further provides a system for generating the target source file of the user interface, which comprises a processor and a non-transitory computer readable storage medium, wherein at least one instruction or at least one section of program is stored in the non-transitory computer readable storage medium, and the at least one instruction or the at least one section of program is loaded and executed by the processor to realize the method.
Compared with the prior art, the method and the system for generating the target source file of the user interface have obvious beneficial effects, can achieve quite technical progress and practicality, have wide industrial utilization value, and have at least the following beneficial effects:
the invention provides a method and a system for generating a target source file of a user interface, which are realized by acquiring a generated header file h0 Identifying h from regular expressions0 The three sentences are respectively stored in different containers; traversing corresponding sentences in each container, and respectively replacing first type elements of the first type sentences with first type target elements to obtain updated first type sentences; replacing class names in the second sentence and the third sentence with target class names and replacing object pointer names with target object pointer names respectively to obtain updated second and third sentences; recombining the updated first, second and third sentences into a target source file to achieve the goal of recombining the header file h0 The purpose of automatically generating the target source file can not only accelerate development progress, but also reduce errors of manual writing, and the generation method provided by the invention is adopted to directly generate the target source file when the ui file is modified again; solves the problem of manually modifying the header file h in the prior art0 The technical problems of high error rate and slow development speed are caused.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to fall within the scope of the invention.
Referring to fig. 1, a flowchart of a method for generating a target source file of a user interface is shown, where the method includes:
s100, acquiring a header file h which is generated according to a user interface created by a user and accords with QT specification0 Said h is0 A first sentence comprising a preprocessing area, a second sentence comprising a class common control member definition area, and a third sentence comprising a function body area, wherein each first sentence is a sentence comprising h0 Each second statement defines a statement for class members including class names and object pointer names, and the third statement includes class names and object pointer names.
Note that, header file h0 Is generated from UIC tool, but header file h0 Does not meet the target system specification of the user, and therefore requires the header file h0 An analysis is performed and automatically converted to a target source file that meets target system specifications.
Specifically, the first statement of the preprocessing region is a preprocessing command in a plurality of different formats. Wherein the first key comprises a pre-processing command, wherein the pre-processing command comprises: ifndef, define, include, etc.
Specifically, the second statement in the class common control member definition area is defined for the control class common members of the class. As an example, a class member in the key public format is, for example: "NameA. NameB". The NameA is a class name and the NameB is an object pointer name.
Specifically, the third statement is a statement in the function main body area, and one or more of the statements include a class name and an object pointer name in the class common control member definition area. As an example, in a certain sentence, "pushbutton=new name a (parameter c)", where name is a class name defined in a class public control member definition area.
S200, identifying h according to regular expression0 The first sentence, the second sentence and the third sentence, the first sentence is stored in the first container, the second sentence is stored in the second container, and the third sentence is stored in the second container according to h0 Is stored in a third container.
Wherein the regular expression is h0 A constraint corresponding to the format of the different category sentences. Those skilled in the art will appreciate that all methods of identifying statement classes using the generation of regular expressions in the prior art fall within the scope of the present invention.
As a preferred embodiment, keywords in the corresponding category of sentences are included in the regular expression.
It will be appreciated that h0 Each sentence in the list comprises a plurality of sub-sentences, the plurality of sub-sentences comprise at least one grammar format, namely, the same sentence is identified by a regular expression or synonymous regular expression, and different sentence categories are distinguished by setting different regular matching character strings comprising keywords, sentence characteristics and the like, so that the aim of classifying sentences with different formats is fulfilled.
It can be understood that sentences in different types are stored through different storage containers, so that subsequent processing of sentences in different containers is facilitated. Alternatively, the container is an array or map, etc.
As a preferred embodiment, before storing the first sentence in the first container, the method further comprises: s220, identifying a first keyword in the first sentence, and according to the first keywordObtaining N first seed sentences with the same first key words, wherein the N first seed sentences are in h0 The order of execution of which is the same as or different from the order of storage in the first container. Optionally, the first type of keyword is include.
As a preferred embodiment, before storing the second sentence in the second container, the method further comprises: s240, identifying a second keyword in the second sentence, and acquiring M class members sharing the same second keyword according to the second keyword, wherein the M class members are in h0 The defined order of (a) is the same as or different from the order of storage in the second container. Optionally, the access modifier of the second type of key is public.
It will be appreciated that the third container is an ordered container or may be implemented as a container accessed in a specified order, ensuring that the original logic is not destroyed when the target source code is reorganized.
S300, traversing a first sentence stored in a first container, and respectively replacing first elements with first target elements according to an element dictionary to obtain an updated first sentence; the element dictionary includes h0 A mapping relationship between the first element of the target source file and the first target element of the target source file.
It should be noted that, the target element is a target header file name corresponding to the original header file name, and the naming specification of the target header file name accords with the naming specification of the target system. Header file h0 The first type elements conforming to the QT naming specification are replaced by target elements, so that the replaced first statement conforms to the target system specification. The order of the first element in the element dictionary is a preset order and may be different from the order stored in the first container.
S400, traversing the second container and the third container respectively, and respectively converting h according to the class name dictionary and the object pointer name dictionary0 Class names of (a) are replaced by target class names, h respectively0 The object pointer name of the (2) is replaced by the target object pointer name, so that updated second sentences and third sentences are obtained; the class name dictionary includes h0 Mapping relationship between class name of object pointer and object class name of object source file, said object pointer name dictionary includes h0 A mapping relationship between the object pointer name of the target source file and the target object pointer name of the target source file.
It should be noted that the target class member is a class member conforming to the naming specification of the target source file. Will h0 The class members meeting the QT naming standards are replaced by target class members meeting the target system naming standards of the user, so that the replaced second statement and third statement meet the target system naming standards. The steps S300 and S400 are only for convenience of description, and the steps may be executed first in the step S300 and then in the step S400, without any order between the steps. S400 may be executed first, and S300 may be executed later; in step S400, the traversing order of the second container and the third container is not limited, and similarly, the second container may be traversed first, then the third container may be traversed, or the third container may be traversed first, then the second container may be traversed.
As one example, replacing a class name with a target class name refers to replacing a class name nameA with a target class name nameSA.
As a preferred embodiment, S400 further includes:
s420, traversing the updated third statement according to a statement mapping dictionary, wherein the statement mapping dictionary comprises a mapping relation between a third seed statement and a target sub statement which do not accord with the target source file specification, and identifying the third seed statement and replacing the third seed statement with the target sub statement. Optionally, the sentence mapping dictionary includes a mapping relation that the target sub-sentence is empty. When the target sentence is empty, the essence operation is to delete h0 A third class of sub-statements in (a).
S500, assembling the updated first statement, second statement and third statement into a target source file h0 The target source file h0 For generating a user interface.
It can be appreciated that the reorganization is performed according to the structure of the target source file. Generally, the reorganization is performed in the order of the first sentence, the second sentence, and the third sentence.
As a preferred embodiment, when the naming specification of the target source file is modified, the target class name in the class name dictionary, the target object pointer name in the object pointer name dictionary and/or the first target element in the element dictionary are adaptively modified, so that the adaptive updating of the target source file can be realized.
In summary, the embodiment of the invention provides a method for generating a target source file of a user interface by acquiring a generated header file h0 Identifying h from regular expressions0 The first sentence of the pre-processing area, the second sentence of the class public control member definition area and the third sentence of the function main body area are respectively stored in different containers; traversing corresponding sentences in each container, and respectively replacing first-type elements of the first-type sentences with first-type target elements to obtain updated first-type sentences; respectively replacing class members in the second sentence and the third sentence with target class members to obtain an updated second sentence and third sentence; recombining the updated first, second and third sentences into a target source file to achieve the goal of recombining the header file h0 The aim of automatically generating the target source file can not only accelerate development progress, but also reduce errors of manual writing, and the target source file is directly generated by using the method provided by the embodiment of the invention when the ui file is modified again; solves the problem of manually modifying the header file h in the prior art0 The technical problems of high error rate, low debugging speed and high manual modification cost are caused.
Based on the same inventive concept as the above method embodiment, the present invention further provides a system for generating a target source file of a user interface, where the system includes a processor and a non-transitory computer readable storage medium, where at least one instruction or at least one program is stored in the non-transitory computer readable storage medium, where the at least one instruction or the at least one program is loaded and executed by the processor to implement the method for generating a target source file of a user interface provided in the above embodiment, and the method for generating a target source file of a user interface is described in detail in the above embodiment and is not repeated.
While certain specific embodiments of the invention have been described in detail by way of example, it will be appreciated by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the invention. Those skilled in the art will also appreciate that many modifications may be made to the embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.