MCPcopy Create free account
hub / github.com/KDE/labplot / dataRegionSelectionChanged

Method dataRegionSelectionChanged

src/frontend/datasources/XLSXOptionsWidget.cpp:62–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void XLSXOptionsWidget::dataRegionSelectionChanged() {
63 DEBUG(Q_FUNC_INFO)
64#ifdef HAVE_QXLSX
65 WAIT_CURSOR;
66
67 const auto& selectedItems = ui.twDataRegions->selectedItems();
68 if (selectedItems.isEmpty()) {
69 RESET_CURSOR;
70 return;
71 }
72
73 if (selectedItems.size() > 1)
74 Q_EMIT enableDataPortionSelection(false);
75 else if (selectedItems.size() == 1)
76 Q_EMIT enableDataPortionSelection(true);
77
78 QXlsx::CellRange selectedRegion;
79 QString sheetName;
80
81 auto* item = selectedItems.last();
82 int column = ui.twDataRegions->currentColumn();
83 int row = ui.twDataRegions->currentIndex().row();
84 const auto& selectedRegionText = item->text(column);
85 auto* const filter = static_cast<XLSXFilter*>(m_fileWidget->currentFileFilter());
86
87 selectedRegion = selectedRegionText;
88 // if sheet name is selected maybe show full sheet?
89 if (item->parent()) {
90 sheetName = item->parent()->text(0);
91 } else {
92 RESET_CURSOR;
93 return;
94 }
95
96 if (!sheetName.isEmpty() && selectedRegion.isValid()) {
97 bool regionCanBeImportedToMatrix = false;
98
99 if (selectedRegion.columnCount() > 100) {
100 const int lastCol = selectedRegion.firstColumn() + 100;
101 selectedRegion.setLastColumn(lastCol);
102 }
103
104 const auto importedStrings = filter->previewForDataRegion(sheetName, selectedRegionText, &regionCanBeImportedToMatrix, ui.sbPreviewLines->value());
105 m_previewString = importedStrings;
106 // QDEBUG("PREVIEW:" << importedStrings)
107
108 // enable the first row as column names option only if the data contains more than 1 row
109 m_fileWidget->enableFirstRowAsColNames(importedStrings.size() > 1);
110
111 Q_EMIT m_fileWidget->enableImportToMatrix(regionCanBeImportedToMatrix);
112
113 // sheet name - item row will identify the region
114 const auto mapVal = qMakePair(sheetName, row);
115 // this region was not currently selected
116 if (m_regionIsPossibleToImportToMatrix.find(mapVal) != m_regionIsPossibleToImportToMatrix.end())
117 m_regionIsPossibleToImportToMatrix.insert(mapVal, regionCanBeImportedToMatrix);
118 else if (!item->isSelected()) // the item was deselected
119 m_regionIsPossibleToImportToMatrix.remove(mapVal);

Callers 1

refreshPreviewMethod · 0.80

Calls 15

selectedItemsMethod · 0.80
currentFileFilterMethod · 0.80
previewForDataRegionMethod · 0.80
insertMethod · 0.80
useFirstRowAsColNamesMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45
rowMethod · 0.45
currentIndexMethod · 0.45
textMethod · 0.45
parentMethod · 0.45

Tested by

no test coverage detected