OpenToonz - An open-source full-featured 2D animation creation software
C
Refactor selection handling in ExportLevelPopup and binarizePopup - boarder range
Abel Youfdb3595ee189
diff --git a/toonz/sources/toonz/binarizepopup.cpp b/toonz/sources/toonz/binarizepopup.cppindex 25f30f200..2cf4954f5 100644--- a/toonz/sources/toonz/binarizepopup.cpp+++ b/toonz/sources/toonz/binarizepopup.cpp@@ -7,6 +7,7 @@#include "menubarcommandids.h"#include "cellselection.h"#include "filmstripselection.h"+#include "selectionutils.h"// TnzQt includes#include "toonzqt/intfield.h"@@ -346,6 +347,19 @@ int BinarizePopup::getSelectedFrames() {}}} else {+ std::set<TXshLevel*> levels;+ SelectionUtils::getSelectedLevels(levels);+ for (auto level : levels){+ if (!level)continue;+ auto sl = level->getSimpleLevel();+ std::vector<TFrameId> ids;+ sl->getFids(ids);+ for (auto id : ids) {+ m_frames.push_back(std::make_pair(sl, id));+ count++;+ }++ }}m_frameIndex = 0;return count;diff --git a/toonz/sources/toonz/exportlevelpopup.cpp b/toonz/sources/toonz/exportlevelpopup.cppindex fb968e855..ae9cc0b9f 100644--- a/toonz/sources/toonz/exportlevelpopup.cpp+++ b/toonz/sources/toonz/exportlevelpopup.cpp@@ -10,6 +10,7 @@#include "iocommand.h"#include "exportlevelcommand.h"#include "formatsettingspopups.h"+#include "selectionutils.h"// TnzQt includes#include "toonzqt/checkbox.h"@@ -57,6 +58,8 @@#include <QMessageBox>#include <QDesktopServices>+using namespace SelectionUtils;+//********************************************************************************// Export callbacks definition//********************************************************************************@@ -359,63 +362,42 @@ ExportLevelPopup::~ExportLevelPopup() {void ExportLevelPopup::collectSelectedSimpleLevels() {outputLevels.clear();- TApp *app = TApp::instance();-- TSelection *selection = app->getCurrentSelection()->getSelection();- TColumnSelection *colSelection = dynamic_cast<TColumnSelection *>(selection);-- if (colSelection && colSelection->getIndices().size() > 0) {- bool enabled = false;- TXsheet *xsh = app->getCurrentXsheet()->getXsheet();- const std::set<int> &colIndices = colSelection->getIndices();-- std::set<int>::const_iterator it, end = colIndices.end();- for (it = colIndices.begin(); it != end; ++it) {- int r0, r1, c = *it;- xsh->getCellRange(c, r0, r1);-- if (r0 <= r1) // There exists a not-empty cell- {- TXshSimpleLevel *sl = xsh->getCell(r0, c).getSimpleLevel();- if (!sl) continue;- int type = sl->getType();- if (!(type == PLI_XSHLEVEL || // ToonzVector- type == TZP_XSHLEVEL || // ToonzRaster- type == OVL_XSHLEVEL)) // Raster- continue;-- outputLevels.push_back(sl);- assert(sl);- }- }+ std::set<TXshLevel*> levels;+ getSelectedLevels(levels);+ for (TXshLevel* level : levels) {+ TXshSimpleLevel* sl = level->getSimpleLevel();+ if (!sl)continue;+ int type = sl->getType();+ if (type == PLI_XSHLEVEL || // ToonzVector+ type == TZP_XSHLEVEL || // ToonzRaster+ type == OVL_XSHLEVEL) // Raster+ outputLevels.push_back(sl);}}//-----------------------------------------------------------------------------void ExportLevelPopup::showEvent(QShowEvent *se) {- // Save current selection - will be restored in the hideEvent()- {- TSelectionHandle *selectionHandle = TApp::instance()->getCurrentSelection();- TSelection *selection = selectionHandle->getSelection();if (Preferences::instance()->getPixelsOnly()) {- m_exportOptions->m_widthFld->hide();- m_exportOptions->m_heightFld->hide();- m_exportOptions->m_widthLabel->hide();- m_exportOptions->m_heightLabel->hide();- m_exportOptions->m_dpiLabel->hide();- } else {- m_exportOptions->m_widthFld->show();- m_exportOptions->m_heightFld->show();- m_exportOptions->m_widthLabel->show();- m_exportOptions->m_heightLabel->show();- m_exportOptions->m_dpiLabel->show();+ m_exportOptions->m_widthFld->hide();+ m_exportOptions->m_heightFld->hide();+ m_exportOptions->m_widthLabel->hide();+ m_exportOptions->m_heightLabel->hide();+ m_exportOptions->m_dpiLabel->hide();+ }+ else {+ m_exportOptions->m_widthFld->show();+ m_exportOptions->m_heightFld->show();+ m_exportOptions->m_widthLabel->show();+ m_exportOptions->m_heightLabel->show();+ m_exportOptions->m_dpiLabel->show();}- selectionHandle->pushSelection();- selectionHandle->setSelection(selection);- }// WARNING: What happens it the restored selection is NO MORE VALID ?+ //+ // This Problem is caused because the global selection of dvitemview+ // is on for default browserpopup , which whould cause the global+ // selection to be cleared// Consider that this popup is NOT MODAL !!//// The same applies to all the other popups in@@ -456,9 +438,6 @@ void ExportLevelPopup::hideEvent(QHideEvent *he) {app->getCurrentSelection()->disconnect(this);app->getCurrentLevel()->disconnect(this);- // Restore original selection- TApp::instance()->getCurrentSelection()->popSelection();-// Reset popup statem_swatch->image() = TImageP();}@@ -564,13 +543,18 @@ void ExportLevelPopup::updateOnSelection() {switch (outputLevels.size()) {case 0:+ setWindowTitle(tr("Export Level: No Level Selected"));+ m_nameField->clear();return;case 1:+ setWindowTitle(tr("Export Level: %1 Level Selected").arg("1"));m_nameField->setEnabled(true);m_nameField->setText(QString::fromStdWString(outputLevels.back()->getName()));break;default:+ setWindowTitle(tr("Export Level: %1 Level Selected")+ .arg(outputLevels.size()));m_nameField->clear();m_nameField->setEnabled(false);}