mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-22 17:08:43 +00:00
Array resize.
This commit is contained in:
parent
90e3d24c00
commit
c8199efbf8
10 changed files with 157 additions and 1 deletions
|
@ -14,6 +14,8 @@ QObject( browser )
|
||||||
{
|
{
|
||||||
m_pvt = new BrowserCtrlPvt();
|
m_pvt = new BrowserCtrlPvt();
|
||||||
m_pvt->setBrowser( browser );
|
m_pvt->setBrowser( browser );
|
||||||
|
|
||||||
|
connect( m_pvt, SIGNAL( arrayResized( const QString&, int ) ), this, SLOT( onArrayResized( const QString&, int ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserCtrl::~BrowserCtrl()
|
BrowserCtrl::~BrowserCtrl()
|
||||||
|
@ -50,6 +52,11 @@ void BrowserCtrl::onValueChanged( QtProperty *p, const QVariant &value )
|
||||||
m_pvt->onValueChanged( p, value );
|
m_pvt->onValueChanged( p, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrowserCtrl::onArrayResized( const QString &name, int size )
|
||||||
|
{
|
||||||
|
Q_EMIT arrayResized( name, size );
|
||||||
|
}
|
||||||
|
|
||||||
void BrowserCtrl::enableMgrConnections()
|
void BrowserCtrl::enableMgrConnections()
|
||||||
{
|
{
|
||||||
QtVariantPropertyManager *mgr = m_pvt->manager();
|
QtVariantPropertyManager *mgr = m_pvt->manager();
|
||||||
|
|
|
@ -26,8 +26,12 @@ public:
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void clicked( const QModelIndex &idx );
|
void clicked( const QModelIndex &idx );
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void arrayResized( const QString &name, int size );
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onValueChanged( QtProperty *p, const QVariant &value );
|
void onValueChanged( QtProperty *p, const QVariant &value );
|
||||||
|
void onArrayResized( const QString &name, int size );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void enableMgrConnections();
|
void enableMgrConnections();
|
||||||
|
|
|
@ -139,6 +139,52 @@ void BrowserCtrlPvt::onArrayValueChanged( QtProperty *p, const QVariant &value )
|
||||||
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode );
|
NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( m_currentNode );
|
||||||
std::string formName;
|
std::string formName;
|
||||||
arr->getFormName( formName, NULL );
|
arr->getFormName( formName, NULL );
|
||||||
|
|
||||||
|
int newSize = value.toInt();
|
||||||
|
int oldSize = arr->Elements.size();
|
||||||
|
|
||||||
|
if( newSize == oldSize )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if( newSize < oldSize )
|
||||||
|
{
|
||||||
|
for( int i = newSize; i < oldSize; i++ )
|
||||||
|
{
|
||||||
|
delete arr->Elements[ i ].Element;
|
||||||
|
}
|
||||||
|
|
||||||
|
arr->Elements.resize( newSize );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arr->Elements.resize( newSize );
|
||||||
|
|
||||||
|
|
||||||
|
const NLGEORGES::CFormDfn *parentDfn;
|
||||||
|
const NLGEORGES::CFormDfn *nodeDfn;
|
||||||
|
uint indexDfn;
|
||||||
|
const NLGEORGES::CType *type;
|
||||||
|
NLGEORGES::UFormDfn::TEntryType entryType;
|
||||||
|
NLGEORGES::CFormElm *node;
|
||||||
|
bool created;
|
||||||
|
bool isArray;
|
||||||
|
|
||||||
|
QString idx;
|
||||||
|
|
||||||
|
for( int i = oldSize; i < newSize; i++ )
|
||||||
|
{
|
||||||
|
idx.clear();
|
||||||
|
idx += "[";
|
||||||
|
idx += QString::number( i );
|
||||||
|
idx += "]";
|
||||||
|
|
||||||
|
bool b;
|
||||||
|
b = arr->createNodeByName( idx.toUtf8().constData(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString name = formName.c_str();
|
||||||
|
Q_EMIT arrayResized( name, newSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
|
void BrowserCtrlPvt::onValueChanged( QtProperty *p, const QVariant &value )
|
||||||
|
|
|
@ -31,6 +31,9 @@ public:
|
||||||
void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; }
|
void setRootNode( NLGEORGES::CFormElm *root ){ m_rootNode = root; }
|
||||||
void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; }
|
void setBrowser( QtTreePropertyBrowser *browser ){ m_browser = browser; }
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void arrayResized( const QString &name, int size );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupStruct( NLGEORGES::UFormElm *node );
|
void setupStruct( NLGEORGES::UFormElm *node );
|
||||||
void setupArray( NLGEORGES::UFormElm *node );
|
void setupArray( NLGEORGES::UFormElm *node );
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace GeorgesQt
|
||||||
|
|
||||||
CFormItem::~CFormItem()
|
CFormItem::~CFormItem()
|
||||||
{
|
{
|
||||||
qDeleteAll(childItems);
|
clearChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFormItem::appendChild(CFormItem *item)
|
void CFormItem::appendChild(CFormItem *item)
|
||||||
|
@ -214,6 +214,29 @@ namespace GeorgesQt
|
||||||
return QIcon();
|
return QIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CFormItem* CFormItem::findItem( const QString &formName )
|
||||||
|
{
|
||||||
|
CFormItem *item = NULL;
|
||||||
|
|
||||||
|
if( _FormName.c_str() == formName )
|
||||||
|
return this;
|
||||||
|
|
||||||
|
for( int i = 0; i < childItems.count(); i++ )
|
||||||
|
{
|
||||||
|
item = childItems[ i ]->findItem( formName );
|
||||||
|
if( item != NULL )
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFormItem::clearChildren()
|
||||||
|
{
|
||||||
|
qDeleteAll( childItems );
|
||||||
|
childItems.clear();
|
||||||
|
}
|
||||||
|
|
||||||
CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr)
|
CFormItem *CFormItem::add (TSub type, const char *name, uint structId, const char *formName, uint slot, NLGEORGES::UForm *formPtr)
|
||||||
{
|
{
|
||||||
CFormItem *newNode = new CFormItem();
|
CFormItem *newNode = new CFormItem();
|
||||||
|
|
|
@ -72,6 +72,10 @@ namespace GeorgesQt
|
||||||
|
|
||||||
QIcon getItemImage(CFormItem *rootItem);
|
QIcon getItemImage(CFormItem *rootItem);
|
||||||
|
|
||||||
|
CFormItem* findItem( const QString &formName );
|
||||||
|
|
||||||
|
void clearChildren();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CFormItem*> childItems;
|
QList<CFormItem*> childItems;
|
||||||
QList<QVariant> itemData;
|
QList<QVariant> itemData;
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace GeorgesQt
|
||||||
m_ui.treeViewTabWidget->setTabEnabled (2,false);
|
m_ui.treeViewTabWidget->setTabEnabled (2,false);
|
||||||
|
|
||||||
m_form = 0;
|
m_form = 0;
|
||||||
|
m_model = NULL;
|
||||||
|
|
||||||
m_ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
m_ui.treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
|
@ -87,11 +88,13 @@ namespace GeorgesQt
|
||||||
m_browserCtrl, SLOT(clicked(const QModelIndex&)));
|
m_browserCtrl, SLOT(clicked(const QModelIndex&)));
|
||||||
connect(m_header, SIGNAL(headerClicked(int)),
|
connect(m_header, SIGNAL(headerClicked(int)),
|
||||||
this, SLOT(headerClicked(int)));
|
this, SLOT(headerClicked(int)));
|
||||||
|
connect(m_browserCtrl, SIGNAL(arrayResized(const QString&,int)), this, SLOT(onArrayResized(const QString&,int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog()
|
CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog()
|
||||||
{
|
{
|
||||||
m_browserCtrl = NULL;
|
m_browserCtrl = NULL;
|
||||||
|
m_model = NULL;
|
||||||
|
|
||||||
delete m_form;
|
delete m_form;
|
||||||
qDebug() << "DTOR";
|
qDebug() << "DTOR";
|
||||||
|
@ -265,6 +268,8 @@ namespace GeorgesQt
|
||||||
|
|
||||||
setWindowTitle(loadedForm);
|
setWindowTitle(loadedForm);
|
||||||
// //Modules::mainWin().getTabBar();
|
// //Modules::mainWin().getTabBar();
|
||||||
|
|
||||||
|
m_model = model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,6 +451,23 @@ namespace GeorgesQt
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::onArrayResized( const QString &name, int size )
|
||||||
|
{
|
||||||
|
QModelIndex current = m_ui.treeView->currentIndex();
|
||||||
|
QModelIndex parent = current.parent();
|
||||||
|
int r = current.row();
|
||||||
|
int c = current.column();
|
||||||
|
|
||||||
|
m_model->arrayResized( name, size );
|
||||||
|
m_ui.treeView->reset();
|
||||||
|
m_ui.treeView->expandAll();
|
||||||
|
|
||||||
|
QModelIndex idx = m_model->index( r, c, parent );
|
||||||
|
if( !idx.isValid() )
|
||||||
|
return;
|
||||||
|
m_ui.treeView->setCurrentIndex( idx );
|
||||||
|
}
|
||||||
|
|
||||||
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event)
|
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
Q_EMIT closing();
|
Q_EMIT closing();
|
||||||
|
|
|
@ -47,6 +47,7 @@ namespace GeorgesQt
|
||||||
{
|
{
|
||||||
|
|
||||||
class CGeorges;
|
class CGeorges;
|
||||||
|
class CGeorgesFormModel;
|
||||||
|
|
||||||
class CGeorgesTreeViewDialog: public QDockWidget
|
class CGeorgesTreeViewDialog: public QDockWidget
|
||||||
{
|
{
|
||||||
|
@ -102,6 +103,8 @@ namespace GeorgesQt
|
||||||
void filterRows();
|
void filterRows();
|
||||||
void headerClicked(int);
|
void headerClicked(int);
|
||||||
|
|
||||||
|
void onArrayResized( const QString &name, int size );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CGeorgesTreeViewDialog m_ui;
|
Ui::CGeorgesTreeViewDialog m_ui;
|
||||||
ExpandableHeaderView *m_header;
|
ExpandableHeaderView *m_header;
|
||||||
|
@ -116,6 +119,7 @@ namespace GeorgesQt
|
||||||
bool m_modified;
|
bool m_modified;
|
||||||
|
|
||||||
BrowserCtrl *m_browserCtrl;
|
BrowserCtrl *m_browserCtrl;
|
||||||
|
CGeorgesFormModel *m_model;
|
||||||
|
|
||||||
}; /* CGeorgesTreeViewDialog */
|
}; /* CGeorgesTreeViewDialog */
|
||||||
|
|
||||||
|
|
|
@ -460,6 +460,46 @@ CFormItem *CGeorgesFormModel::addArray(CFormItem *parent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CGeorgesFormModel::arrayResized( const QString &name, int size )
|
||||||
|
{
|
||||||
|
CFormItem *item = m_rootItem->findItem( name );
|
||||||
|
if( item == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
NLGEORGES::UFormElm *elm = NULL;
|
||||||
|
|
||||||
|
item->form()->getRootNode().getNodeByName( &elm, name.toUtf8().constData() );
|
||||||
|
|
||||||
|
if( elm == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
NLGEORGES::CFormElmArray *celm = dynamic_cast< NLGEORGES::CFormElmArray* >( elm );
|
||||||
|
if( celm == NULL )
|
||||||
|
return;
|
||||||
|
|
||||||
|
item->clearChildren();
|
||||||
|
|
||||||
|
for( int i = 0; i < celm->Elements.size(); i++ )
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormElmArray::CElement &e = celm->Elements[ i ];
|
||||||
|
|
||||||
|
QString formName = name;
|
||||||
|
formName += '[';
|
||||||
|
formName += QString::number( i );
|
||||||
|
formName += ']';
|
||||||
|
|
||||||
|
QString n;
|
||||||
|
if( e.Name.empty() )
|
||||||
|
n = "#" + QString::number( i );
|
||||||
|
else
|
||||||
|
n = e.Name.c_str();
|
||||||
|
|
||||||
|
item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,9 @@ namespace GeorgesQt
|
||||||
{
|
{
|
||||||
Q_EMIT dataChanged(index, index);
|
Q_EMIT dataChanged(index, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void arrayResized( const QString &name, int size );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupModelData();
|
void setupModelData();
|
||||||
void loadFormData(NLGEORGES::UFormElm *rootElm, CFormItem *parent);
|
void loadFormData(NLGEORGES::UFormElm *rootElm, CFormItem *parent);
|
||||||
|
|
Loading…
Reference in a new issue