From 04c6c1b48ad572d49593b6967260e711ce2dcbcd Mon Sep 17 00:00:00 2001 From: sfb Date: Thu, 22 Dec 2011 19:58:59 -0600 Subject: [PATCH] Changed: #1409 Added hierarchy to the tile model, renamed the base class to 'Node' --HG-- branch : branch-tile-edit-ovqt-plugin --- .../tile_editor/tile_editor_main_window.cpp | 71 +------- .../src/plugins/tile_editor/tile_item.cpp | 172 ++++++++++++------ .../src/plugins/tile_editor/tile_item.h | 88 ++++++--- .../src/plugins/tile_editor/tile_model.cpp | 68 +++++-- .../src/plugins/tile_editor/tile_model.h | 15 +- 5 files changed, 254 insertions(+), 160 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp index 12596e1bb..427fda7a9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_editor_main_window.cpp @@ -97,15 +97,11 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) // Transition List View m_ui->listViewTransition->setModel(m_model); - //m_ui->listViewTransition->addAction(m_ui->actionAddTile); - //m_ui->listViewTransition->addAction(m_ui->actionDeleteTile); m_ui->listViewTransition->addAction(m_ui->actionReplaceImage); m_ui->listViewTransition->addAction(m_ui->actionDeleteImage); // Displacement List View m_ui->listViewDisplacement->setModel(m_model); - //m_ui->listViewDisplacement->addAction(m_ui->actionAddTile); - //m_ui->listViewDisplacement->addAction(m_ui->actionDeleteTile); m_ui->listViewDisplacement->addAction(m_ui->actionReplaceImage); m_ui->listViewDisplacement->addAction(m_ui->actionDeleteImage); @@ -172,69 +168,11 @@ void TileEditorMainWindow::onTileSetAdd() //} //else //{ - // Create the new tile set. - QVector items; - items.push_back(text); - TileItem *tileSet = new TileItem(items); - // child for 128x128 tiles - QVector tiles128; - tiles128.push_back(QString("128")); - TileTypeTileItem *tile128= new TileTypeTileItem(tiles128); - - // child for 256x256 tiles - QVector tiles256; - tiles256.push_back(QString("256")); - TileTypeTileItem *tile256= new TileTypeTileItem(tiles256); + TileSetNode *tileSet = model->createTileSetNode(text); - // child for transition tiles. - QVector tilesTrans; - tilesTrans.push_back(QString("Transition")); - TileTypeTileItem *tileTrans= new TileTypeTileItem(tilesTrans); - - // Add the default transition tiles. - // TODO tie this to CTileSet::count from NeL - for(int transPos=0; transPos<48; transPos++) - { - QVector tileInfo; - tileInfo.push_back(QString("filename").append(QString::number(transPos+1))); - TileItem *transTile= new TileItem(tileInfo); - tileTrans->appendRow(transTile); - } - - // child for displacement tiles - QVector tilesDisp; - tilesDisp.push_back(QString("Displacement")); - TileTypeTileItem *tileDisp= new TileTypeTileItem(tilesDisp); - - // Add the default displacement tiles. - // TODO tie this to CTileSet::CountDisplace from NeL - for(int dispPos=0; dispPos<16; dispPos++) - { - QVector tileInfo; - tileInfo.push_back(QString("filename").append(QString::number(dispPos+1))); - TileItem *dispTile= new TileItem(tileInfo); - tileDisp->appendRow(dispTile); - } - - // Append them in the correct order to the tile set. - tileSet->appendRow(tile128); - tileSet->appendRow(tile256); - tileSet->appendRow(tileTrans); - tileSet->appendRow(tileDisp); - - model->appendRow(tileSet); - - m_ui->tileSetLV->reset(); - //updateActions() - //} - - // tileBank.addTileSet( text.toStdString() ); - - // ui.tileSetListWidget->addItem(text); - // ui.tileSetListWidget->setCurrentRow(ui.tileSetListWidget->count() - 1); - //} + m_ui->tileSetLV->reset(); } } @@ -256,4 +194,9 @@ void TileEditorMainWindow::changeActiveTileSet(const QModelIndex &newIndex, cons m_ui->listView256->setRootIndex(tile256Idx); m_ui->listViewTransition->setRootIndex(tileTransIdx); m_ui->listViewDisplacement->setRootIndex(tileDispIdx); + + m_ui->listView128->reset(); + m_ui->listView256->reset(); + m_ui->listViewTransition->reset(); + m_ui->listViewDisplacement->reset(); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp index 5758b9280..289bc4a83 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.cpp @@ -18,145 +18,213 @@ #include -TileItem::TileItem(const QVector &data, TileItem *parent) +Node::Node() : m_parentItem(0) { - parentItem = parent; - itemData = data; } -TileItem::~TileItem() +Node::Node(const QVector &data, Node *parent) { - qDeleteAll(childItems); + m_parentItem = parent; + m_itemData = data; } -void TileItem::appendChild(TileItem *item) +Node::~Node() { - childItems.append(item); + qDeleteAll(m_childItems); } -TileItem *TileItem::child(int row) +void Node::appendChild(Node *item) +{ + m_childItems.append(item); +} + +Node *Node::child(int row) { //nlinfo("row %d and size %d", row, childItems.size()); - return childItems.value(row); + return m_childItems.value(row); } -int TileItem::childCount() const +int Node::childCount() const { - return childItems.count(); + return m_childItems.count(); } -int TileItem::childNumber() const +int Node::childNumber() const { - if(parentItem) - return parentItem->childItems.indexOf(const_cast(this)); + if(m_parentItem) + return m_parentItem->m_childItems.indexOf(const_cast(this)); return 0; } -bool TileItem::insertChildren(int position, int count, int columns) +bool Node::insertChildren(int position, int count, int columns) { - if(position<0 || position>childItems.size()) + if(position<0 || position>m_childItems.size()) return false; for(int row = 0; row < count; row++) { QVector data(columns); - TileItem *item = new TileItem(data, this); - childItems.insert(position, item); + Node *item = new Node(data, this); + m_childItems.insert(position, item); } return true; } -bool TileItem::removeChildren(int position, int count) +bool Node::removeChildren(int position, int count) { - if(position<0 || position+count>childItems.size()) + if(position<0 || position+count>m_childItems.size()) return false; for(int row=0; row itemData.size()) + if(position<0 || position > m_itemData.size()) return false; for(int column=0; columninsertColumns(position, columns); return true; } -int TileItem::row() const +int Node::row() const { - if(parentItem) - return parentItem->childItems.indexOf(const_cast(this)); + if(m_parentItem) + return m_parentItem->m_childItems.indexOf(const_cast(this)); return 0; } -int TileItem::columnCount() const +int Node::columnCount() const { - return itemData.count(); + return m_itemData.count(); } -QVariant TileItem::data(int column) const +QVariant Node::data(int column) const { - return itemData.value(column); + return m_itemData.value(column); } -bool TileItem::setData(int column, const QVariant &value) +bool Node::setData(int column, const QVariant &value) { - if(column < 0 || column >= itemData.size()) + if(column < 0 || column >= m_itemData.size()) return false; - itemData[column] = value; + m_itemData[column] = value; return true; } -TileItem *TileItem::parent() +Node *Node::parent() { - return parentItem; + return m_parentItem; } -void TileItem::setParent(TileItem *parent) +void Node::setParent(Node *parent) { - parentItem = parent; + m_parentItem = parent; } -void TileItem::appendRow(const QList &items) +void Node::appendRow(const QList &items) { - Q_FOREACH(TileItem *item, items) + Q_FOREACH(Node *item, items) appendRow(item); } -void TileItem::appendRow(TileItem *item) +void Node::appendRow(Node *item) { item->setParent(this); - childItems.append(item); + m_childItems.append(item); } /////////////////////////////////////////////////// -TileTypeTileItem::TileTypeTileItem(const QVector &data, TileItem *parent) : TileItem(data,parent) +TileSetNode::TileSetNode(QString tileSetName, Node *parent) : m_tileSetName(tileSetName) { + m_parentItem = parent; } -TileTypeTileItem::~TileTypeTileItem() +TileSetNode::~TileSetNode() { - qDeleteAll(childItems); + qDeleteAll(m_childItems); } -QVariant TileTypeTileItem::data(int column) const +QVariant TileSetNode::data(int column) const { - QVariant val = itemData.value(column); + return QVariant(m_tileSetName); +} - nlinfo("the column is %d and the value is '%s'. there are %d values", - column, val.toString().toStdString().c_str(), itemData.size()); - return itemData.value(column); -} \ No newline at end of file +/////////////////////////////////////////////////// + +TileTypeNode::TileTypeNode(TNodeTileType type, Node *parent) : m_nodeTileType(type) +{ + m_parentItem = parent; +} + +TileTypeNode::~TileTypeNode() +{ + qDeleteAll(m_childItems); +} + +QVariant TileTypeNode::data(int column) const +{ + return QVariant(getTileTypeName(m_nodeTileType)); +} + +TileTypeNode::TNodeTileType TileTypeNode::getTileType() +{ + return m_nodeTileType; +} + + +const char *TileTypeNode::getTileTypeName(TNodeTileType type) +{ + switch(type) + { + case Tile128: + return "128"; + case Tile256: + return "256"; + case TileTransition: + return "Transition"; + case TileDisplacement: + return "Displacement"; + default: + break; + } + return "UNKNOWN"; +} + +/////////////////////////////////////////////////// + +TileItemNode::TileItemNode(int tileId, TTileChannel channel, QString filename, Node *parent) : m_tileId(tileId) +{ + m_tileFilename[channel] = filename; + m_parentItem = parent; + nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileDiffuse].toStdString().c_str()); +} + +TileItemNode::~TileItemNode() +{ + qDeleteAll(m_childItems); +} + +void TileItemNode::setTileFilename(TTileChannel channel, QString filename) +{ + m_tileFilename[channel] = filename; +} + +QVariant TileItemNode::data(int column) const +{ + nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileDiffuse].toStdString().c_str()); + // find some way to know which file/bitmap to display + return QVariant(m_tileFilename[TileDiffuse]); +} diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h index 8f1c6a61a..eceb38a79 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_item.h @@ -22,54 +22,90 @@ #include #include -class TileItem +class Node { public: + Node(); + Node(const QVector &data, Node *parent=0); + virtual ~Node(); - TileItem(const QVector &data, TileItem *parent=0); - virtual ~TileItem(); + void appendChild(Node *child); - void appendChild(TileItem *child); - - TileItem *child(int row); + Node *child(int row); int childCount() const; int childNumber() const; int columnCount() const; bool setData(int column, const QVariant &value); - QVariant data(int column) const; + virtual QVariant data(int column) const; bool insertChildren(int position, int count, int columns); bool removeChildren(int position, int count); bool insertColumns(int position, int columns); int row() const; - TileItem *parent(); - void setParent(TileItem *parent); + Node *parent(); + void setParent(Node *parent); - void appendRow(const QList &items); - void appendRow(TileItem *item); - - //QImage *getTileImageFromChannel(int channel); - - //int getTileIndex() { return m_tileIndex; } - //QString getTileFilename() { return m_tileFilename; } + void appendRow(const QList &items); + void appendRow(Node *item); protected: - QList childItems; - QVector itemData; - TileItem *parentItem; - - //QMap m_tileChannels; - //int m_tileIndex; - //QString m_tileFilename; + QList m_childItems; + QVector m_itemData; + Node *m_parentItem; }; -class TileTypeTileItem : public TileItem +class TileSetNode : public Node { public: - TileTypeTileItem(const QVector &data, TileItem *parent=0); - virtual ~TileTypeTileItem(); + TileSetNode(QString tileSetName, Node *parent=0); + virtual ~TileSetNode(); QVariant data(int column) const; + + const QString &getTileSetName(); +private: + QString m_tileSetName; +}; + +class TileTypeNode : public Node +{ +public: + enum TNodeTileType + { + Tile128 = 0, + Tile256 = 1, + TileTransition = 2, + TileDisplacement = 3 + }; + + TileTypeNode(TNodeTileType type, Node *parent=0); + virtual ~TileTypeNode(); + QVariant data(int column) const; + + TNodeTileType getTileType(); + + static const char *getTileTypeName(TNodeTileType type); +private: + TNodeTileType m_nodeTileType; +}; + +class TileItemNode : public Node +{ +public: + enum TTileChannel + { + TileDiffuse = 0, + TileAdditive = 1, + TileAlpha = 2, + }; + + TileItemNode(int tileId, TTileChannel channel, QString filename, Node *parent=0); + virtual ~TileItemNode(); + QVariant data(int column) const; + void setTileFilename(TTileChannel channel, QString filename); +private: + int m_tileId; + QMap m_tileFilename; }; #endif // TILE_ITEM_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp index 20911310c..d31289c21 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.cpp @@ -25,7 +25,7 @@ TileModel::TileModel(const QStringList &headers, QObject *parent) : QAbstractIte Q_FOREACH(QString header, headers) rootData << header; - rootItem = new TileItem(rootData); + rootItem = new Node(rootData); } TileModel::~TileModel() @@ -33,11 +33,11 @@ TileModel::~TileModel() delete rootItem; } -TileItem *TileModel::getItem(const QModelIndex &index) const +Node *TileModel::getItem(const QModelIndex &index) const { if(index.isValid()) { - TileItem *item = static_cast(index.internalPointer()); + Node *item = static_cast(index.internalPointer()); if(item) return item; } return rootItem; @@ -48,9 +48,9 @@ QModelIndex TileModel::index(int row, int column, const QModelIndex &parent) con if(parent.isValid() && parent.column() != 0) return QModelIndex(); - TileItem *parentItem = getItem(parent); + Node *parentItem = getItem(parent); - TileItem *childItem = parentItem->child(row); + Node *childItem = parentItem->child(row); if(childItem) return createIndex(row, column, childItem); else @@ -62,8 +62,8 @@ QModelIndex TileModel::parent(const QModelIndex &index) const if(!index.isValid()) return QModelIndex(); - TileItem *childItem = getItem(index); - TileItem *parentItem = childItem->parent(); + Node *childItem = getItem(index); + Node *parentItem = childItem->parent(); if(parentItem == rootItem) return QModelIndex(); @@ -73,13 +73,13 @@ QModelIndex TileModel::parent(const QModelIndex &index) const int TileModel::rowCount(const QModelIndex &parent) const { - TileItem *parentItem = getItem(parent); + Node *parentItem = getItem(parent); return parentItem->childCount(); } int TileModel::columnCount(const QModelIndex &parent) const { - TileItem *parentItem = getItem(parent); + Node *parentItem = getItem(parent); return parentItem->columnCount(); } @@ -91,7 +91,7 @@ QVariant TileModel::data(const QModelIndex &index, int role) const if(role != Qt::DisplayRole) return QVariant(); - TileItem *item = static_cast(index.internalPointer()); + Node *item = static_cast(index.internalPointer()); return item->data(index.column()); } @@ -111,13 +111,57 @@ QVariant TileModel::headerData(int section, Qt::Orientation orientation, int rol return QVariant(); } -void TileModel::appendRow(const QList &items) +void TileModel::appendRow(const QList &items) { rootItem->appendRow(items); } -void TileModel::appendRow(TileItem *item) +void TileModel::appendRow(Node *item) { rootItem->appendRow(item); +} + +TileSetNode *TileModel::createTileSetNode(QString tileSetName) +{ + // Create the new tile set. + TileSetNode *tileSet = new TileSetNode(tileSetName); + + // child for 128x128 tiles + TileTypeNode *tile128= new TileTypeNode(TileTypeNode::Tile128); + + // child for 256x256 tiles + TileTypeNode *tile256= new TileTypeNode(TileTypeNode::Tile256); + + // child for transition tiles. + TileTypeNode *tileTrans= new TileTypeNode(TileTypeNode::TileTransition); + + // Add the default transition tiles. + // TODO tie this to CTileSet::count from NeL + for(int transPos=0; transPos<48; transPos++) + { + TileItemNode *transTile= new TileItemNode(transPos, TileItemNode::TileDiffuse, QString("filename").append(QString::number(transPos+1))); + tileTrans->appendRow(transTile); + } + + // child for displacement tiles + TileTypeNode *tileDisp= new TileTypeNode(TileTypeNode::TileDisplacement); + + // Add the default displacement tiles. + // TODO tie this to CTileSet::CountDisplace from NeL + for(int dispPos=0; dispPos<16; dispPos++) + { + TileItemNode *dispTile= new TileItemNode(dispPos, TileItemNode::TileDiffuse, QString("filename").append(QString::number(dispPos+1))); + tileDisp->appendRow(dispTile); + } + + // Append them in the correct order to the tile set. + tileSet->appendRow(tile128); + tileSet->appendRow(tile256); + tileSet->appendRow(tileTrans); + tileSet->appendRow(tileDisp); + + this->appendRow(tileSet); + + return tileSet; } \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h index 140f60555..fba135812 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/tile_editor/tile_model.h @@ -21,7 +21,8 @@ #include -class TileItem; +class Node; +class TileSetNode; class TileModel : public QAbstractItemModel { @@ -40,15 +41,17 @@ public: int columnCount(const QModelIndex &parent = QModelIndex()) const; // Tile Model specific functions - void appendRow(const QList &items); - void appendRow(TileItem *item); + void appendRow(const QList &items); + void appendRow(Node *item); + + TileSetNode *createTileSetNode(QString tileSetName); private: - TileItem *getItem(const QModelIndex &index) const; + Node *getItem(const QModelIndex &index) const; //QList m_tiles; //int m_activeEditChannel; - TileItem *rootItem; + Node *rootItem; }; -#endif // TILE_128_MODEL_H +#endif // TILE_MODEL_H