1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include "ColourScheme.h"
#include "itextstream.h"
namespace colours
{
ColourScheme::ColourScheme()
{}
/* ColourScheme Constructor
* Builds the colourscheme structure and passes the found <colour> tags to the ColourItem constructor
* All the found <colour> items are stored in a vector of ColourItems
*/
ColourScheme::ColourScheme(const xml::Node& schemeNode)
{
_readOnly = (schemeNode.getAttributeValue("readonly") == "1");
// Select all <colour> nodes from the tree
xml::NodeList colourNodes = schemeNode.getNamedChildren("colour");
if (colourNodes.empty())
{
rMessage() << "ColourScheme: No scheme items found." << std::endl;
return;
}
// Assign the name of this scheme
_name = schemeNode.getAttributeValue("name");
// Cycle through all found colour tags and add them to this scheme
for (const xml::Node& colourNode : colourNodes)
{
std::string colourName = colourNode.getAttributeValue("name");
_colours[colourName] = ColourItem(colourNode);
}
}
void ColourScheme::foreachColour(
const std::function<void(const std::string& name, IColourItem& colour)>& functor)
{
for (auto& pair : _colours)
{
functor(pair.first, pair.second);
}
}
void ColourScheme::foreachColour(
const std::function<void(const std::string& name, const IColourItem& colour)>& functor) const
{
for (auto& pair : _colours)
{
functor(pair.first, pair.second);
}
}
ColourItem& ColourScheme::getColour(const std::string& colourName)
{
auto it = _colours.find(colourName);
if (it != _colours.end())
{
return it->second;
}
rMessage() << "ColourScheme: Colour " << colourName << " doesn't exist!" << std::endl;
return _emptyColour;
}
const std::string& ColourScheme::getName() const
{
return _name;
}
bool ColourScheme::isReadOnly() const
{
return _readOnly;
}
void ColourScheme::setReadOnly(bool isReadOnly)
{
_readOnly = isReadOnly;
}
void ColourScheme::mergeMissingItemsFromScheme(const IColourScheme& other)
{
other.foreachColour([&](const std::string& name, const colours::IColourItem& colour)
{
// Insert any missing ColourItems from the other mapping into this scheme
if (_colours.find(name) == _colours.end())
{
_colours.emplace(name, ColourItem(colour));
}
});
}
} // namespace
|