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

Method addHighlightCellsRule

src/3rdparty/QXlsx/source/xlsxconditionalformatting.cpp:158–262  ·  view source on GitHub ↗

! * Add a hightlight rule with the given \a type, \a formula1, \a formula2, * \a format and \a stopIfTrue. * Return false if failed. */

Source from the content-addressed store, hash-verified

156 * Return false if failed.
157 */
158bool ConditionalFormatting::addHighlightCellsRule(HighlightRuleType type, const QString &formula1, const QString &formula2, const Format &format, bool stopIfTrue)
159{
160 if (format.isEmpty())
161 return false;
162
163 bool skipFormula = false;
164
165 auto cfRule = std::make_shared<XlsxCfRuleData>();
166 if (type >= Highlight_LessThan && type <= Highlight_NotBetween) {
167 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("cellIs");
168 QString op;
169 switch (type) {
170 case Highlight_Between: op = QStringLiteral("between"); break;
171 case Highlight_Equal: op = QStringLiteral("equal"); break;
172 case Highlight_GreaterThan: op = QStringLiteral("greaterThan"); break;
173 case Highlight_GreaterThanOrEqual: op = QStringLiteral("greaterThanOrEqual"); break;
174 case Highlight_LessThan: op = QStringLiteral("lessThan"); break;
175 case Highlight_LessThanOrEqual: op = QStringLiteral("lessThanOrEqual"); break;
176 case Highlight_NotBetween: op = QStringLiteral("notBetween"); break;
177 case Highlight_NotEqual: op = QStringLiteral("notEqual"); break;
178 default: break;
179 }
180 cfRule->attrs[XlsxCfRuleData::A_operator] = op;
181 } else if (type >= Highlight_ContainsText && type <= Highlight_EndsWith) {
182 if (type == Highlight_ContainsText) {
183 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsText");
184 cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("containsText");
185 cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(SEARCH(\"%1\",%2)))").arg(formula1);
186 } else if (type == Highlight_NotContainsText) {
187 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsText");
188 cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("notContains");
189 cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(SEARCH(\"%2\",%1))").arg(formula1);
190 } else if (type == Highlight_BeginsWith) {
191 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("beginsWith");
192 cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("beginsWith");
193 cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("LEFT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1);
194 } else {
195 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("endsWith");
196 cfRule->attrs[XlsxCfRuleData::A_operator] = QStringLiteral("endsWith");
197 cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("RIGHT(%2,LEN(\"%1\"))=\"%1\"").arg(formula1);
198 }
199 cfRule->attrs[XlsxCfRuleData::A_text] = formula1;
200 skipFormula = true;
201 } else if (type == Highlight_TimePeriod) {
202 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("timePeriod");
203 //:Todo
204 return false;
205 } else if (type == Highlight_Duplicate) {
206 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("duplicateValues");
207 } else if (type == Highlight_Unique) {
208 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("uniqueValues");
209 } else if (type == Highlight_Errors) {
210 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("containsErrors");
211 cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("ISERROR(%1)");
212 skipFormula = true;
213 } else if (type == Highlight_NoErrors) {
214 cfRule->attrs[XlsxCfRuleData::A_type] = QStringLiteral("notContainsErrors");
215 cfRule->attrs[XlsxCfRuleData::A_formula1_temp] = QStringLiteral("NOT(ISERROR(%1))");

Callers

nothing calls this directly

Calls 4

argMethod · 0.80
appendMethod · 0.80
QStringClass · 0.50
isEmptyMethod · 0.45

Tested by

no test coverage detected