mirror of https://github.com/CGAL/cgal
WIP move up and down :
- groups are blocked. Need a way to treat differently full selected groups .
This commit is contained in:
parent
836f14533f
commit
00178a0f06
|
|
@ -1074,88 +1074,162 @@ bool Scene::dropMimeData(const QMimeData * /*data*/,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::moveRowUp()
|
|
||||||
{
|
bool Scene::sort_lists(QVector<QList<int> >&sorted_lists, bool up)
|
||||||
QList<int> to_select;
|
{
|
||||||
QList<int> sorted_list = selectionIndices();
|
QVector<int> group_found;
|
||||||
std::sort(sorted_list.begin(), sorted_list.end(),
|
Q_FOREACH(int i, selectionIndices())
|
||||||
|
{
|
||||||
|
Scene_item* item = this->item(i);
|
||||||
|
if(item->has_group == 0)
|
||||||
|
{
|
||||||
|
sorted_lists.first().push_back(i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int group_id = item_id(item->parentGroup());
|
||||||
|
if(group_found.contains(group_id))
|
||||||
|
sorted_lists[group_id].push_back(i);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
group_found.push_back(group_id);
|
||||||
|
if(sorted_lists.size() < group_id+1)
|
||||||
|
sorted_lists.resize(group_id+1);
|
||||||
|
sorted_lists[group_id].push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::sort(sorted_lists.first().begin(), sorted_lists.first().end(),
|
||||||
[this](int a, int b) {
|
[this](int a, int b) {
|
||||||
return children.indexOf(a) < children.indexOf(b);
|
return children.indexOf(a) < children.indexOf(b);
|
||||||
});
|
});
|
||||||
if( children.indexOf(sorted_list.first()) == 0)
|
if(!sorted_lists.first().isEmpty())
|
||||||
return;
|
|
||||||
for(int i=0; i<sorted_list.size(); ++i)
|
|
||||||
{
|
{
|
||||||
Item_id selected_id = sorted_list[i];
|
if(up && children.indexOf(sorted_lists.first().first()) == 0)
|
||||||
|
return false;
|
||||||
|
else if(!up && children.indexOf(sorted_lists.first().last()) == children.size() -1)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for(int i=1; i<sorted_lists.size(); ++i)
|
||||||
|
{
|
||||||
|
QList<int>& list = sorted_lists[i];
|
||||||
|
if(list.isEmpty())
|
||||||
|
continue;
|
||||||
|
Scene_group_item* group = qobject_cast<Scene_group_item*>(this->item(i));
|
||||||
|
if(!group)
|
||||||
|
continue;
|
||||||
|
std::sort(list.begin(), list.end(),
|
||||||
|
[this, group](int a, int b) {
|
||||||
|
return group->getChildren().indexOf(a) < group->getChildren().indexOf(b);
|
||||||
|
});
|
||||||
|
if(up && group->getChildren().indexOf(list.first()) == 0)
|
||||||
|
return false;
|
||||||
|
else if(!up && group->getChildren().indexOf(list.last()) == group->getChildren().size()-1)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void Scene::moveRowUp()
|
||||||
|
{
|
||||||
|
QVector<QList<int> >sorted_lists(1);
|
||||||
|
QList<int> to_select;
|
||||||
|
//sort lists according to the indices of each item in its container (scene or group)
|
||||||
|
//if moving one up would put it out of range, then we stop and do nothing.
|
||||||
|
if(!sort_lists(sorted_lists, true))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(int i=0; i<sorted_lists.first().size(); ++i)
|
||||||
|
{
|
||||||
|
Item_id selected_id = sorted_lists.first()[i];
|
||||||
Scene_item* selected_item = item(selected_id);
|
Scene_item* selected_item = item(selected_id);
|
||||||
if(!selected_item)
|
if(!selected_item)
|
||||||
return;
|
return;
|
||||||
if(index_map.key(selected_id).row() > 0)
|
if(index_map.key(selected_id).row() > 0)
|
||||||
{
|
{
|
||||||
if(item(selected_id)->has_group >0)
|
//if not in group
|
||||||
|
QModelIndex baseId = index_map.key(selected_id);
|
||||||
|
int newId = children.indexOf(
|
||||||
|
index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent()))) ;
|
||||||
|
children.move(children.indexOf(selected_id), newId);
|
||||||
|
redraw_model();
|
||||||
|
to_select.append(m_entries.indexOf(selected_item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int i=1; i<sorted_lists.size(); ++i)
|
||||||
|
{
|
||||||
|
for(int j = 0; j< sorted_lists[i].size(); ++j)
|
||||||
|
{
|
||||||
|
Item_id selected_id = sorted_lists[i][j];
|
||||||
|
Scene_item* selected_item = item(selected_id);
|
||||||
|
if(!selected_item)
|
||||||
|
return;
|
||||||
|
if(index_map.key(selected_id).row() > 0)
|
||||||
{
|
{
|
||||||
Scene_group_item* group = selected_item->parentGroup();
|
Scene_group_item* group = selected_item->parentGroup();
|
||||||
if(group)
|
if(group)
|
||||||
{
|
{
|
||||||
int id = group->getChildren().indexOf(item_id(selected_item));
|
int id = group->getChildren().indexOf(item_id(selected_item));
|
||||||
group->moveUp(id);
|
group->moveUp(id);
|
||||||
|
redraw_model();
|
||||||
|
to_select.append(m_entries.indexOf(selected_item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
//if not in group
|
|
||||||
QModelIndex baseId = index_map.key(selected_id);
|
|
||||||
int newId = children.indexOf(
|
|
||||||
index_map.value(index(baseId.row()-1, baseId.column(),baseId.parent()))) ;
|
|
||||||
children.move(children.indexOf(selected_id), newId);
|
|
||||||
}
|
|
||||||
redraw_model();
|
|
||||||
to_select.append(m_entries.indexOf(selected_item));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectionChanged(to_select);
|
if(!to_select.isEmpty())
|
||||||
|
selectionChanged(to_select);
|
||||||
}
|
}
|
||||||
void Scene::moveRowDown()
|
void Scene::moveRowDown()
|
||||||
{
|
{
|
||||||
|
QVector<QList<int> >sorted_lists(1);
|
||||||
QList<int> to_select;
|
QList<int> to_select;
|
||||||
QList<int> sorted_list = selectionIndices();
|
//sort lists according to the indices of each item in its container (scene or group)
|
||||||
std::sort(sorted_list.begin(), sorted_list.end(),
|
//if moving one up would put it out of range, then we stop and do nothing.
|
||||||
[this](int a, int b) {
|
if(!sort_lists(sorted_lists, false))
|
||||||
return children.indexOf(a) < children.indexOf(b);
|
|
||||||
});
|
|
||||||
if( children.indexOf(sorted_list.last()) == children.size() -1)
|
|
||||||
return;
|
return;
|
||||||
for(int i=sorted_list.size()-1; i>=0; --i)
|
for(int i=sorted_lists.first().size()-1; i>=0; --i)
|
||||||
{
|
{
|
||||||
Item_id selected_id = sorted_list[i];
|
Item_id selected_id = sorted_lists.first()[i];
|
||||||
Scene_item* selected_item = item(selected_id);
|
Scene_item* selected_item = item(selected_id);
|
||||||
if(!selected_item)
|
if(!selected_item)
|
||||||
|
|
||||||
return;
|
return;
|
||||||
if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1)
|
if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1)
|
||||||
{
|
{
|
||||||
if(item(selected_id)->has_group >0)
|
|
||||||
{
|
|
||||||
Scene_group_item* group = selected_item->parentGroup();
|
|
||||||
if(group)
|
|
||||||
{
|
|
||||||
int id = group->getChildren().indexOf(item_id(selected_item));
|
|
||||||
group->moveDown(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//if not in group
|
//if not in group
|
||||||
QModelIndex baseId = index_map.key(selected_id);
|
QModelIndex baseId = index_map.key(selected_id);
|
||||||
int newId = children.indexOf(
|
int newId = children.indexOf(
|
||||||
index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent()))) ;
|
index_map.value(index(baseId.row()+1, baseId.column(),baseId.parent()))) ;
|
||||||
children.move(children.indexOf(selected_id), newId);
|
children.move(children.indexOf(selected_id), newId);
|
||||||
}
|
|
||||||
redraw_model();
|
redraw_model();
|
||||||
to_select.prepend(m_entries.indexOf(selected_item));
|
to_select.prepend(m_entries.indexOf(selected_item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(int i=1; i<sorted_lists.size(); ++i){
|
||||||
|
if(sorted_lists[i].isEmpty())
|
||||||
|
continue;
|
||||||
|
for(int j = sorted_lists[i].size()-1; j >=0; --j)
|
||||||
|
{
|
||||||
|
Item_id selected_id = sorted_lists[i][j];
|
||||||
|
Scene_item* selected_item = item(selected_id);
|
||||||
|
if(!selected_item)
|
||||||
|
return;
|
||||||
|
if(index_map.key(selected_id).row() < rowCount(index_map.key(selected_id).parent())-1)
|
||||||
|
{
|
||||||
|
if(item(selected_id)->has_group >0)
|
||||||
|
{
|
||||||
|
Scene_group_item* group = selected_item->parentGroup();
|
||||||
|
if(group)
|
||||||
|
{
|
||||||
|
int id = group->getChildren().indexOf(item_id(selected_item));
|
||||||
|
group->moveDown(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
redraw_model();
|
||||||
|
to_select.prepend(m_entries.indexOf(selected_item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
selectionChanged(to_select);
|
selectionChanged(to_select);
|
||||||
}
|
}
|
||||||
Scene::Item_id Scene::mainSelectionIndex() const {
|
Scene::Item_id Scene::mainSelectionIndex() const {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QVector>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QItemDelegate>
|
#include <QItemDelegate>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
@ -286,7 +287,7 @@ private:
|
||||||
QOpenGLVertexArrayObject* vao;
|
QOpenGLVertexArrayObject* vao;
|
||||||
mutable QOpenGLBuffer vbo[2];
|
mutable QOpenGLBuffer vbo[2];
|
||||||
bool visibility_recentering_enabled;
|
bool visibility_recentering_enabled;
|
||||||
|
bool sort_lists(QVector<QList<int> >&sorted_lists, bool up);
|
||||||
}; // end class Scene
|
}; // end class Scene
|
||||||
|
|
||||||
class QAbstractProxyModel;
|
class QAbstractProxyModel;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue