mirror of https://gitlab.com/pamhyr/pamhyr2
Scenario: Add X, Y position for tree display.
parent
b634acec67
commit
b8ed3d8954
|
|
@ -29,12 +29,14 @@ class Scenario(SQLSubModel):
|
|||
id: int = -1,
|
||||
name: str = "",
|
||||
description: str = "",
|
||||
x: int = 0.0, y: int = 0.0,
|
||||
revision: int = 0,
|
||||
parent=None):
|
||||
super(Scenario, self).__init__()
|
||||
|
||||
self._set_id(id)
|
||||
|
||||
self._x, self._y = x, y
|
||||
self._name = name
|
||||
self._description = description
|
||||
self._revision = revision
|
||||
|
|
@ -54,11 +56,21 @@ class Scenario(SQLSubModel):
|
|||
def id(self):
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
return self._x
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
return self._y
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE scenario(
|
||||
id INTEGER PRIMARY KEY,
|
||||
x REAL NOT NULL DEFAULT 1000,
|
||||
y REAL NOT NULL DEFAULT 1000,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
revision INTEGER NOT NULL,
|
||||
|
|
@ -73,10 +85,10 @@ class Scenario(SQLSubModel):
|
|||
def _db_add_default(cls, execute):
|
||||
execute(
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"scenario(id, name, description, revision, parent_id) " +
|
||||
"VALUES (" +
|
||||
" 0, 'default', 'Default scenario',\n" +
|
||||
" 0, NULL" +
|
||||
"scenario(id, x, y, name, description, revision, parent_id) " +
|
||||
"VALUES (\n" +
|
||||
" 0, 1000, 1000, 'default', 'Default scenario',\n" +
|
||||
" 0, NULL\n" +
|
||||
")"
|
||||
)
|
||||
|
||||
|
|
@ -96,6 +108,17 @@ class Scenario(SQLSubModel):
|
|||
cls._db_create(execute)
|
||||
cls._db_add_default(execute)
|
||||
|
||||
if major == "0" and minor == "1":
|
||||
if int(release) < 2:
|
||||
execute(
|
||||
"ALTER TABLE scenario " +
|
||||
"ADD COLUMN x REAL NOT NULL DEFAULT 1000"
|
||||
)
|
||||
execute(
|
||||
f"ALTER TABLE scenario " +
|
||||
"ADD COLUMN x REAL NOT NULL DEFAULT 1000"
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
|
|
@ -116,7 +139,7 @@ class Scenario(SQLSubModel):
|
|||
scenarios = {}
|
||||
|
||||
table = execute(
|
||||
"SELECT id, name, description, revision, parent_id " +
|
||||
"SELECT id, x, y, name, description, revision, parent_id " +
|
||||
"FROM scenario " +
|
||||
"ORDER BY id ASC"
|
||||
)
|
||||
|
|
@ -125,6 +148,7 @@ class Scenario(SQLSubModel):
|
|||
it = iter(row)
|
||||
|
||||
id = next(it)
|
||||
x, y = next(it), next(it)
|
||||
name = next(it)
|
||||
desc = next(it)
|
||||
revi = next(it)
|
||||
|
|
@ -134,7 +158,8 @@ class Scenario(SQLSubModel):
|
|||
parent = scenarios[parent]
|
||||
|
||||
new = cls(
|
||||
id=id, name=name, description=desc,
|
||||
id=id, x=x, y=y,
|
||||
name=name, description=desc,
|
||||
revision=revi, parent=parent
|
||||
)
|
||||
scenarios[id] = new
|
||||
|
|
@ -148,9 +173,10 @@ class Scenario(SQLSubModel):
|
|||
|
||||
execute(
|
||||
"INSERT OR REPLACE INTO " +
|
||||
"scenario(id, name, description, revision, parent_id) " +
|
||||
"scenario(id, x, y, name, description, revision, parent_id) " +
|
||||
"VALUES (" +
|
||||
f"{self._id}, " +
|
||||
f"{self.x}, {self.y} " +
|
||||
f"'{self._db_format(self.name)}', " +
|
||||
f"'{self._db_format(self.description)}', " +
|
||||
f"{self._revision}, " +
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Study(SQLModel):
|
|||
|
||||
def __init__(self, filename=None, init_new=True):
|
||||
# Metadata
|
||||
self._version = "0.1.1"
|
||||
self._version = "0.1.2"
|
||||
self.creation_date = datetime.now()
|
||||
self.last_modification_date = datetime.now()
|
||||
self.last_save_date = datetime.now()
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ class ScenarioItem(QGraphicsTextItem):
|
|||
self.graph = graph_widget
|
||||
self.scenario = scenario
|
||||
|
||||
self.setPos(QPointF(self.scenario.x, self.scenario.y))
|
||||
|
||||
self.setPlainText(self.scenario.name)
|
||||
self.setDefaultTextColor(Qt.black)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue