Skip to content

Commit

Permalink
bug#451 displayer sorted layer list
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongxu Li committed Feb 11, 2014
1 parent e1db360 commit 5686c61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion librecad/src/lib/engine/rs_layerlist.cpp
Expand Up @@ -107,6 +107,15 @@ void RS_LayerList::activate(RS_Layer* layer, bool notify) {
}


/**
* @brief sort by layer names
*/
void RS_LayerList::sort()
{
std::stable_sort(layers.begin(), layers.end(), [](const RS_Layer* l0, const RS_Layer* l1 )->bool{
return l0->getName() < l1->getName();
});
}

/**
* Adds a layer to the layer list.
Expand All @@ -127,7 +136,7 @@ void RS_LayerList::add(RS_Layer* layer) {
RS_Layer* l = find(layer->getName());
if (l==NULL) {
layers.append(layer);

this->sort();
// notify listeners
for (int i=0; i<layerListListeners.size(); ++i) {
RS_LayerListListener* l = layerListListeners.at(i);
Expand Down
4 changes: 4 additions & 0 deletions librecad/src/lib/engine/rs_layerlist.h
Expand Up @@ -114,6 +114,10 @@ class RS_LayerList {
virtual bool isModified() const {
return modified;
}
/**
* @brief sort by layer names
*/
void sort();

friend std::ostream& operator << (std::ostream& os, RS_LayerList& l);

Expand Down
1 change: 1 addition & 0 deletions librecad/src/ui/qg_layerbox.cpp
Expand Up @@ -64,6 +64,7 @@ void QG_LayerBox::init(RS_LayerList& layerList,
bool showByBlock, bool showUnchanged) {
this->showByBlock = showByBlock;
this->showUnchanged = showUnchanged;
layerList.sort();
this->layerList = &layerList;

if (showUnchanged) {
Expand Down

0 comments on commit 5686c61

Please sign in to comment.