File indexing completed on 2024-05-12 15:58:47
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_update_selection_job.h" 0008 #include "kis_image.h" 0009 #include "kis_projection_leaf.h" 0010 0011 0012 KisUpdateSelectionJob::KisUpdateSelectionJob(KisSelectionSP selection, const QRect &updateRect) 0013 : m_selection(selection), 0014 m_updateRect(updateRect) 0015 { 0016 /** 0017 * TODO: we should implement correct KisShapeSelectionCanvas for 0018 * projection. See a comment in KisUpdateSelectionJob::run(). 0019 * 0020 * Right now, since this job accesses some projections for write, we 0021 * should declare it as exclusive 0022 */ 0023 0024 setExclusive(true); 0025 } 0026 0027 bool KisUpdateSelectionJob::overrides(const KisSpontaneousJob *_otherJob) 0028 { 0029 const KisUpdateSelectionJob *otherJob = 0030 dynamic_cast<const KisUpdateSelectionJob*>(_otherJob); 0031 0032 bool retval = false; 0033 0034 if (otherJob && otherJob->m_selection == m_selection) { 0035 if (!m_updateRect.isEmpty()) { 0036 m_updateRect |= otherJob->m_updateRect; 0037 } 0038 retval = true; 0039 } 0040 0041 return retval; 0042 } 0043 0044 void KisUpdateSelectionJob::run() 0045 { 0046 QRect dirtyRect; 0047 0048 KisNodeSP parentNode = m_selection->parentNode(); 0049 if (parentNode) { 0050 dirtyRect = parentNode->extent(); 0051 } 0052 0053 if (!m_updateRect.isEmpty()) { 0054 m_selection->updateProjection(m_updateRect); 0055 } else { 0056 m_selection->updateProjection(); 0057 } 0058 0059 m_selection->notifySelectionChanged(); 0060 0061 /** 0062 * TODO: in the future we should remove selection projection calculation 0063 * from this job and to reuse a fully-featured shape layer canvas 0064 * from KisShapeLayer. Then projection calculation will be a little 0065 * bit more efficient. 0066 */ 0067 if (parentNode && parentNode->projectionLeaf()->isOverlayProjectionLeaf()) { 0068 dirtyRect |= parentNode->extent(); 0069 parentNode->setDirty(dirtyRect); 0070 } 0071 } 0072 0073 int KisUpdateSelectionJob::levelOfDetail() const 0074 { 0075 return 0; 0076 } 0077 0078 QString KisUpdateSelectionJob::debugName() const 0079 { 0080 return "KisUpdateSelectionJob"; 0081 }