mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-27 17:46:18 +00:00
Changed: #1302 When selecting graphics items in scene will be selected the appropriate primitives in the primitives dialog.
This commit is contained in:
parent
4786379e85
commit
8362d0b123
7 changed files with 53 additions and 2 deletions
|
@ -155,7 +155,7 @@ Path PrimitivesTreeModel::pathFromNode(Node *node)
|
|||
Path path;
|
||||
while(iter != 0)
|
||||
{
|
||||
path.prepend(PathItem(iter->row(), 1));
|
||||
path.prepend(PathItem(iter->row(), 0));
|
||||
iter = iter->parent();
|
||||
}
|
||||
return path;
|
||||
|
|
|
@ -167,6 +167,11 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
|||
QVariant graphicsData;
|
||||
graphicsData.setValue<AbstractWorldItem *>(item);
|
||||
node->setData(Constants::GRAPHICS_DATA_QT4_2D, graphicsData);
|
||||
|
||||
QVariant persistenVariant;
|
||||
QPersistentModelIndex *persistentIndex = new QPersistentModelIndex(primIndex);
|
||||
persistenVariant.setValue<QPersistentModelIndex *>(persistentIndex);
|
||||
item->setData(Constants::NODE_PERISTENT_INDEX, persistenVariant);
|
||||
}
|
||||
|
||||
int count = model->rowCount(primIndex);
|
||||
|
@ -185,6 +190,8 @@ void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
|||
QGraphicsItem *item = getGraphicsItem(node);
|
||||
if (item != 0)
|
||||
scene->removeWorldItem(item);
|
||||
|
||||
delete qvariant_cast<QPersistentModelIndex *>(item->data(Constants::NODE_PERISTENT_INDEX));
|
||||
}
|
||||
|
||||
int count = model->rowCount(primIndex);
|
||||
|
@ -358,6 +365,7 @@ LoadRootPrimitiveCommand::~LoadRootPrimitiveCommand()
|
|||
|
||||
void LoadRootPrimitiveCommand::undo()
|
||||
{
|
||||
// Disable edit points mode
|
||||
m_scene->setEnabledEditPoints(false);
|
||||
|
||||
QModelIndex index = m_model->pathToIndex(m_rootPrimIndex);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QtGui/QUndoCommand>
|
||||
#include <QtGui/QGraphicsScene>
|
||||
#include <QtGui/QGraphicsItem>
|
||||
#include <QPersistentModelIndex>
|
||||
|
||||
namespace LandscapeEditor
|
||||
{
|
||||
|
@ -283,4 +284,7 @@ private:
|
|||
|
||||
} /* namespace WorldEditor */
|
||||
|
||||
// Enable the use of QVariant with this class.
|
||||
Q_DECLARE_METATYPE(QPersistentModelIndex *)
|
||||
|
||||
#endif // WORLD_EDITOR_ACTIONS_H
|
||||
|
|
|
@ -459,6 +459,9 @@ void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
|||
|
||||
m_selectedItems.push_back(item);
|
||||
}
|
||||
|
||||
Q_EMIT updateSelectedItems(m_selectedItems);
|
||||
|
||||
updateSelectedWorldItems(true);
|
||||
m_selectionArea = QRectF();
|
||||
update();
|
||||
|
@ -556,6 +559,8 @@ void WorldEditorScene::updatePickSelection(const QPointF &point)
|
|||
m_selectedItems.push_back(worldItemsItems.at(m_lastPickedPrimitive));
|
||||
updateSelectedWorldItems(true);
|
||||
}
|
||||
|
||||
Q_EMIT updateSelectedItems(m_selectedItems);
|
||||
}
|
||||
|
||||
void WorldEditorScene::updatePickSelectionPoints(const QPointF &point)
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
bool isEnabledEditPoints() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void selectionUpdated(const QList<QGraphicsItem *> &selected, const QList<QGraphicsItem *> &deselected);
|
||||
void updateSelectedItems(const QList<QGraphicsItem *> &selected);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setEnabledEditPoints(bool enabled);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <QtGui/QFileDialog>
|
||||
#include <QtGui/QStatusBar>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QPersistentModelIndex>
|
||||
|
||||
namespace WorldEditor
|
||||
{
|
||||
|
@ -108,6 +109,9 @@ WorldEditorWindow::WorldEditorWindow(QWidget *parent)
|
|||
connect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this, SLOT(updateSelection(QItemSelection, QItemSelection)));
|
||||
|
||||
connect(m_worldEditorScene, SIGNAL(updateSelectedItems(QList<QGraphicsItem *>)),
|
||||
this, SLOT(selectedItemsInScene(QList<QGraphicsItem *>)));
|
||||
|
||||
m_statusBarTimer = new QTimer(this);
|
||||
connect(m_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar()));
|
||||
|
||||
|
@ -295,6 +299,35 @@ void WorldEditorWindow::updateSelection(const QItemSelection &selected, const QI
|
|||
m_worldEditorScene->updateSelection(itemSelected, itemDeselected);
|
||||
}
|
||||
|
||||
void WorldEditorWindow::selectedItemsInScene(const QList<QGraphicsItem *> &selected)
|
||||
{
|
||||
QItemSelectionModel *selectionModel = m_ui.treePrimitivesView->selectionModel();
|
||||
disconnect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this, SLOT(updateSelection(QItemSelection, QItemSelection)));
|
||||
|
||||
selectionModel->clear();
|
||||
QItemSelection itemSelection;
|
||||
Q_FOREACH(QGraphicsItem *item, selected)
|
||||
{
|
||||
QPersistentModelIndex *index = qvariant_cast<QPersistentModelIndex *>(item->data(Constants::NODE_PERISTENT_INDEX));
|
||||
if (index->isValid())
|
||||
{
|
||||
QModelIndex modelIndex = index->operator const QModelIndex &();
|
||||
QItemSelection mergeItemSelection(modelIndex, modelIndex);
|
||||
itemSelection.merge(mergeItemSelection, QItemSelectionModel::Select);
|
||||
}
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
selectionModel->select(itemSelection, QItemSelectionModel::Select);
|
||||
|
||||
// TODO: update property editor
|
||||
// ...
|
||||
|
||||
connect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this, SLOT(updateSelection(QItemSelection, QItemSelection)));
|
||||
}
|
||||
|
||||
void WorldEditorWindow::showEvent(QShowEvent *showEvent)
|
||||
{
|
||||
QMainWindow::showEvent(showEvent);
|
||||
|
|
|
@ -61,6 +61,7 @@ private Q_SLOTS:
|
|||
void updateStatusBar();
|
||||
|
||||
void updateSelection(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
void selectedItemsInScene(const QList<QGraphicsItem *> &selected);
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent *showEvent);
|
||||
|
|
Loading…
Reference in a new issue