- the project items color is now controlled from Foreground Role in ObjectCollection.data()

- made again plot functions threaded but moved the dataChanged signal (update_view() ) to the main thread by using an already existing signal (plots_updated signal) to avoid the errors with register QVector
This commit is contained in:
Marius Stanciu 2019-05-01 03:33:15 +03:00
parent eda4202952
commit 8062af7feb
3 changed files with 37 additions and 35 deletions

View File

@ -4979,6 +4979,7 @@ class App(QtCore.QObject):
# self.plotcanvas.auto_adjust_axes()
self.plotcanvas.vispy_canvas.update() # TODO: Need update canvas?
self.on_zoom_fit(None)
self.collection.update_view()
# TODO: Rework toolbar 'clear', 'replot' functions
def on_toolbar_replot(self):
@ -7936,23 +7937,23 @@ The normal flow when working in FlatCAM is the following:</span></p>
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().
'''
def enable_plots(self, objects, threaded=False):
def enable_plots(self, objects, threaded=True):
if threaded is True:
def worker_task(app_obj):
percentage = 0.1
try:
delta = 0.9 / len(objects)
except ZeroDivisionError:
self.progress.emit(0)
return
# percentage = 0.1
# try:
# delta = 0.9 / len(objects)
# except ZeroDivisionError:
# self.progress.emit(0)
# return
for obj in objects:
obj.options['plot'] = True
percentage += delta
self.progress.emit(int(percentage*100))
# percentage += delta
# self.progress.emit(int(percentage*100))
self.progress.emit(0)
# self.progress.emit(0)
self.plots_updated.emit()
self.collection.update_view()
# self.collection.update_view()
# Send to worker
# self.worker.add_task(worker_task, [self])
@ -7960,9 +7961,9 @@ The normal flow when working in FlatCAM is the following:</span></p>
else:
for obj in objects:
obj.options['plot'] = True
self.progress.emit(0)
# self.progress.emit(0)
self.plots_updated.emit()
self.collection.update_view()
# self.collection.update_view()
# TODO: FIX THIS
'''
@ -7972,7 +7973,7 @@ The normal flow when working in FlatCAM is the following:</span></p>
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().
'''
def disable_plots(self, objects, threaded=False):
def disable_plots(self, objects, threaded=True):
# TODO: This method is very similar to replot_all. Try to merge.
"""
Disables plots
@ -7982,23 +7983,23 @@ The normal flow when working in FlatCAM is the following:</span></p>
"""
if threaded is True:
self.progress.emit(10)
# self.progress.emit(10)
def worker_task(app_obj):
percentage = 0.1
try:
delta = 0.9 / len(objects)
except ZeroDivisionError:
self.progress.emit(0)
return
# percentage = 0.1
# try:
# delta = 0.9 / len(objects)
# except ZeroDivisionError:
# self.progress.emit(0)
# return
for obj in objects:
obj.options['plot'] = False
percentage += delta
self.progress.emit(int(percentage*100))
# percentage += delta
# self.progress.emit(int(percentage*100))
self.progress.emit(0)
# self.progress.emit(0)
self.plots_updated.emit()
self.collection.update_view()
# self.collection.update_view()
# Send to worker
self.worker_task.emit({'fcn': worker_task, 'params': [self]})
@ -8006,7 +8007,7 @@ The normal flow when working in FlatCAM is the following:</span></p>
for obj in objects:
obj.options['plot'] = False
self.plots_updated.emit()
self.collection.update_view()
# self.collection.update_view()
def clear_plots(self):

View File

@ -256,13 +256,6 @@ class ObjectCollection(QtCore.QAbstractItemModel):
# self.view.setAcceptDrops(True)
# self.view.setDropIndicatorShown(True)
color = self.app.defaults['global_proj_item_color']
# set StyleSheet
stylesheet = "QTreeView::item {color: %s;}" % color
self.view.setStyleSheet(stylesheet)
font = QtGui.QFont()
font.setPixelSize(12)
font.setFamily("Seagoe UI")
@ -385,9 +378,10 @@ class ObjectCollection(QtCore.QAbstractItemModel):
return index.internalPointer().data(index.column())
if role == Qt.ForegroundRole:
color = QColor(self.app.defaults['global_proj_item_color'])
obj = index.internalPointer().obj
if obj:
return QtGui.QBrush(QtCore.Qt.black) if obj.options["plot"] else QtGui.QBrush(QtCore.Qt.darkGray)
return QtGui.QBrush(color) if obj.options["plot"] else QtGui.QBrush(QtCore.Qt.lightGray)
else:
return index.internalPointer().data(index.column())
@ -690,6 +684,8 @@ class ObjectCollection(QtCore.QAbstractItemModel):
:param name: Name of the FlatCAM Object
:return: None
"""
log.debug("ObjectCollection.set_inactive()")
obj = self.get_by_name(name)
item = obj.item
group = self.group_items[obj.kind]
@ -769,4 +765,4 @@ class ObjectCollection(QtCore.QAbstractItemModel):
return obj_list
def update_view(self):
self.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
self.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex(), [QtCore.Qt.EditRole])

View File

@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing.
=================================================
01.05.2019
- the project items color is now controlled from Foreground Role in ObjectCollection.data()
- made again plot functions threaded but moved the dataChanged signal (update_view() ) to the main thread by using an already existing signal (plots_updated signal) to avoid the errors with register QVector
30.04.2019
- in ObjectCollection class, made sure that renaming an object in Project View does not result in an empty name. If new name is blank the rename is cancelled.