|
|
|
@ -14,14 +14,7 @@
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
|
#include "georges_treeview_dialog.h"
|
|
|
|
|
#include "georges.h"
|
|
|
|
|
#include "georgesform_model.h"
|
|
|
|
|
#include "georgesform_proxy_model.h"
|
|
|
|
|
#include "formitem.h"
|
|
|
|
|
#include "formdelegate.h"
|
|
|
|
|
#include "expandable_headerview.h"
|
|
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
@ -43,6 +36,14 @@
|
|
|
|
|
#include "../core/icore.h"
|
|
|
|
|
#include "../core/core_constants.h"
|
|
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
|
#include "georges.h"
|
|
|
|
|
#include "georgesform_model.h"
|
|
|
|
|
#include "georgesform_proxy_model.h"
|
|
|
|
|
#include "formitem.h"
|
|
|
|
|
#include "formdelegate.h"
|
|
|
|
|
#include "expandable_headerview.h"
|
|
|
|
|
|
|
|
|
|
using namespace NLMISC;
|
|
|
|
|
using namespace NLGEORGES;
|
|
|
|
|
|
|
|
|
@ -60,7 +61,7 @@ namespace GeorgesQt
|
|
|
|
|
// Set the default sheet dir dir to the level design path.
|
|
|
|
|
m_lastSheetDir = ".";
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
|
|
|
|
|
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
|
|
|
|
|
m_lastSheetDir = settings->value(Core::Constants::LEVELDESIGN_PATH, "l:/leveldesign").toString();
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
|
@ -71,23 +72,14 @@ namespace GeorgesQt
|
|
|
|
|
m_ui.treeView->header()->setStretchLastSection(true);
|
|
|
|
|
m_ui.treeViewTabWidget->setTabEnabled (2,false);
|
|
|
|
|
|
|
|
|
|
m_ui.checkBoxParent->setStyleSheet("background-color: rgba(0,255,0,30)");
|
|
|
|
|
m_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
|
|
|
|
|
m_form = 0;
|
|
|
|
|
|
|
|
|
|
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&)));
|
|
|
|
|
m_ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
|
|
connect(m_ui.treeView, 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)),
|
|
|
|
|
this, SLOT(filterRows()));
|
|
|
|
|
connect(m_ui.checkBoxDefaults, SIGNAL(toggled(bool)),
|
|
|
|
|
this, SLOT(filterRows()));
|
|
|
|
|
connect(m_header, SIGNAL(headerClicked(int)),
|
|
|
|
|
this, SLOT(headerClicked(int)));
|
|
|
|
|
}
|
|
|
|
@ -101,12 +93,12 @@ namespace GeorgesQt
|
|
|
|
|
void CGeorgesTreeViewDialog::headerClicked(int section)
|
|
|
|
|
{
|
|
|
|
|
if (section == 0)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
if (*(m_header->expanded()))
|
|
|
|
|
m_ui.treeView->expandAll();
|
|
|
|
|
else
|
|
|
|
|
m_ui.treeView->collapseAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CGeorgesTreeViewDialog::setForm(const CForm *form)
|
|
|
|
@ -116,30 +108,30 @@ namespace GeorgesQt
|
|
|
|
|
|
|
|
|
|
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName)
|
|
|
|
|
{
|
|
|
|
|
if(NLMISC::CPath::exists(formName.toUtf8().constData()))
|
|
|
|
|
if(NLMISC::CPath::exists(formName.toStdString()))
|
|
|
|
|
{
|
|
|
|
|
//NLGEORGES::CForm *form = dynamic_cast<NLGEORGES::CForm*>(m_georges->loadForm(formName.toUtf8()));
|
|
|
|
|
return (NLGEORGES::CForm *)m_georges->loadForm(formName.toUtf8().constData());
|
|
|
|
|
//NLGEORGES::CForm *form = dynamic_cast<NLGEORGES::CForm*>(m_georges->loadForm(formName.toStdString()));
|
|
|
|
|
return (NLGEORGES::CForm *)m_georges->loadForm(formName.toStdString());
|
|
|
|
|
}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// CForm *form = 0;
|
|
|
|
|
// // Load the DFN
|
|
|
|
|
// std::string extStr = NLMISC::CFile::getExtension( formName.toUtf8() );
|
|
|
|
|
// std::string extStr = NLMISC::CFile::getExtension( formName.toStdString() );
|
|
|
|
|
// QString dfnName = QString("%1.dfn").arg(extStr.c_str());
|
|
|
|
|
// UFormDfn *formdfn;
|
|
|
|
|
// if (NLMISC::CPath::exists(dfnName.toUtf8()))
|
|
|
|
|
// if (NLMISC::CPath::exists(dfnName.toStdString()))
|
|
|
|
|
// {
|
|
|
|
|
// formdfn = _georges->loadFormDfn (dfnName.toUtf8());
|
|
|
|
|
// formdfn = _georges->loadFormDfn (dfnName.toStdString());
|
|
|
|
|
// if (!formdfn)
|
|
|
|
|
// {
|
|
|
|
|
// nlwarning("Failed to load dfn: %s", dfnName.toUtf8());
|
|
|
|
|
// nlwarning("Failed to load dfn: %s", dfnName.toStdString().c_str());
|
|
|
|
|
// return 0;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// nlwarning("Cannot find dfn: %s", dfnName.toUtf8());
|
|
|
|
|
// nlwarning("Cannot find dfn: %s", dfnName.toStdString().c_str());
|
|
|
|
|
// return 0;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
@ -155,56 +147,56 @@ namespace GeorgesQt
|
|
|
|
|
// }
|
|
|
|
|
// return form;
|
|
|
|
|
//}
|
|
|
|
|
nlinfo("File '%s' does not exist!", formName.toUtf8().constData());
|
|
|
|
|
nlinfo("File '%s' does not exist!", formName.toStdString().c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByDfnName(const QString dfnName)
|
|
|
|
|
{
|
|
|
|
|
if(NLMISC::CPath::exists(dfnName.toUtf8().constData()))
|
|
|
|
|
{
|
|
|
|
|
// Create a new form object.
|
|
|
|
|
NLGEORGES::CForm *form = new NLGEORGES::CForm();
|
|
|
|
|
m_form = form;
|
|
|
|
|
if(NLMISC::CPath::exists(dfnName.toStdString()))
|
|
|
|
|
{
|
|
|
|
|
// Create a new form object.
|
|
|
|
|
NLGEORGES::CForm *form = new NLGEORGES::CForm();
|
|
|
|
|
m_form = form;
|
|
|
|
|
|
|
|
|
|
// Retrieve a copy of the root definition.
|
|
|
|
|
NLGEORGES::CFormDfn *formDfn = dynamic_cast<NLGEORGES::CFormDfn *>(m_georges->loadFormDfn(dfnName.toUtf8().constData()));
|
|
|
|
|
// Retrieve a copy of the root definition.
|
|
|
|
|
NLGEORGES::CFormDfn *formDfn = dynamic_cast<NLGEORGES::CFormDfn *>(m_georges->loadFormDfn(dfnName.toStdString()));
|
|
|
|
|
|
|
|
|
|
// Next we'll use the root node to build a new form.
|
|
|
|
|
NLGEORGES::CFormElmStruct *fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(0));
|
|
|
|
|
fes->build(formDfn);
|
|
|
|
|
// Next we'll use the root node to build a new form.
|
|
|
|
|
NLGEORGES::CFormElmStruct *fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(0));
|
|
|
|
|
fes->build(formDfn);
|
|
|
|
|
|
|
|
|
|
// And then initialize the held elements;
|
|
|
|
|
for(uint i = 0; i<NLGEORGES::CForm::HeldElementCount; i++)
|
|
|
|
|
{
|
|
|
|
|
fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(i+1));
|
|
|
|
|
fes->build(formDfn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return form;
|
|
|
|
|
}
|
|
|
|
|
nlinfo("File '%s' does not exist!", dfnName.toUtf8().constData());
|
|
|
|
|
return NULL;
|
|
|
|
|
// And then initialize the held elements;
|
|
|
|
|
for(uint i = 0; i<NLGEORGES::CForm::HeldElementCount; i++)
|
|
|
|
|
{
|
|
|
|
|
fes = dynamic_cast<NLGEORGES::CFormElmStruct *>(getRootNode(i+1));
|
|
|
|
|
fes->build(formDfn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return form;
|
|
|
|
|
}
|
|
|
|
|
nlinfo("File '%s' does not exist!", dfnName.toStdString().c_str());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLGEORGES::CFormElm *CGeorgesTreeViewDialog::getRootNode(uint slot)
|
|
|
|
|
{
|
|
|
|
|
NLGEORGES::CForm *form = getFormPtr();
|
|
|
|
|
NLGEORGES::CForm *form = getFormPtr();
|
|
|
|
|
|
|
|
|
|
if(slot == 0)
|
|
|
|
|
{
|
|
|
|
|
const NLGEORGES::UFormElm &formElm = form->getRootNode();
|
|
|
|
|
return (NLGEORGES::CFormElm *)&formElm;
|
|
|
|
|
}
|
|
|
|
|
if(slot == 0)
|
|
|
|
|
{
|
|
|
|
|
const NLGEORGES::UFormElm &formElm = form->getRootNode();
|
|
|
|
|
return (NLGEORGES::CFormElm *)&formElm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure the slot value is valid and then return the corresponding element.
|
|
|
|
|
nlassert(slot < NLGEORGES::CForm::HeldElementCount+1);
|
|
|
|
|
return getFormPtr()->HeldElements[slot-1];
|
|
|
|
|
// Make sure the slot value is valid and then return the corresponding element.
|
|
|
|
|
nlassert(slot < NLGEORGES::CForm::HeldElementCount+1);
|
|
|
|
|
return getFormPtr()->HeldElements[slot-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NLGEORGES::CForm *CGeorgesTreeViewDialog::getFormPtr()
|
|
|
|
|
{
|
|
|
|
|
return dynamic_cast<NLGEORGES::CForm *>(m_form);
|
|
|
|
|
return dynamic_cast<NLGEORGES::CForm *>(m_form);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CGeorgesTreeViewDialog::loadFormIntoDialog(CForm *form)
|
|
|
|
@ -218,14 +210,16 @@ namespace GeorgesQt
|
|
|
|
|
UFormElm *root = 0;
|
|
|
|
|
root = &m_form->getRootNode();
|
|
|
|
|
|
|
|
|
|
// Extract the parent forms into the list of parents in the dialog.
|
|
|
|
|
QStringList parents;
|
|
|
|
|
uint cnt = form->getParentCount();
|
|
|
|
|
for (uint i = 0; i < cnt /*form->getParentCount()*/; i++)
|
|
|
|
|
uint cnt = form->getParentCount();
|
|
|
|
|
for (uint i = 0; i < cnt /*form->getParentCount()*/; i++)
|
|
|
|
|
{
|
|
|
|
|
UForm *u = m_form->getParentForm(i);
|
|
|
|
|
parents << u->getFilename().c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exact the comment box for the dialog.
|
|
|
|
|
QString comments;
|
|
|
|
|
comments = m_form->getComment().c_str();
|
|
|
|
|
|
|
|
|
@ -249,22 +243,15 @@ namespace GeorgesQt
|
|
|
|
|
nlinfo("typ's %d",deps["typ"].count());
|
|
|
|
|
nlinfo("dfn's %d",deps["dfn"].count());
|
|
|
|
|
|
|
|
|
|
//nlwarning(strList.join(";").toUtf8());
|
|
|
|
|
//nlwarning(strList.join(";").toStdString().c_str());
|
|
|
|
|
if (root)
|
|
|
|
|
{
|
|
|
|
|
loadedForm = m_form->getFilename().c_str();
|
|
|
|
|
|
|
|
|
|
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents,m_header->expanded());
|
|
|
|
|
CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel();
|
|
|
|
|
proxyModel->setSourceModel(model);
|
|
|
|
|
m_ui.treeView->setModel(proxyModel);
|
|
|
|
|
CGeorgesFormModel *model = new CGeorgesFormModel(m_form,deps,comments,parents,m_header->expanded());
|
|
|
|
|
m_ui.treeView->setModel(model);
|
|
|
|
|
m_ui.treeView->expandAll();
|
|
|
|
|
// this is a debug output row
|
|
|
|
|
m_ui.treeView->hideColumn(3);
|
|
|
|
|
|
|
|
|
|
filterRows();
|
|
|
|
|
|
|
|
|
|
// //_ui.treeView->setRowHidden(0,QModelIndex(),true);
|
|
|
|
|
connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
|
|
|
|
|
this, SLOT(modifiedFile()));
|
|
|
|
|
|
|
|
|
@ -276,12 +263,11 @@ namespace GeorgesQt
|
|
|
|
|
void CGeorgesTreeViewDialog::addParentForm(QString parentFormNm)
|
|
|
|
|
{
|
|
|
|
|
// Try to load the form
|
|
|
|
|
NLGEORGES::UForm *uParentForm = m_georges->loadForm(parentFormNm.toUtf8().constData());
|
|
|
|
|
NLGEORGES::UForm *uParentForm = m_georges->loadForm(parentFormNm.toStdString());
|
|
|
|
|
NLGEORGES::CForm *parentForm = dynamic_cast<NLGEORGES::CForm*>(uParentForm);
|
|
|
|
|
NLGEORGES::CForm *mainForm = static_cast<NLGEORGES::CForm*>(m_form);
|
|
|
|
|
|
|
|
|
|
CGeorgesFormProxyModel * proxyModel = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
|
|
|
|
CGeorgesFormModel *model = dynamic_cast<CGeorgesFormModel *>(proxyModel->sourceModel());
|
|
|
|
|
CGeorgesFormModel *model = dynamic_cast<CGeorgesFormModel *>(m_ui.treeView->model());
|
|
|
|
|
|
|
|
|
|
if(parentForm)
|
|
|
|
|
{
|
|
|
|
@ -291,11 +277,11 @@ namespace GeorgesQt
|
|
|
|
|
if (parentForm->Elements.FormDfn == mainForm->Elements.FormDfn)
|
|
|
|
|
{
|
|
|
|
|
// This is the parent form selector
|
|
|
|
|
if(!mainForm->insertParent(mainForm->getParentCount(),parentFormNm.toUtf8(), parentForm))
|
|
|
|
|
nlwarning("Failed to add parent form: %s", parentFormNm.toUtf8().constData());
|
|
|
|
|
if(!mainForm->insertParent(mainForm->getParentCount(),parentFormNm.toStdString().c_str(), parentForm))
|
|
|
|
|
nlwarning("Failed to add parent form: %s", parentFormNm.toStdString().c_str());
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nlinfo("Successfullyadded parent form: %s", parentFormNm.toUtf8().constData());
|
|
|
|
|
nlinfo("Successfullyadded parent form: %s", parentFormNm.toStdString().c_str());
|
|
|
|
|
model->addParentForm(parentFormNm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -316,12 +302,12 @@ namespace GeorgesQt
|
|
|
|
|
void CGeorgesTreeViewDialog::write( )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
NLMISC::COFile file;
|
|
|
|
|
std::string s = NLMISC::CPath::lookup(loadedForm.toUtf8().constData(), false);
|
|
|
|
|
if(file.open (s))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
NLMISC::COFile file;
|
|
|
|
|
std::string s = NLMISC::CPath::lookup(loadedForm.toStdString(), false);
|
|
|
|
|
if(file.open (s))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// if (loadedForm.contains(".typ"))
|
|
|
|
|
// {
|
|
|
|
|
// //nlassert (Type != NULL);
|
|
|
|
@ -334,7 +320,7 @@ namespace GeorgesQt
|
|
|
|
|
// // flushValueChange ();
|
|
|
|
|
// //}
|
|
|
|
|
// //Type->write (xmlStream.getDocument (), theApp.Georges4CVS);
|
|
|
|
|
// //modify (NULL, NULL, false);
|
|
|
|
|
// //modify (NULL, NULL, false);
|
|
|
|
|
// //flushValueChange ();
|
|
|
|
|
// //UpdateAllViews (NULL);
|
|
|
|
|
// //return TRUE;
|
|
|
|
@ -356,9 +342,9 @@ namespace GeorgesQt
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
nlassert (m_form != NULL);
|
|
|
|
|
nlassert (m_form != NULL);
|
|
|
|
|
|
|
|
|
|
// Write the file
|
|
|
|
|
// Write the file
|
|
|
|
|
// /*if (IsModified ())
|
|
|
|
|
// {
|
|
|
|
|
// ((CForm*)(UForm*)Form)->Header.MinorVersion++;
|
|
|
|
@ -380,33 +366,29 @@ namespace GeorgesQt
|
|
|
|
|
// // Get the left view
|
|
|
|
|
// //CView* pView = getLeftView ();
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
catch (Exception &e)
|
|
|
|
|
{
|
|
|
|
|
nlerror("Error while loading file: %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nlerror("Can't open the file %s for writing.", s.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception &e)
|
|
|
|
|
{
|
|
|
|
|
nlerror("Error while loading file: %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nlerror("Can't open the file %s for writing.", s.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
|
|
|
|
|
{
|
|
|
|
|
// TODO: this is messy :( perhaps this can be done better
|
|
|
|
|
CGeorgesFormProxyModel * proxyModel =
|
|
|
|
|
dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
|
|
|
|
CGeorgesFormModel *model =
|
|
|
|
|
dynamic_cast<CGeorgesFormModel *>(proxyModel->sourceModel());
|
|
|
|
|
QModelIndex sourceIndex = proxyModel->mapToSource(index);
|
|
|
|
|
//CGeorgesFormModel *model =
|
|
|
|
|
// dynamic_cast<CGeorgesFormModel *>((m_ui.treeView->model());
|
|
|
|
|
|
|
|
|
|
CFormItem *item = model->getItem(sourceIndex);
|
|
|
|
|
//CFormItem *item = model->getItem(index);
|
|
|
|
|
|
|
|
|
|
if (item->parent() && item->parent()->data(0) == "parents")
|
|
|
|
|
{
|
|
|
|
|
Q_EMIT changeFile(CPath::lookup(item->data(0).toString().toUtf8().constData(),false).c_str());
|
|
|
|
|
}
|
|
|
|
|
//if (item->parent() && item->parent()->data(0) == "parents")
|
|
|
|
|
//{
|
|
|
|
|
// Q_EMIT changeFile(CPath::lookup(item->data(0).toString().toStdString(),false).c_str());
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//// col containing additional stuff like icons
|
|
|
|
|
//if (index.column() == 2)
|
|
|
|
@ -415,7 +397,7 @@ namespace GeorgesQt
|
|
|
|
|
// CFormItem *item = m->getItem(in2);
|
|
|
|
|
// QString value = item->data(1).toString();
|
|
|
|
|
|
|
|
|
|
// QString path = CPath::lookup(value.toUtf8(),false).c_str();
|
|
|
|
|
// QString path = CPath::lookup(value.toStdString(),false).c_str();
|
|
|
|
|
|
|
|
|
|
// if(value.contains(".tga") || value.contains(".png"))
|
|
|
|
|
// {
|
|
|
|
@ -443,7 +425,7 @@ namespace GeorgesQt
|
|
|
|
|
// {
|
|
|
|
|
// Modules::objViewInt()->resetScene();
|
|
|
|
|
// //Modules::config().configRemapExtensions();
|
|
|
|
|
// Modules::objViewInt()->loadMesh(path.toUtf8(),"");
|
|
|
|
|
// Modules::objViewInt()->loadMesh(path.toStdString(),"");
|
|
|
|
|
// }
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
@ -472,12 +454,12 @@ namespace GeorgesQt
|
|
|
|
|
|
|
|
|
|
void CGeorgesTreeViewDialog::filterRows()
|
|
|
|
|
{
|
|
|
|
|
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
|
|
|
|
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
|
|
|
|
|
if (m) {
|
|
|
|
|
m->setShowParents(m_ui.checkBoxParent->isChecked());
|
|
|
|
|
m->setShowDefaults(m_ui.checkBoxDefaults->isChecked());
|
|
|
|
|
}
|
|
|
|
|
//CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
|
|
|
|
//CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
|
|
|
|
|
//if (m) {
|
|
|
|
|
// m->setShowParents(m_ui.checkBoxParent->isChecked());
|
|
|
|
|
// m->setShowDefaults(m_ui.checkBoxDefaults->isChecked());
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CGeorgesTreeViewDialog::showContextMenu(const QPoint &pos)
|
|
|
|
@ -492,109 +474,128 @@ namespace GeorgesQt
|
|
|
|
|
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);
|
|
|
|
|
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(m_ui.treeView->model());
|
|
|
|
|
|
|
|
|
|
if (m)
|
|
|
|
|
if(m)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CFormItem *item = m->getItem(sourceIndex);
|
|
|
|
|
CFormItem *item = m->getItem(index);
|
|
|
|
|
|
|
|
|
|
// Right click on the "parents" item
|
|
|
|
|
if (item->data(0) == "parents")
|
|
|
|
|
contextMenu.addAction("Add parent...");
|
|
|
|
|
// Right click on a parent item
|
|
|
|
|
else if(item->parent() && item->parent()->data(0) == "parents")
|
|
|
|
|
// if (item->data(0) == "parents")
|
|
|
|
|
// contextMenu.addAction("Add parent...");
|
|
|
|
|
// // Right click on a parent item
|
|
|
|
|
// else if(item->parent() && item->parent()->data(0) == "parents")
|
|
|
|
|
// {
|
|
|
|
|
// contextMenu.addAction("Add parent...");
|
|
|
|
|
// contextMenu.addAction("Remove parent");
|
|
|
|
|
// }
|
|
|
|
|
if(item->isArray())
|
|
|
|
|
{
|
|
|
|
|
contextMenu.addAction("Add parent...");
|
|
|
|
|
contextMenu.addAction("Remove parent");
|
|
|
|
|
contextMenu.addAction("Append array entry...");
|
|
|
|
|
}
|
|
|
|
|
else if(item->getFormElm()->isArray())
|
|
|
|
|
contextMenu.addAction("Add array entry...");
|
|
|
|
|
else if(item->getFormElm()->isStruct())
|
|
|
|
|
else if(item->isArrayMember())
|
|
|
|
|
{
|
|
|
|
|
QMenu *structContext = new QMenu("Add struct element...", this);
|
|
|
|
|
contextMenu.addMenu(structContext);
|
|
|
|
|
|
|
|
|
|
NLGEORGES::UFormDfn *defn = item->getFormElm()->getStructDfn();
|
|
|
|
|
if(defn)
|
|
|
|
|
{
|
|
|
|
|
for(uint defnNum=0; defnNum < defn->getNumEntry(); defnNum++)
|
|
|
|
|
{
|
|
|
|
|
std::string entryName;
|
|
|
|
|
std::string dummy;
|
|
|
|
|
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
|
|
|
|
|
bool result = defn->getEntryName(defnNum, entryName);
|
|
|
|
|
bool result2 = item->getFormElm()->getValueByName(dummy, entryName.c_str(), NLGEORGES::UFormElm::Eval, whereV);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(result2 && *whereV != UFormElm::ValueForm)
|
|
|
|
|
{
|
|
|
|
|
structContext->addAction(entryName.c_str());
|
|
|
|
|
}
|
|
|
|
|
delete whereV;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
contextMenu.addAction("Delete array entry...");
|
|
|
|
|
contextMenu.addAction("Insert after array entry...");
|
|
|
|
|
}
|
|
|
|
|
else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm)
|
|
|
|
|
contextMenu.addAction("Revert to parent/default...");
|
|
|
|
|
// else if(item->getFormElm()->isStruct())
|
|
|
|
|
// {
|
|
|
|
|
// QMenu *structContext = new QMenu("Add struct element...", this);
|
|
|
|
|
// contextMenu.addMenu(structContext);
|
|
|
|
|
|
|
|
|
|
QAction *selectedItem = contextMenu.exec(globalPos);
|
|
|
|
|
if(selectedItem)
|
|
|
|
|
{
|
|
|
|
|
if(selectedItem->text() == "Add parent...")
|
|
|
|
|
{
|
|
|
|
|
// Get the file extension of the form so we can build a dialog pattern.
|
|
|
|
|
QString file = m_form->getFilename().c_str();
|
|
|
|
|
file = file.remove(0,file.indexOf(".")+1);
|
|
|
|
|
QString filePattern = "Parent Sheets (*."+file+")";
|
|
|
|
|
|
|
|
|
|
nlinfo("parent defn name '%s'", file.toUtf8().constData());
|
|
|
|
|
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select parent sheets..."), m_lastSheetDir, filePattern);
|
|
|
|
|
if(!fileNames.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
Q_FOREACH(QString fileToParent, fileNames)
|
|
|
|
|
{
|
|
|
|
|
// Get just the filename. Georges doesn't want the path.
|
|
|
|
|
QFileInfo pathInfo( fileToParent );
|
|
|
|
|
QString tmpFileName( pathInfo.fileName() );
|
|
|
|
|
// NLGEORGES::UFormDfn *defn = item->getFormElm()->getStructDfn();
|
|
|
|
|
// if(defn)
|
|
|
|
|
// {
|
|
|
|
|
// for(uint defnNum=0; defnNum < defn->getNumEntry(); defnNum++)
|
|
|
|
|
// {
|
|
|
|
|
// std::string entryName;
|
|
|
|
|
// std::string dummy;
|
|
|
|
|
// UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
|
|
|
|
|
// bool result = defn->getEntryName(defnNum, entryName);
|
|
|
|
|
// bool result2 = item->getFormElm()->getValueByName(dummy, entryName.c_str(), NLGEORGES::UFormElm::Eval, whereV);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// if(result2 && *whereV != UFormElm::ValueForm)
|
|
|
|
|
// {
|
|
|
|
|
// structContext->addAction(entryName.c_str());
|
|
|
|
|
// }
|
|
|
|
|
// delete whereV;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm)
|
|
|
|
|
// contextMenu.addAction("Revert to parent/default...");
|
|
|
|
|
|
|
|
|
|
QAction *selectedItem = contextMenu.exec(QCursor::pos());
|
|
|
|
|
if(selectedItem)
|
|
|
|
|
{
|
|
|
|
|
if(selectedItem->text() == "Append array entry...")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
nlinfo("requesting to add parent form '%s'", tmpFileName.toUtf8().constData());
|
|
|
|
|
|
|
|
|
|
// Call to add the form and load it into the Georges form.
|
|
|
|
|
addParentForm(tmpFileName);
|
|
|
|
|
} // Append an array entry...
|
|
|
|
|
else if(selectedItem->text() == "Delete array entry...")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Save the file lookup path for future dialog boxes.
|
|
|
|
|
m_lastSheetDir = pathInfo.absolutePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_ui.treeView->expandAll();
|
|
|
|
|
}
|
|
|
|
|
else if(selectedItem->text() == "Remove parent")
|
|
|
|
|
{
|
|
|
|
|
NLGEORGES::CForm *form = static_cast<NLGEORGES::CForm *>(m_form);
|
|
|
|
|
QString parentFileName = item->data(0).toString();
|
|
|
|
|
}
|
|
|
|
|
else if(selectedItem->text() == "Insert after array entry...")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for(uint num = 0; num < form->getParentCount(); num++)
|
|
|
|
|
{
|
|
|
|
|
QString curParentName = form->getParent(num)->getFilename().c_str();
|
|
|
|
|
if(parentFileName == curParentName)
|
|
|
|
|
{
|
|
|
|
|
form->removeParent(num);
|
|
|
|
|
m->removeParentForm(parentFileName);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_ui.treeView->expandAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // if selected context menu item is valid.
|
|
|
|
|
// if(selectedItem->text() == "Add parent...")
|
|
|
|
|
// {
|
|
|
|
|
// // Get the file extension of the form so we can build a dialog pattern.
|
|
|
|
|
// QString file = m_form->getFilename().c_str();
|
|
|
|
|
// file = file.remove(0,file.indexOf(".")+1);
|
|
|
|
|
// QString filePattern = "Parent Sheets (*."+file+")";
|
|
|
|
|
//
|
|
|
|
|
// nlinfo("parent defn name '%s'", file.toStdString().c_str());
|
|
|
|
|
// QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select parent sheets..."), m_lastSheetDir, filePattern);
|
|
|
|
|
// if(!fileNames.isEmpty())
|
|
|
|
|
// {
|
|
|
|
|
// Q_FOREACH(QString fileToParent, fileNames)
|
|
|
|
|
// {
|
|
|
|
|
// // Get just the filename. Georges doesn't want the path.
|
|
|
|
|
// QFileInfo pathInfo( fileToParent );
|
|
|
|
|
// QString tmpFileName( pathInfo.fileName() );
|
|
|
|
|
|
|
|
|
|
// nlinfo("requesting to add parent form '%s'", tmpFileName.toStdString().c_str());
|
|
|
|
|
//
|
|
|
|
|
// // Call to add the form and load it into the Georges form.
|
|
|
|
|
// addParentForm(tmpFileName);
|
|
|
|
|
|
|
|
|
|
// // Save the file lookup path for future dialog boxes.
|
|
|
|
|
// m_lastSheetDir = pathInfo.absolutePath();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// m_ui.treeView->expandAll();
|
|
|
|
|
// }
|
|
|
|
|
// else if(selectedItem->text() == "Remove parent")
|
|
|
|
|
// {
|
|
|
|
|
// NLGEORGES::CForm *form = static_cast<NLGEORGES::CForm *>(m_form);
|
|
|
|
|
// QString parentFileName = item->data(0).toString();
|
|
|
|
|
|
|
|
|
|
// for(uint num = 0; num < form->getParentCount(); num++)
|
|
|
|
|
// {
|
|
|
|
|
// QString curParentName = form->getParent(num)->getFilename().c_str();
|
|
|
|
|
// if(parentFileName == curParentName)
|
|
|
|
|
// {
|
|
|
|
|
// form->removeParent(num);
|
|
|
|
|
// m->removeParentForm(parentFileName);
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// m_ui.treeView->expandAll();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
} // if selected context menu item is valid.
|
|
|
|
|
} // if 'm' model valid.
|
|
|
|
|
|
|
|
|
|
if(structContext)
|
|
|
|
|
delete structContext;
|
|
|
|
|
//if(structContext)
|
|
|
|
|
// delete structContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} /* namespace GeorgesQt */
|
|
|
|
|