| 93 | } |
| 94 | |
| 95 | void ColorMapsManager::render(QPixmap& pixmap, const QString& name) { |
| 96 | if (name.isEmpty()) |
| 97 | return; |
| 98 | |
| 99 | if (!m_colors.contains(name)) { |
| 100 | for (const auto& name : collectionNames()) |
| 101 | colorMapNames(name); |
| 102 | } |
| 103 | |
| 104 | // convert from the string RGB represetation to QColor |
| 105 | m_colormap.clear(); |
| 106 | for (auto& rgb : m_colors[name]) { |
| 107 | QStringList rgbValues = rgb.split(QLatin1Char(',')); |
| 108 | if (rgbValues.count() == 3) |
| 109 | m_colormap << QColor(rgbValues.at(0).toInt(), rgbValues.at(1).toInt(), rgbValues.at(2).toInt()); |
| 110 | else if (rgbValues.count() == 4) |
| 111 | m_colormap << QColor(rgbValues.at(1).toInt(), rgbValues.at(2).toInt(), rgbValues.at(3).toInt()); |
| 112 | } |
| 113 | |
| 114 | // render the preview pixmap |
| 115 | int height = 80; |
| 116 | int width = 200; |
| 117 | int count = m_colormap.count(); |
| 118 | pixmap = QPixmap(width, height); |
| 119 | QPainter p(&pixmap); |
| 120 | int i = 0; |
| 121 | for (auto& color : m_colormap) { |
| 122 | p.setPen(color); |
| 123 | p.setBrush(color); |
| 124 | p.drawRect(i * width / count, 0, width / count, height); |
| 125 | ++i; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @brief Processes the json metadata file that contains the list of colormap collections. |
no test coverage detected