Changed: #1306 Added undo stack deeper (for later) and began adding form context menus proof-of-concept.
This commit is contained in:
parent
70ec74a97f
commit
cd6dfef39d
3 changed files with 65 additions and 0 deletions
|
@ -176,6 +176,7 @@ namespace Plugin
|
|||
if (!m_dockedWidgets.size())
|
||||
{
|
||||
CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock);
|
||||
dock->setUndoStack(m_undoStack);
|
||||
m_lastActiveDock = dock;
|
||||
m_dockedWidgets.append(dock);
|
||||
|
||||
|
@ -197,6 +198,7 @@ namespace Plugin
|
|||
}
|
||||
}
|
||||
CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock);
|
||||
dock->setUndoStack(m_undoStack);
|
||||
m_dockedWidgets.append(dock);
|
||||
|
||||
connect(m_dockedWidgets.last(), SIGNAL(closing()),
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QSettings>
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/path.h>
|
||||
|
@ -65,6 +66,10 @@ namespace Plugin
|
|||
FormDelegate *formdelegate = new FormDelegate(this);
|
||||
m_ui.treeView->setItemDelegateForColumn(1, formdelegate);
|
||||
|
||||
// Set up custom context menu.
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));
|
||||
|
||||
connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
|
||||
this, SLOT(doubleClicked (QModelIndex)));
|
||||
connect(m_ui.checkBoxParent, SIGNAL(toggled(bool)),
|
||||
|
@ -385,4 +390,52 @@ namespace Plugin
|
|||
}
|
||||
}
|
||||
|
||||
void CGeorgesTreeViewDialog::showContextMenu(const QPoint &pos)
|
||||
{
|
||||
QMenu contextMenu;
|
||||
QPoint globalPos = this->mapToGlobal(pos);
|
||||
|
||||
// Fisrt we're going to see if we've right clicked on a new item and select it.
|
||||
QModelIndex &index = this->m_ui.treeView->currentIndex();
|
||||
|
||||
if(!index.isValid())
|
||||
return;
|
||||
|
||||
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
||||
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
|
||||
QModelIndex sourceIndex = mp->mapToSource(index);
|
||||
|
||||
if (m)
|
||||
{
|
||||
|
||||
CFormItem *item = m->getItem(sourceIndex);
|
||||
|
||||
if ((item->parent() && item->parent()->data(0) == "parents") || item->data(0) == "parents")
|
||||
contextMenu.addAction("Add parent...");
|
||||
else if(item->getFormElm()->isArray())
|
||||
contextMenu.addAction("Add array entry...");
|
||||
else if(item->getFormElm()->isStruct())
|
||||
contextMenu.addAction("Add element...");
|
||||
else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm)
|
||||
contextMenu.addAction("Revert to parent/default...");
|
||||
else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueParentForm)
|
||||
contextMenu.addAction("Override parent/default value...");
|
||||
else
|
||||
contextMenu.addAction("Add element...");
|
||||
|
||||
QAction *selectedItem = contextMenu.exec(globalPos);
|
||||
if(selectedItem)
|
||||
{
|
||||
if(selectedItem->text() == "Add parent...")
|
||||
{
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select parent sheets..."));
|
||||
if(!fileNames.isEmpty())
|
||||
{
|
||||
// add some parents.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace NLQT */
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
|
||||
// Qt includes
|
||||
#include <QtGui/QDockWidget>
|
||||
#include <QtGui/QUndoCommand>
|
||||
#include <QtGui/QUndoStack>
|
||||
|
||||
|
||||
// STL includes
|
||||
|
||||
|
@ -60,6 +63,10 @@ namespace Plugin
|
|||
|
||||
QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }
|
||||
|
||||
void setUndoStack(QUndoStack *stack) {
|
||||
m_undoStack = stack;
|
||||
}
|
||||
|
||||
QString loadedForm;
|
||||
|
||||
protected:
|
||||
|
@ -75,6 +82,7 @@ namespace Plugin
|
|||
void loadFormIntoDialog(CForm *form = 0);
|
||||
void modifiedFile( );
|
||||
void checkVisibility(bool);
|
||||
void showContextMenu(const QPoint &pos);
|
||||
|
||||
private Q_SLOTS:
|
||||
void doubleClicked ( const QModelIndex & index );
|
||||
|
@ -87,6 +95,8 @@ namespace Plugin
|
|||
UForm *m_form;
|
||||
CGeorges *m_georges;
|
||||
|
||||
QUndoStack *m_undoStack;
|
||||
|
||||
bool m_modified;
|
||||
|
||||
}; /* CGeorgesTreeViewDialog */
|
||||
|
|
Loading…
Reference in a new issue