|
|
Line 3: |
Line 3: |
| == Description == | | == Description == |
| | | |
− | The task element is described in the [[Task_Management_Method#Task|"Task Management Method"]]. The tasks in the project are stored in a table in the project database. The name of a task does not have to be unique. Therefore, a task also has to have a unique id. Further, since a task represents a graphical element, it has a position, a width and a height. These attributes are expressed in pixels. The TaskDepender™ program uses a true-type font, and therefore the width and height will be determined when the task is displayed. | + | The task element is described in the [[Task_Management_Method#Task|"Task Management Method"]]. The tasks in the project are stored in a table in the project database. The name of a task does not have to be unique, a task has to have a unique id which can be generated as a integer primary key<ref name="primary_key">[http://www.sqlite.org/lang_createtable.html#rowid rowid - SQLite specification]</ref> by the database. Since a task represents a graphical element, it has a position, a width and a height. The TaskDepender™ program uses a true-type font, and therefore the width and height will be determined when the task is displayed. |
| + | |
| + | == Constraints == |
| | | |
| The following constraints apply for the tasks table: | | The following constraints apply for the tasks table: |
Line 10: |
Line 12: |
| | | |
| == Design == | | == Design == |
− |
| |
− | === Columns ===
| |
| | | |
| The tasks are stored in a table with the following columns: | | The tasks are stored in a table with the following columns: |
Line 38: |
Line 38: |
| |} | | |} |
| | | |
− | === Constraints ===
| |
− |
| |
− | The two constraints for the table can be implemented by by [http://www.sqlite.org/foreignkeys.html#fk_actions referencing] these columns to the appropriate columns. This is done as follows:
| |
− | * Delete contained task when container is deleted: self-reference the <tt>ContainerId</tt> column to the <tt>Id</tt> column.
| |
− | * Set <tt>RecourceId</tt> to <tt>NULL</tt> when recource deleted: reference <tt>RecourceId</tt> to the <tt>Id</tt> in the [[Resources database table|resources table]].
| |
− |
| |
− | === Create ===
| |
− |
| |
− | When a new project is created, the tasks table is created. Because of the reference to the resource (see [[#Constraints|"Constraints"]], the tasks table must be created ''after'' the [[Resources database table|resources table]].
| |
− |
| |
− | === Insert ===
| |
− |
| |
− | Since a task can only be added in the current container, the <tt>ContainerId</tt> does not have to be supplied but can be retrieved from the [[State variables database table|<tt>StateVariables</tt>]] table.
| |
− |
| |
− | === Update ===
| |
− |
| |
− | A task can only be updated when it is selected. The selected tasks are stored in the [[Selected tasks database table|selected tasks table]]. This means that the user does not have to supply the id when updating a selected task. To restrict the database to update more tasks when the selected tasks table contains more than one task, the update is limited to the first element.
| |
− |
| |
− | === Delete ===
| |
− |
| |
− | Only selected tasks can be deleted. This means that the user does not have to supply an id, but simply all selected tasks are deleted.
| |
− |
| |
− | === Cut ===
| |
− |
| |
− | As described in [[Cut selected elements|"Cut selected elements"]], selected elements can be 'cut to the clipboard' by setting the <tt>ContainerId</tt> column to the maximum integer value. Since the <tt>Id</tt> of a task is stored in a [[Types|<tt>uint32</tt>]], this value is explicitly set to 4294967295 (=2<sup>32</sup>).
| |
− |
| |
− | === Paste ===
| |
− |
| |
− | As described in [[Paste elements|"Paste elements"]], elements can be pasted into the current diagram by setting the <tt>ContainerId</tt> column to the current container. As follows from the previous section, this is done by finding all the tasks that have this <tt>ContainerId</tt> set to the maximum integer value of 4294967295.
| |
− |
| |
− | == Implementation ==
| |
− |
| |
− | === Interface structure ===
| |
− |
| |
− | <syntaxhighlight lang="cpp">
| |
− | typedef struct
| |
− | {
| |
− | uint32 id,
| |
− | char* name,
| |
− | char* description,
| |
− | uint resourceId,
| |
− | uint x,
| |
− | uint y,
| |
− | uint width,
| |
− | uint height,
| |
− | uint32 container_id
| |
− | } tdd_task;
| |
− | </syntaxhighlight>
| |
− |
| |
− | === Create table ===
| |
− |
| |
− | <syntaxhighlight lang="sql">
| |
− | CREATE TABLE Tasks
| |
− | (
| |
− | Id INTEGER PRIMARY KEY,
| |
− | Name TEXT,
| |
− | Description TEXT,
| |
− | ResourceId INTEGER REFERENCES Resources(Id) ON DELETE SET NULL,
| |
− | X INTEGER,
| |
− | Y INTEGER,
| |
− | Width INTEGER,
| |
− | Height INTEGER,
| |
− | ContainerId INTEGER REFERENCES Tasks(Id) ON DELETE CASCADE
| |
− | )
| |
− | </syntaxhighlight>
| |
− |
| |
− | === Insert ===
| |
− |
| |
− | <syntaxhighlight lang="sql">
| |
− | INSERT INTO Tasks
| |
− | (Name,Description, Resource, X, Y, Width, Height, ContainerId)
| |
− | VALUES (%s, %s, %s, %d, %d, %d, %d, (SELECT Val FROM StateVariables WHERE Name='CurrentContainerId'))
| |
− | </syntaxhighlight>
| |
− |
| |
− | === Update ===
| |
− |
| |
− | <syntaxhighlight lang="sql">
| |
− | UPDATE Tasks SET
| |
− | Name=%s,
| |
− | Description=%s,
| |
− | Resource=%s,
| |
− | X=%d,
| |
− | Y=%d,
| |
− | Width=%d,
| |
− | Height=%d
| |
− | WHERE Id IN (SELECT Id FROM SelectedTasks)
| |
− | </syntaxhighlight>
| |
− |
| |
− | === Delete selected tasks ===
| |
− |
| |
− | <syntaxhighlight lang="sql">
| |
− | DELETE FROM Tasks WHERE Id IN (SELECT Id FROM SelectedTasks)
| |
− | </syntaxhighlight>
| |
− |
| |
− | === Cut selected tasks ===
| |
| | | |
− | <syntaxhighlight lang="sql">
| + | The following actions are defined: |
− | UPDATE Tasks SET ContainerId=4294967295 WHERE Id IN (SELECT Id FROM SelectedTasks)
| + | * [[Tasks database table - Create|Create]] |
− | </syntaxhighlight>
| + | * [[Tasks database table - Insert|Insert]] |
| + | * [[Tasks database table - Update|Update]] |
| + | * [[Tasks database table - Delete|Delete]] |
| + | * [[Tasks database table - Cut|Cut]] |
| + | * [[Tasks database table - Paste|Paste]] |
| | | |
− | === Paste tasks === | + | == References == |
| + | <references/> |
| | | |
− | <syntaxhighlight lang="sql">
| |
− | UPDATE Tasks SET ContainerId=(SELECT Val FROM StateVariables WHERE Name='CurrentContainerId') WHERE ContainerId=4294967295
| |
− | </syntaxhighlight>
| |
| | | |
| ---- | | ---- |
| * [[Database]] | | * [[Database]] |