Changeset View
Changeset View
Standalone View
Standalone View
libs/pigment/resources/KoColorSet.cpp
Context not available. | |||||
97 | d->paletteType = rhs.d->paletteType; | 97 | d->paletteType = rhs.d->paletteType; | ||
---|---|---|---|---|---|
98 | d->data = rhs.d->data; | 98 | d->data = rhs.d->data; | ||
99 | d->comment = rhs.d->comment; | 99 | d->comment = rhs.d->comment; | ||
100 | d->groupNames = rhs.d->groupNames; | | |||
101 | d->groups = rhs.d->groups; | 100 | d->groups = rhs.d->groups; | ||
102 | d->isGlobal = rhs.d->isGlobal; | 101 | d->isGlobal = rhs.d->isGlobal; | ||
103 | d->isEditable = rhs.d->isEditable; | 102 | d->isEditable = rhs.d->isEditable; | ||
Context not available. | |||||
128 | 127 | | |||
129 | d->data = dev->readAll(); | 128 | d->data = dev->readAll(); | ||
130 | 129 | | |||
131 | Q_ASSERT(d->data.size() != 0); | 130 | if (d->data.size() == 0) { | ||
131 | return false; | ||||
132 | } | ||||
132 | 133 | | |||
133 | return d->init(); | 134 | return d->init(); | ||
134 | } | 135 | } | ||
Context not available. | |||||
231 | 232 | | |||
232 | quint32 KoColorSet::colorCount() const | 233 | quint32 KoColorSet::colorCount() const | ||
233 | { | 234 | { | ||
234 | int colorCount = d->groups[GLOBAL_GROUP_NAME].colorCount(); | 235 | int colorCount = 0; | ||
235 | for (KisSwatchGroup &g : d->groups.values()) { | 236 | for (KisSwatchGroup &g : d->groups) { | ||
236 | colorCount += g.colorCount(); | 237 | colorCount += g.colorCount(); | ||
237 | } | 238 | } | ||
238 | return colorCount; | 239 | return colorCount; | ||
Context not available. | |||||
240 | 241 | | |||
241 | void KoColorSet::add(const KisSwatch &c, const QString &groupName) | 242 | void KoColorSet::add(const KisSwatch &c, const QString &groupName) | ||
242 | { | 243 | { | ||
243 | KisSwatchGroup &modifiedGroup = d->groups.contains(groupName) | 244 | for (KisSwatchGroup &g : d->groups) { | ||
244 | ? d->groups[groupName] : d->global(); | 245 | if (g.name() == groupName) { | ||
245 | modifiedGroup.addEntry(c); | 246 | g.addEntry(c); | ||
247 | return; | ||||
248 | } | ||||
249 | } | ||||
250 | d->global().addEntry(c); | ||||
246 | } | 251 | } | ||
247 | 252 | | |||
248 | void KoColorSet::setEntry(const KisSwatch &e, int x, int y, const QString &groupName) | 253 | void KoColorSet::setEntry(const KisSwatch &e, int x, int y, | ||
254 | const QString &groupName) | ||||
249 | { | 255 | { | ||
250 | KisSwatchGroup &modifiedGroup = d->groups.contains(groupName) | 256 | for (KisSwatchGroup &g : d->groups) { | ||
251 | ? d->groups[groupName] : d->global(); | 257 | if (g.name() == groupName) { | ||
252 | modifiedGroup.setEntry(e, x, y); | 258 | g.setEntry(e, x, y); | ||
259 | return; | ||||
260 | } | ||||
261 | } | ||||
262 | d->global().setEntry(e, x, y); | ||||
253 | } | 263 | } | ||
254 | 264 | | |||
255 | void KoColorSet::clear() | 265 | void KoColorSet::clear() | ||
256 | { | 266 | { | ||
257 | d->groups.clear(); | 267 | d->groups.clear(); | ||
258 | d->groupNames.clear(); | 268 | d->groups.push_front(KisSwatchGroup()); | ||
259 | d->groups[GLOBAL_GROUP_NAME] = KisSwatchGroup(); | 269 | d->global().setName(GLOBAL_GROUP_NAME); | ||
260 | d->groupNames.append(GLOBAL_GROUP_NAME); | | |||
261 | } | 270 | } | ||
262 | 271 | | |||
263 | KisSwatch KoColorSet::getColorGlobal(quint32 x, quint32 y) const | 272 | KisSwatch KoColorSet::getColorGlobal(quint32 x, quint32 y) const | ||
264 | { | 273 | { | ||
265 | int yInGroup = y; | 274 | int yInGroup = y; | ||
266 | QString nameGroupFoundIn; | 275 | const KisSwatchGroup *groupFoundIn = nullptr; | ||
267 | for (const QString &groupName : d->groupNames) { | 276 | for (const KisSwatchGroup &g : d->groups) { | ||
268 | if (yInGroup < d->groups[groupName].rowCount()) { | 277 | if (yInGroup < g.rowCount()) { | ||
269 | nameGroupFoundIn = groupName; | 278 | groupFoundIn = &g; | ||
270 | break; | 279 | break; | ||
271 | } else { | 280 | } else { | ||
272 | yInGroup -= d->groups[groupName].rowCount(); | 281 | yInGroup -= d->global().rowCount(); | ||
273 | } | 282 | } | ||
274 | } | 283 | } | ||
275 | const KisSwatchGroup &groupFoundIn = nameGroupFoundIn == GLOBAL_GROUP_NAME | 284 | if (!groupFoundIn) { | ||
276 | ? d->global() : d->groups[nameGroupFoundIn]; | 285 | groupFoundIn = &d->global(); | ||
277 | Q_ASSERT(groupFoundIn.checkEntry(x, yInGroup)); | 286 | } | ||
278 | return groupFoundIn.getEntry(x, yInGroup); | 287 | Q_ASSERT(groupFoundIn->checkEntry(x, yInGroup)); | ||
288 | return groupFoundIn->getEntry(x, yInGroup); | ||||
279 | } | 289 | } | ||
280 | 290 | | |||
281 | KisSwatch KoColorSet::getColorGroup(quint32 x, quint32 y, QString groupName) | 291 | KisSwatch KoColorSet::getColorGroup(quint32 x, quint32 y, QString groupName) | ||
282 | { | 292 | { | ||
283 | KisSwatch e; | 293 | KisSwatch e; | ||
284 | const KisSwatchGroup &sourceGroup = groupName == QString() | 294 | KisSwatchGroup *sourceGroup = nullptr; | ||
285 | ? d->global() : d->groups[groupName]; | 295 | for (KisSwatchGroup &g : d->groups) { | ||
286 | if (sourceGroup.checkEntry(x, y)) { | 296 | if (g.name() == groupName) { | ||
287 | e = sourceGroup.getEntry(x, y); | 297 | sourceGroup = &g; | ||
298 | break; | ||||
299 | } | ||||
300 | } | ||||
301 | if (!sourceGroup) { | ||||
302 | sourceGroup = &d->global(); | ||||
303 | } | ||||
304 | if (sourceGroup->checkEntry(x, y)) { | ||||
305 | e = sourceGroup->getEntry(x, y); | ||||
288 | } | 306 | } | ||
289 | return e; | 307 | return e; | ||
290 | } | 308 | } | ||
291 | 309 | | |||
292 | QStringList KoColorSet::getGroupNames() | 310 | QStringList KoColorSet::getGroupNames() | ||
293 | { | 311 | { | ||
294 | if (d->groupNames.size() != d->groups.size()) { | 312 | QStringList tmp; | ||
295 | warnPigment << "mismatch between groups and the groupnames list."; | 313 | for (KisSwatchGroup &g : d->groups) { | ||
296 | return QStringList(d->groups.keys()); | 314 | tmp.append(g.name()); | ||
297 | } | 315 | } | ||
298 | return d->groupNames; | 316 | return tmp; | ||
317 | } | ||||
318 | | ||||
319 | QList<KisSwatchGroup> &KoColorSet::getGroups() | ||||
320 | { | ||||
321 | return d->groups; | ||||
299 | } | 322 | } | ||
300 | 323 | | |||
301 | bool KoColorSet::changeGroupName(const QString &oldGroupName, const QString &newGroupName) | 324 | bool KoColorSet::changeGroupName(const QString &oldGroupName, const QString &newGroupName) | ||
302 | { | 325 | { | ||
303 | if (!d->groups.contains(oldGroupName)) { | 326 | KisSwatchGroup *targetGroup = getGroup(oldGroupName); | ||
327 | if (!targetGroup) { | ||||
304 | return false; | 328 | return false; | ||
305 | } | 329 | } | ||
306 | if (oldGroupName == newGroupName) { | 330 | if (oldGroupName == newGroupName) { | ||
307 | return true; | 331 | return true; | ||
308 | } | 332 | } | ||
309 | d->groups[newGroupName] = d->groups[oldGroupName]; | 333 | targetGroup->setName(newGroupName); | ||
310 | d->groups.remove(oldGroupName); | | |||
311 | d->groups[newGroupName].setName(newGroupName); | | |||
312 | //rename the string in the stringlist; | | |||
313 | int index = d->groupNames.indexOf(oldGroupName); | | |||
314 | d->groupNames.replace(index, newGroupName); | | |||
315 | return true; | 334 | return true; | ||
316 | } | 335 | } | ||
317 | 336 | | |||
318 | void KoColorSet::setColumnCount(int columns) | 337 | void KoColorSet::setColumnCount(int columns) | ||
319 | { | 338 | { | ||
320 | d->groups[GLOBAL_GROUP_NAME].setColumnCount(columns); | 339 | for (KisSwatchGroup &g : d->groups) { | ||
321 | for (KisSwatchGroup &g : d->groups.values()) { | | |||
322 | g.setColumnCount(columns); | 340 | g.setColumnCount(columns); | ||
323 | } | 341 | } | ||
324 | } | 342 | } | ||
325 | 343 | | |||
326 | int KoColorSet::columnCount() const | 344 | int KoColorSet::columnCount() const | ||
327 | { | 345 | { | ||
328 | return d->groups[GLOBAL_GROUP_NAME].columnCount(); | 346 | return d->global().columnCount(); | ||
329 | } | 347 | } | ||
330 | 348 | | |||
331 | QString KoColorSet::comment() | 349 | QString KoColorSet::comment() | ||
Context not available. | |||||
338 | d->comment = comment; | 356 | d->comment = comment; | ||
339 | } | 357 | } | ||
340 | 358 | | |||
341 | bool KoColorSet::addGroup(const QString &groupName) | 359 | bool KoColorSet::addGroup(const QString &newGroupName) | ||
342 | { | 360 | { | ||
343 | if (d->groups.contains(groupName) || d->groupNames.contains(groupName)) { | 361 | for (KisSwatchGroup &g : d->groups) { | ||
344 | return false; | 362 | if (g.name() == newGroupName) { | ||
363 | return false; | ||||
364 | } | ||||
345 | } | 365 | } | ||
346 | d->groupNames.append(groupName); | 366 | KisSwatchGroup newGroup; | ||
347 | d->groups[groupName] = KisSwatchGroup(); | 367 | newGroup.setName(newGroupName); | ||
348 | d->groups[groupName].setName(groupName); | 368 | d->groups.append(newGroup); | ||
349 | return true; | 369 | return true; | ||
350 | } | 370 | } | ||
351 | 371 | | |||
352 | bool KoColorSet::moveGroup(const QString &groupName, const QString &groupNameInsertBefore) | 372 | bool KoColorSet::moveGroup(const QString &groupName, | ||
373 | const QString &groupNameInsertBefore) | ||||
353 | { | 374 | { | ||
354 | if (d->groupNames.contains(groupName)==false || d->groupNames.contains(groupNameInsertBefore)==false) { | 375 | int currentIndex = -1, groupInsertBeforeIndex = -1; | ||
376 | int i = 0; | ||||
377 | for (KisSwatchGroup &g : d->groups) { | ||||
378 | if (g.name() == groupName) { | ||||
379 | currentIndex = i; | ||||
380 | } | ||||
381 | if (g.name() == groupNameInsertBefore) { | ||||
382 | groupInsertBeforeIndex = i; | ||||
383 | } | ||||
384 | if (currentIndex != -1 && groupInsertBeforeIndex != -1) { | ||||
385 | break; | ||||
386 | } | ||||
387 | i++; | ||||
388 | } | ||||
389 | if (currentIndex == -1 || currentIndex == 0 || | ||||
390 | groupInsertBeforeIndex == -1 || groupInsertBeforeIndex == 0) { | ||||
355 | return false; | 391 | return false; | ||
356 | } | 392 | } | ||
357 | if (groupNameInsertBefore != GLOBAL_GROUP_NAME && groupName != GLOBAL_GROUP_NAME) { | 393 | if (groupInsertBeforeIndex == currentIndex) { | ||
358 | d->groupNames.removeAt(d->groupNames.indexOf(groupName)); | 394 | return true; | ||
359 | int index = d->groupNames.indexOf(groupNameInsertBefore); | 395 | } | ||
360 | d->groupNames.insert(index, groupName); | 396 | if (groupInsertBeforeIndex == currentIndex + 1) { | ||
397 | return true; | ||||
398 | } | ||||
399 | if (groupInsertBeforeIndex > currentIndex) { | ||||
400 | d->groups.insert(groupInsertBeforeIndex, d->groups[currentIndex]); | ||||
401 | d->groups.removeAt(currentIndex); | ||||
402 | return true; | ||||
403 | } else { // i.e. groupInsertBeforeIndex < currentIndex | ||||
404 | d->groups.insert(groupInsertBeforeIndex, d->groups[currentIndex]); | ||||
405 | d->groups.removeAt(currentIndex + 1); | ||||
406 | return true; | ||||
361 | } | 407 | } | ||
362 | return true; | | |||
363 | } | 408 | } | ||
364 | 409 | | |||
365 | bool KoColorSet::removeGroup(const QString &groupName, bool keepColors) | 410 | bool KoColorSet::removeGroup(const QString &groupName, bool keepColors) | ||
366 | { | 411 | { | ||
367 | if (!d->groups.contains(groupName)) { | | |||
368 | return false; | | |||
369 | } | | |||
370 | | ||||
371 | if (groupName == GLOBAL_GROUP_NAME) { | 412 | if (groupName == GLOBAL_GROUP_NAME) { | ||
372 | return false; | 413 | return false; | ||
373 | } | 414 | } | ||
374 | 415 | | |||
375 | if (keepColors) { | 416 | int i = 0; | ||
376 | // put all colors directly below global | 417 | for (KisSwatchGroup &g : d->groups) { | ||
377 | int startingRow = d->groups[GLOBAL_GROUP_NAME].rowCount(); | 418 | if (g.name() == groupName) { | ||
378 | for (const KisSwatchGroup::SwatchInfo &info : d->groups[groupName].infoList()) { | 419 | if (keepColors) { | ||
379 | d->groups[GLOBAL_GROUP_NAME].setEntry(info.swatch, | 420 | // put all colors directly below global | ||
380 | info.column, | 421 | int startingRow = g.rowCount(); | ||
381 | info.row + startingRow); | 422 | for (const KisSwatchGroup::SwatchInfo &info : g.infoList()) { | ||
423 | d->global().setEntry(info.swatch, | ||||
424 | info.column, | ||||
425 | info.row + startingRow); | ||||
426 | } | ||||
427 | } | ||||
428 | d->groups.removeAt(i); | ||||
429 | return true; | ||||
382 | } | 430 | } | ||
431 | i++; | ||||
383 | } | 432 | } | ||
384 | 433 | return false; | |||
385 | d->groupNames.removeAt(d->groupNames.indexOf(groupName)); | | |||
386 | d->groups.remove(groupName); | | |||
387 | return true; | | |||
388 | } | 434 | } | ||
389 | 435 | | |||
390 | QString KoColorSet::defaultFileExtension() const | 436 | QString KoColorSet::defaultFileExtension() const | ||
Context not available. | |||||
396 | int KoColorSet::rowCount() const | 442 | int KoColorSet::rowCount() const | ||
397 | { | 443 | { | ||
398 | int res = 0; | 444 | int res = 0; | ||
399 | for (const QString &name : d->groupNames) { | 445 | for (const KisSwatchGroup &g: d->groups) { | ||
400 | res += d->groups[name].rowCount(); | 446 | res += g.rowCount(); | ||
401 | } | 447 | } | ||
402 | return res; | 448 | return res; | ||
403 | } | 449 | } | ||
404 | 450 | | |||
405 | KisSwatchGroup *KoColorSet::getGroup(const QString &name) | 451 | KisSwatchGroup *KoColorSet::getGroup(const QString &name) | ||
406 | { | 452 | { | ||
407 | if (!d->groups.contains(name)) { | 453 | for (KisSwatchGroup &g: d->groups) { | ||
408 | return Q_NULLPTR; | 454 | if (g.name() == name) { | ||
455 | return &g; | ||||
456 | } | ||||
409 | } | 457 | } | ||
410 | return &(d->groups[name]); | 458 | return Q_NULLPTR; | ||
411 | } | 459 | } | ||
412 | 460 | | |||
413 | KisSwatchGroup *KoColorSet::getGlobalGroup() | 461 | KisSwatchGroup *KoColorSet::getGlobalGroup() | ||
Context not available. | |||||
442 | quint8 highestPercentage = 0; | 490 | quint8 highestPercentage = 0; | ||
443 | quint8 testPercentage = 0; | 491 | quint8 testPercentage = 0; | ||
444 | 492 | | |||
445 | for (const QString &groupName : getGroupNames()) { | 493 | for (const KisSwatchGroup &group : d->groups) { | ||
446 | KisSwatchGroup *group = getGroup(groupName); | 494 | for (const KisSwatchGroup::SwatchInfo &currInfo : group.infoList()) { | ||
447 | for (const KisSwatchGroup::SwatchInfo &currInfo : group->infoList()) { | | |||
448 | KoColor color = currInfo.swatch.color(); | 495 | KoColor color = currInfo.swatch.color(); | ||
449 | if (useGivenColorSpace == true && compare.colorSpace() != color.colorSpace()) { | 496 | if (useGivenColorSpace == true && compare.colorSpace() != color.colorSpace()) { | ||
450 | color.convertTo(compare.colorSpace()); | 497 | color.convertTo(compare.colorSpace()); | ||
Context not available. | |||||
470 | , isGlobal(true) | 517 | , isGlobal(true) | ||
471 | , isEditable(false) | 518 | , isEditable(false) | ||
472 | { | 519 | { | ||
473 | groups[KoColorSet::GLOBAL_GROUP_NAME] = KisSwatchGroup(); | 520 | KisSwatchGroup newGroup; | ||
474 | groupNames.append(KoColorSet::GLOBAL_GROUP_NAME); | 521 | newGroup.setName(GLOBAL_GROUP_NAME); | ||
522 | groups.append(newGroup); | ||||
475 | } | 523 | } | ||
476 | 524 | | |||
477 | KoColorSet::PaletteType KoColorSet::Private::detectFormat(const QString &fileName, const QByteArray &ba) | 525 | KoColorSet::PaletteType KoColorSet::Private::detectFormat(const QString &fileName, const QByteArray &ba) | ||
Context not available. | |||||
640 | bool KoColorSet::Private::init() | 688 | bool KoColorSet::Private::init() | ||
641 | { | 689 | { | ||
642 | // just in case this is a reload (eg by KoEditColorSetDialog), | 690 | // just in case this is a reload (eg by KoEditColorSetDialog), | ||
643 | groupNames.clear(); | | |||
644 | groups.clear(); | 691 | groups.clear(); | ||
645 | groupNames.append(KoColorSet::GLOBAL_GROUP_NAME); | 692 | KisSwatchGroup globalGroup; | ||
646 | groups[KoColorSet::GLOBAL_GROUP_NAME] = KisSwatchGroup(); | 693 | globalGroup.setName(GLOBAL_GROUP_NAME); | ||
694 | groups.append(KisSwatchGroup()); | ||||
647 | 695 | | |||
648 | if (colorSet->filename().isNull()) { | 696 | if (colorSet->filename().isNull()) { | ||
649 | warnPigment << "Cannot load palette" << colorSet->name() << "there is no filename set"; | 697 | warnPigment << "Cannot load palette" << colorSet->name() << "there is no filename set"; | ||
Context not available. | |||||
720 | * groups[KoColorSet::GLOBAL_GROUP_NAME] so that saveGpl can stay const | 768 | * groups[KoColorSet::GLOBAL_GROUP_NAME] so that saveGpl can stay const | ||
721 | */ | 769 | */ | ||
722 | 770 | | |||
723 | for (int y = 0; y < groups[KoColorSet::GLOBAL_GROUP_NAME].rowCount(); y++) { | 771 | for (int y = 0; y < groups[0].rowCount(); y++) { | ||
724 | for (int x = 0; x < colorSet->columnCount(); x++) { | 772 | for (int x = 0; x < colorSet->columnCount(); x++) { | ||
725 | if (!groups[KoColorSet::GLOBAL_GROUP_NAME].checkEntry(x, y)) { | 773 | if (!groups[0].checkEntry(x, y)) { | ||
726 | continue; | 774 | continue; | ||
727 | } | 775 | } | ||
728 | const KisSwatch& entry = groups[KoColorSet::GLOBAL_GROUP_NAME].getEntry(x, y); | 776 | const KisSwatch& entry = groups[0].getEntry(x, y); | ||
729 | QColor c = entry.color().toQColor(); | 777 | QColor c = entry.color().toQColor(); | ||
730 | stream << c.red() << " " << c.green() << " " << c.blue() << "\t"; | 778 | stream << c.red() << " " << c.green() << " " << c.blue() << "\t"; | ||
731 | if (entry.name().isEmpty()) | 779 | if (entry.name().isEmpty()) | ||
Context not available. | |||||
846 | quint8 g = data[i+1]; | 894 | quint8 g = data[i+1]; | ||
847 | quint8 b = data[i+2]; | 895 | quint8 b = data[i+2]; | ||
848 | e.setColor(KoColor(QColor(r, g, b), KoColorSpaceRegistry::instance()->rgb8())); | 896 | e.setColor(KoColor(QColor(r, g, b), KoColorSpaceRegistry::instance()->rgb8())); | ||
849 | groups[KoColorSet::GLOBAL_GROUP_NAME].addEntry(e); | 897 | groups[0].addEntry(e); | ||
850 | } | 898 | } | ||
851 | return true; | 899 | return true; | ||
852 | } | 900 | } | ||
Context not available. | |||||
885 | QString name = a.join(" "); | 933 | QString name = a.join(" "); | ||
886 | e.setName(name.isEmpty() ? i18n("Untitled") : name); | 934 | e.setName(name.isEmpty() ? i18n("Untitled") : name); | ||
887 | 935 | | |||
888 | groups[KoColorSet::GLOBAL_GROUP_NAME].addEntry(e); | 936 | groups[0].addEntry(e); | ||
889 | } | 937 | } | ||
890 | return true; | 938 | return true; | ||
891 | } | 939 | } | ||
Context not available. | |||||
1050 | Q_UNUSED(v2); | 1098 | Q_UNUSED(v2); | ||
1051 | } | 1099 | } | ||
1052 | if (!skip) { | 1100 | if (!skip) { | ||
1053 | groups[KoColorSet::GLOBAL_GROUP_NAME].addEntry(e); | 1101 | groups[0].addEntry(e); | ||
1054 | } | 1102 | } | ||
1055 | } | 1103 | } | ||
1056 | return true; | 1104 | return true; | ||
Context not available. | |||||
1399 | return false; | 1447 | return false; | ||
1400 | } | 1448 | } | ||
1401 | if (materialsBook.contains(id)) { | 1449 | if (materialsBook.contains(id)) { | ||
1402 | groups[KoColorSet::GLOBAL_GROUP_NAME].addEntry(materialsBook.value(id)); | 1450 | groups[0].addEntry(materialsBook.value(id)); | ||
1403 | } | 1451 | } | ||
1404 | else { | 1452 | else { | ||
1405 | warnPigment << "Invalid swatch definition (material not found) (line" << swatch.lineNumber() << ", column" << swatch.columnNumber() << ")"; | 1453 | warnPigment << "Invalid swatch definition (material not found) (line" << swatch.lineNumber() << ", column" << swatch.columnNumber() << ")"; | ||
Context not available. | |||||
1427 | warnPigment << "Invalid swatch definition (no material id) (line" << groupSwatch.lineNumber() << ", column" << groupSwatch.columnNumber() << ")"; | 1475 | warnPigment << "Invalid swatch definition (no material id) (line" << groupSwatch.lineNumber() << ", column" << groupSwatch.columnNumber() << ")"; | ||
1428 | return false; | 1476 | return false; | ||
1429 | } | 1477 | } | ||
1478 | KisSwatchGroup *g = | ||||
1479 | colorSet->getGroup(currentGroupName); | ||||
1430 | if (materialsBook.contains(id)) { | 1480 | if (materialsBook.contains(id)) { | ||
1431 | groups[currentGroupName].addEntry(materialsBook.value(id)); | 1481 | g->addEntry(materialsBook.value(id)); | ||
1432 | } | 1482 | } | ||
1433 | else { | 1483 | else { | ||
1434 | warnPigment << "Invalid swatch definition (material not found) (line" << groupSwatch.lineNumber() << ", column" << groupSwatch.columnNumber() << ")"; | 1484 | warnPigment << "Invalid swatch definition (material not found) (line" << groupSwatch.lineNumber() << ", column" << groupSwatch.columnNumber() << ")"; | ||
Context not available. | |||||
1490 | root.setAttribute(KPL_PALETTE_READONLY_ATTR, | 1540 | root.setAttribute(KPL_PALETTE_READONLY_ATTR, | ||
1491 | (colorSet->isEditable() || !colorSet->isGlobal()) ? "false" : "true"); | 1541 | (colorSet->isEditable() || !colorSet->isGlobal()) ? "false" : "true"); | ||
1492 | root.setAttribute(KPL_PALETTE_COLUMN_COUNT_ATTR, colorSet->columnCount()); | 1542 | root.setAttribute(KPL_PALETTE_COLUMN_COUNT_ATTR, colorSet->columnCount()); | ||
1493 | root.setAttribute(KPL_GROUP_ROW_COUNT_ATTR, groups[KoColorSet::GLOBAL_GROUP_NAME].rowCount()); | 1543 | root.setAttribute(KPL_GROUP_ROW_COUNT_ATTR, groups[0].rowCount()); | ||
1494 | 1544 | | |||
1495 | saveKplGroup(doc, root, colorSet->getGroup(KoColorSet::GLOBAL_GROUP_NAME), colorSpaces); | 1545 | saveKplGroup(doc, root, &groups[0], colorSpaces); | ||
1496 | 1546 | | |||
1497 | for (const QString &groupName : groupNames) { | 1547 | for (const KisSwatchGroup &g : groups) { | ||
1498 | if (groupName == KoColorSet::GLOBAL_GROUP_NAME) { continue; } | 1548 | if (g.name() == KoColorSet::GLOBAL_GROUP_NAME) { continue; } | ||
1499 | QDomElement gl = doc.createElement(KPL_GROUP_TAG); | 1549 | QDomElement gl = doc.createElement(KPL_GROUP_TAG); | ||
1500 | gl.setAttribute(KPL_GROUP_NAME_ATTR, groupName); | 1550 | gl.setAttribute(KPL_GROUP_NAME_ATTR, g.name()); | ||
1501 | root.appendChild(gl); | 1551 | root.appendChild(gl); | ||
1502 | saveKplGroup(doc, gl, colorSet->getGroup(groupName), colorSpaces); | 1552 | saveKplGroup(doc, gl, &g, colorSpaces); | ||
1503 | } | 1553 | } | ||
1504 | 1554 | | |||
1505 | doc.appendChild(root); | 1555 | doc.appendChild(root); | ||
Context not available. | |||||
1526 | profileElement.appendChild(el); | 1576 | profileElement.appendChild(el); | ||
1527 | 1577 | | |||
1528 | } | 1578 | } | ||
1579 | | ||||
1529 | doc.appendChild(profileElement); | 1580 | doc.appendChild(profileElement); | ||
1530 | if (!store->open("profiles.xml")) { return false; } | 1581 | if (!store->open("profiles.xml")) { return false; } | ||
1531 | QByteArray ba = doc.toByteArray(); | 1582 | QByteArray ba = doc.toByteArray(); | ||
Context not available. | |||||
1538 | void KoColorSet::Private::saveKplGroup(QDomDocument &doc, | 1589 | void KoColorSet::Private::saveKplGroup(QDomDocument &doc, | ||
1539 | QDomElement &groupEle, | 1590 | QDomElement &groupEle, | ||
1540 | const KisSwatchGroup *group, | 1591 | const KisSwatchGroup *group, | ||
1541 | QSet<const KoColorSpace *> &colorSetSet) const | 1592 | QSet<const KoColorSpace *> &colorSpaceSet) const | ||
1542 | { | 1593 | { | ||
1594 | QSet<QString> colorSpaceNameSet; | ||||
1595 | for (const KoColorSpace *cs : colorSpaceSet) { | ||||
1596 | colorSpaceNameSet.insert(cs->profile()->fileName()); | ||||
1597 | } | ||||
1598 | | ||||
1543 | groupEle.setAttribute(KPL_GROUP_ROW_COUNT_ATTR, QString::number(group->rowCount())); | 1599 | groupEle.setAttribute(KPL_GROUP_ROW_COUNT_ATTR, QString::number(group->rowCount())); | ||
1544 | 1600 | | |||
1545 | for (const SwatchInfoType &info : group->infoList()) { | 1601 | for (const SwatchInfoType &info : group->infoList()) { | ||
1546 | const KoColorProfile *profile = info.swatch.color().colorSpace()->profile(); | 1602 | const KoColorProfile *profile = info.swatch.color().colorSpace()->profile(); | ||
1547 | // Only save non-builtin profiles.= | 1603 | // Only save non-builtin profiles. | ||
1548 | if (!profile->fileName().isEmpty()) { | 1604 | // Multiple profiles can be from one same file. | ||
1549 | colorSetSet.insert(info.swatch.color().colorSpace()); | 1605 | // Do not store the file again if it is already there. | ||
1606 | if (!profile->fileName().isEmpty() && !colorSpaceNameSet.contains(profile->fileName())) { | ||||
1607 | colorSpaceNameSet.insert(profile->fileName()); | ||||
1608 | colorSpaceSet.insert(info.swatch.color().colorSpace()); | ||||
1550 | } | 1609 | } | ||
1551 | QDomElement swatchEle = doc.createElement(KPL_SWATCH_TAG); | 1610 | QDomElement swatchEle = doc.createElement(KPL_SWATCH_TAG); | ||
1552 | swatchEle.setAttribute(KPL_SWATCH_NAME_ATTR, info.swatch.name()); | 1611 | swatchEle.setAttribute(KPL_SWATCH_NAME_ATTR, info.swatch.name()); | ||
Context not available. |