개정판 21c5196e
issue #1197: 저장 속도 개선
Change-Id: Ia8f30347db8dec4c0a14398e1e35279162ee0c31
HYTOS/HYTOS/AppDocData.py | ||
---|---|---|
1130 | 1130 |
@date 2019.08.28 |
1131 | 1131 |
''' |
1132 | 1132 |
|
1133 |
def saveToDatabase(self, item, index):
|
|
1133 |
def saveToDatabase(self, items, show_progress=None):
|
|
1134 | 1134 |
""" save given items to database """ |
1135 |
|
|
1136 |
queries = [] |
|
1137 |
for item in items: |
|
1138 |
queries.append(item.toSql()) |
|
1139 |
|
|
1135 | 1140 |
with sqlite3.connect(self.activeDrawing.path, isolation_level=None) as conn: |
1136 | 1141 |
conn.execute('PRAGMA foreign_keys = ON') |
1137 | 1142 |
try: |
1138 | 1143 |
# Get a cursor object |
1139 | 1144 |
cursor = conn.cursor() |
1145 |
cursor.execute('begin') |
|
1140 | 1146 |
|
1141 |
if index == 0: |
|
1142 |
# delete Components |
|
1143 |
sql = 'delete from Components' |
|
1144 |
cursor.execute(sql) |
|
1145 |
|
|
1146 |
sql = item.toSql() |
|
1147 |
if type(sql) is list: |
|
1148 |
for item in sql: |
|
1149 |
if item is not None and 2 == len(item): |
|
1150 |
cursor.execute(item[0], item[1]) |
|
1151 |
else: |
|
1152 |
if sql is not None and 2 == len(sql): |
|
1153 |
cursor.execute(sql[0], sql[1]) |
|
1147 |
# delete Components |
|
1148 |
sql = 'delete from Components' |
|
1149 |
cursor.execute(sql) |
|
1154 | 1150 |
|
1155 |
conn.commit() |
|
1151 |
progress = 0 |
|
1152 |
length = len(queries) |
|
1153 |
for sql in queries: |
|
1154 |
if type(sql) is list: |
|
1155 |
for item in sql: |
|
1156 |
if item is not None and 2 == len(item): |
|
1157 |
cursor.execute(item[0], item[1]) |
|
1158 |
else: |
|
1159 |
if sql is not None and 2 == len(sql): |
|
1160 |
cursor.execute(sql[0], sql[1]) |
|
1161 |
|
|
1162 |
if show_progress: |
|
1163 |
show_progress(int((progress / length) * 100)) |
|
1164 |
progress += 1 |
|
1165 |
|
|
1166 |
cursor.execute('commit') |
|
1156 | 1167 |
# Catch the exception |
1157 | 1168 |
except Exception as ex: |
1158 | 1169 |
from App import App |
... | ... | |
1162 | 1173 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1163 | 1174 |
sys.exc_info()[-1].tb_lineno) |
1164 | 1175 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1176 |
finally: |
|
1177 |
if show_progress: |
|
1178 |
show_progress(100) |
|
1165 | 1179 |
|
1166 | 1180 |
def getDrawings(self): |
1167 | 1181 |
""" |
HYTOS/HYTOS/Drawing.py | ||
---|---|---|
21 | 21 |
|
22 | 22 |
self.allItems = [] |
23 | 23 |
self._hmbTable = None |
24 |
|
|
24 |
|
|
25 |
self._modified = False |
|
26 |
|
|
27 |
@property |
|
28 |
def modified(self): |
|
29 |
"""getter of modified""" |
|
30 |
return self._modified |
|
31 |
|
|
32 |
@modified.setter |
|
33 |
def modified(self, value): |
|
34 |
"""setter of modified""" |
|
35 |
self._modified = value |
|
36 |
|
|
25 | 37 |
def clearItemList(self): |
26 | 38 |
self.allItems.clear() |
27 | 39 |
|
... | ... | |
64 | 76 |
else: |
65 | 77 |
self._attrs.append([name, value]) |
66 | 78 |
|
67 |
#print('attribute({},{})'.format(name, value)) |
|
68 |
|
|
69 | 79 |
''' |
70 | 80 |
@brief getter of hmb table |
71 | 81 |
@author humkyung |
HYTOS/HYTOS/MainWindow.py | ||
---|---|---|
52 | 52 |
""" This is MainWindow class """ |
53 | 53 |
addMessage = pyqtSignal(Enum, str) |
54 | 54 |
|
55 |
''' |
|
56 |
@brief initialize |
|
57 |
@author |
|
58 |
@date |
|
59 |
@history humkyung 2018.04.12 add splitter widget |
|
60 |
Jeongwoo 2018.04.27 Add Signal/Slot Connection 'noteNoSingleClicked' |
|
61 |
Jeongwoo 2018.05.09 Initialize Action group |
|
62 |
Jeongwoo 2018.05.10 Add Signal/Slot Connection 'lineNoSingleClicked' |
|
63 |
Add QActionGroup for managing checkable action |
|
64 |
Jeongwoo 2018.06.27 Add Action [Zoom, Fit Window] and Add new actions into ActionGroup |
|
65 |
humkyung 2018.08.23 add labelStatus to statusbar |
|
66 |
|
|
67 |
''' |
|
68 |
|
|
69 | 55 |
def __init__(self): |
56 |
"""initialize""" |
|
57 |
|
|
70 | 58 |
try: |
71 | 59 |
super(self.__class__, self).__init__() |
72 | 60 |
self.setupUi(self) |
... | ... | |
522 | 510 |
sys.exc_info()[-1].tb_lineno) |
523 | 511 |
self.addMessage.emit(MessageType.Error, message) |
524 | 512 |
|
513 |
def save_drawing_if_necessary(self): |
|
514 |
"""ask user to save drawing or not when drawing is modified""" |
|
515 |
|
|
516 |
app_doc_data = AppDocData.instance() |
|
517 |
if app_doc_data.activeDrawing and app_doc_data.activeDrawing.modified: |
|
518 |
if QMessageBox.Yes == QMessageBox.question(self, self.tr("Question"), |
|
519 |
self.tr("Do you want to save drawing?"), |
|
520 |
QMessageBox.Yes | QMessageBox.No): |
|
521 |
self.actionSaveCliked() |
|
522 |
|
|
525 | 523 |
def open_selected_drawing(self, item): |
526 | 524 |
""" open selected drawing """ |
527 | 525 |
try: |
528 | 526 |
path = item.text(2) |
529 | 527 |
if os.path.exists(path): |
528 |
self.save_drawing_if_necessary() |
|
530 | 529 |
self.open_drawing(path) |
531 | 530 |
|
532 | 531 |
except Exception as ex: |
... | ... | |
549 | 548 |
from datetime import datetime |
550 | 549 |
from AppDocData import AppDocData |
551 | 550 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
552 |
from SaveWorkCommand import SaveWorkCommand |
|
553 | 551 |
|
554 | 552 |
try: |
555 | 553 |
app_doc_data = AppDocData.instance() |
... | ... | |
592 | 590 |
|
593 | 591 |
def save_drawing_data(self): |
594 | 592 |
""" save drawing data """ |
593 |
|
|
595 | 594 |
from datetime import datetime |
596 | 595 |
from AppDocData import AppDocData |
597 | 596 |
from SymbolSvgItem import SymbolSvgItem |
... | ... | |
604 | 603 |
maxValue = len(items) |
605 | 604 |
self.progress.setMaximum(maxValue) |
606 | 605 |
|
607 |
index = 0 |
|
608 |
for item in items: |
|
609 |
if type(item) is SymbolSvgItem or type(item) is QEngineeringStreamlineItem: |
|
610 |
app_doc_data.saveToDatabase(item, index) |
|
611 |
self.progress.setValue(index) |
|
612 |
index += 1 |
|
613 |
|
|
614 |
QApplication.processEvents() |
|
606 |
app_doc_data.saveToDatabase([item for item in items |
|
607 |
if type(item) is SymbolSvgItem or type(item) is QEngineeringStreamlineItem], |
|
608 |
self.progress.setValue) |
|
615 | 609 |
|
616 | 610 |
if app_doc_data.activeDrawing: |
617 | 611 |
app_doc_data.activeDrawing.hmbTable.saveData() |
... | ... | |
624 | 618 |
drawing.date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
625 | 619 |
app_doc_data.updateDrawing(drawing) |
626 | 620 |
|
621 |
app_doc_data.activeDrawing.modified = False |
|
622 |
self.setMainWindowTitle(f"{app_doc_data.activeDrawing.path}") |
|
623 |
|
|
627 | 624 |
except Exception as ex: |
628 | 625 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
629 | 626 |
sys.exc_info()[-1].tb_lineno) |
... | ... | |
682 | 679 |
self.graphicsView.useDefaultCommand() |
683 | 680 |
self.graphicsView.zoomImageInit() |
684 | 681 |
|
682 |
def scene_changed(self): |
|
683 |
"""update modified flag""" |
|
684 |
|
|
685 |
app_doc_data = AppDocData.instance() |
|
686 |
app_doc_data.activeDrawing.modified = True |
|
687 |
self.setMainWindowTitle(f"{app_doc_data.activeDrawing.path}*") |
|
688 |
|
|
685 | 689 |
''' |
686 | 690 |
@brief selection changed |
687 | 691 |
@author humkyung |
... | ... | |
1536 | 1540 |
try: |
1537 | 1541 |
app_doc_data = AppDocData.instance() |
1538 | 1542 |
|
1539 |
## Set appDocData
|
|
1543 |
# Set appDocData |
|
1540 | 1544 |
app_doc_data.clear() |
1541 | 1545 |
self.onCommandRejected() |
1542 | 1546 |
|
... | ... | |
1548 | 1552 |
self.clear_loop() |
1549 | 1553 |
self.clearlogs() |
1550 | 1554 |
self.clear_output() |
1551 |
## Load data on database
|
|
1555 |
# Load data on database
|
|
1552 | 1556 |
|
1553 | 1557 |
self.symbolTreeWidget.initSymbolTreeWidget() |
1554 | 1558 |
|
... | ... | |
1625 | 1629 |
from datetime import datetime |
1626 | 1630 |
from Drawing import Drawing |
1627 | 1631 |
|
1632 |
self.save_drawing_if_necessary() |
|
1633 |
|
|
1628 | 1634 |
workspace = self.getWorkSpace() |
1629 | 1635 |
|
1630 | 1636 |
options = QFileDialog.Options() |
... | ... | |
1653 | 1659 |
|
1654 | 1660 |
def on_open_drawing(self): |
1655 | 1661 |
""" open selected drawing by user """ |
1656 |
workspace = self.getWorkSpace() |
|
1657 | 1662 |
|
1663 |
self.save_drawing_if_necessary() |
|
1664 |
|
|
1665 |
workspace = self.getWorkSpace() |
|
1658 | 1666 |
options = QFileDialog.Options() |
1659 | 1667 |
options |= QFileDialog.DontUseNativeDialog |
1660 | 1668 |
name, _ = QFileDialog.getOpenFileName(self, self.tr('Open'), workspace, 'HYTOS File(*.hytos)', options=options) |
1661 |
if name: self.open_drawing(name) |
|
1669 |
if name: |
|
1670 |
self.open_drawing(name) |
|
1662 | 1671 |
|
1663 | 1672 |
def open_drawing(self, name): |
1664 | 1673 |
""" open given drawing has name """ |
... | ... | |
1677 | 1686 |
else: |
1678 | 1687 |
drawing = matches[0] |
1679 | 1688 |
|
1689 |
# disconnect scene changed if signal is connected |
|
1690 |
if self.graphicsView.scene.receivers(self.graphicsView.scene.contents_changed) > 0: |
|
1691 |
self.graphicsView.scene.contents_changed.disconnect() |
|
1692 |
|
|
1680 | 1693 |
self.open_border_file() |
1681 | 1694 |
self.load_data(drawing) |
1682 | 1695 |
|
1696 |
# connect scene changed signal |
|
1697 |
self.graphicsView.scene.contents_changed.connect(self.scene_changed) |
|
1698 |
|
|
1683 | 1699 |
def getWorkSpace(self): |
1684 | 1700 |
""" get work space path """ |
1685 | 1701 |
app_doc_data = AppDocData.instance() |
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py | ||
---|---|---|
817 | 817 |
|
818 | 818 |
self.build_path() |
819 | 819 |
self.update() |
820 |
self.scene().contents_changed.emit() |
|
820 | 821 |
|
821 | 822 |
def mouseDoubleClickEvent(self, event): |
822 | 823 |
from StreamDataDialog import QStreamDataDialog |
HYTOS/HYTOS/Shapes/SymbolSvgItem.py | ||
---|---|---|
656 | 656 |
""" call signals when item's position is changed """ |
657 | 657 |
if change == QGraphicsItem.ItemPositionHasChanged: |
658 | 658 |
self.transfer.on_pos_changed.emit(self) |
659 |
self.scene().contents_changed.emit() |
|
659 | 660 |
return value |
660 | 661 |
|
661 | 662 |
return super().itemChange(change, value) |
내보내기 Unified diff