From cf3f72741f423cd4c8ec9f989d3c75cb85aebf78 Mon Sep 17 00:00:00 2001 From: fo76utils <87907510+fo76utils@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:15:28 +0200 Subject: [PATCH] Removed use of deprecated Qt functions, fixed compiler warnings --- lib/fsengine/bsa.cpp | 104 +++++++++++++++-------------- lib/lz4frame.c | 14 ++-- src/data/nifitem.h | 6 +- src/data/niftypes.h | 8 +++ src/data/nifvalue.cpp | 8 ++- src/gamemanager.h | 3 +- src/gl/bsshape.cpp | 58 ++++++++-------- src/gl/controllers.cpp | 29 ++++---- src/gl/glcontroller.cpp | 37 +++++----- src/gl/glnode.cpp | 46 ++++++------- src/gl/glproperty.cpp | 2 +- src/gl/gltools.cpp | 27 ++++---- src/io/materialfile.cpp | 6 +- src/io/nifstream.cpp | 1 + src/lib/importex/3ds.cpp | 13 ++-- src/lib/importex/3ds.h | 14 ++-- src/lib/importex/col.cpp | 11 +-- src/main.cpp | 6 +- src/model/kfmmodel.cpp | 2 +- src/model/nifdelegate.cpp | 6 +- src/model/nifmodel.cpp | 2 +- src/model/nifmodel.h | 2 +- src/model/nifproxymodel.cpp | 2 +- src/nifskope.cpp | 9 +-- src/nifskope.h | 1 - src/nifskope_ui.cpp | 25 ++++--- src/spellbook.cpp | 4 +- src/spells/animation.cpp | 37 +++++----- src/spells/blocks.cpp | 80 ++++++++++++---------- src/spells/color.cpp | 7 +- src/spells/flags.cpp | 4 +- src/spells/havok.cpp | 21 +++--- src/spells/mesh.cpp | 37 +++++----- src/spells/misc.cpp | 13 ++-- src/spells/moppcode.cpp | 11 +-- src/spells/morphctrl.cpp | 15 +++-- src/spells/normals.cpp | 10 +-- src/spells/optimize.cpp | 19 +++--- src/spells/sanitize.cpp | 27 ++++---- src/spells/skeleton.cpp | 96 ++++++++++++-------------- src/spells/stringpalette.cpp | 21 +++--- src/spells/strippify.cpp | 51 +++++++------- src/spells/tangentspace.cpp | 13 ++-- src/spells/texture.cpp | 11 ++- src/spells/texture.h | 3 +- src/spells/transform.cpp | 3 +- src/ui/checkablemessagebox.cpp | 8 +-- src/ui/widgets/colorwheel.cpp | 16 ++--- src/ui/widgets/fileselect.cpp | 2 +- src/ui/widgets/floatslider.cpp | 4 +- src/ui/widgets/groupbox.h | 4 +- src/ui/widgets/inspect.h | 2 +- src/ui/widgets/nifcheckboxlist.cpp | 2 +- src/ui/widgets/nifview.cpp | 25 +++---- src/ui/widgets/nifview.h | 4 +- src/ui/widgets/uvedit.cpp | 16 ++--- src/ui/widgets/valueedit.cpp | 10 +-- src/ui/widgets/xmlcheck.cpp | 12 ++-- src/version.cpp | 8 +-- src/xml/kfmxml.cpp | 1 + src/xml/nifxml.cpp | 8 ++- 61 files changed, 546 insertions(+), 501 deletions(-) diff --git a/lib/fsengine/bsa.cpp b/lib/fsengine/bsa.cpp index e73c5d70..c0474690 100644 --- a/lib/fsengine/bsa.cpp +++ b/lib/fsengine/bsa.cpp @@ -35,6 +35,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "zlib/zlib.h" #include "lz4frame.h" #include "zlib.hpp" +#include "gamemanager.h" #include #include @@ -68,7 +69,7 @@ static bool BSAReadSizedString( QFile & bsa, QString & s ) quint8 len; if ( bsa.read( (char *)&len, 1 ) != 1 ) return false; - + QByteArray b( len, char(0) ); if ( bsa.read( b.data(), len ) == len ) { s = QString::fromLatin1( b ); @@ -111,6 +112,7 @@ QByteArray gUncompress( const char * data, const int size ) switch ( ret ) { case Z_NEED_DICT: ret = Z_DATA_ERROR; // and fall through + [[fallthrough]]; case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd( &strm ); @@ -159,10 +161,10 @@ bool BSA::canOpen( const QString & fn ) if ( f.open( QIODevice::ReadOnly ) ) { quint32 magic, version; - + if ( f.read( (char *) & magic, sizeof( magic ) ) != 4 ) return false; - + //qDebug() << "Magic:" << QString::number( magic, 16 ); if ( magic == F4_BSAHEADER_FILEID ) { if ( f.read( (char *) & version, sizeof( version ) ) != 4 ) @@ -178,7 +180,7 @@ bool BSA::canOpen( const QString & fn ) } } - + return false; } @@ -186,14 +188,14 @@ bool BSA::canOpen( const QString & fn ) bool BSA::open() { QMutexLocker lock( & bsaMutex ); - + try { if ( ! bsa.open( QIODevice::ReadOnly ) ) throw QString( "file open" ); - + quint32 magic; - + bsa.read( (char*) &magic, sizeof( magic ) ); if ( magic == F4_BSAHEADER_FILEID ) { @@ -285,28 +287,28 @@ bool BSA::open() else if ( magic == OB_BSAHEADER_FILEID ) { bsa.read( (char*) &version, sizeof( version ) ); - + if ( version != OB_BSAHEADER_VERSION && version != F3_BSAHEADER_VERSION && version != SSE_BSAHEADER_VERSION ) throw QString( "file version" ); - + OBBSAHeader header; - + if ( bsa.read( (char *) & header, sizeof( header ) ) != sizeof( header ) ) throw QString( "header size" ); - + numFiles = header.FileCount; - + //qDebug() << bsaName << header; - + if ( ( header.ArchiveFlags & OB_BSAARCHIVE_PATHNAMES ) == 0 || ( header.ArchiveFlags & OB_BSAARCHIVE_FILENAMES ) == 0 ) throw QString( "header flags" ); - + compressToggle = header.ArchiveFlags & OB_BSAARCHIVE_COMPRESSFILES; - + if (version == F3_BSAHEADER_VERSION || version == SSE_BSAHEADER_VERSION) { namePrefix = header.ArchiveFlags & F3_BSAARCHIVE_PREFIXFULLFILENAMES; } - + int folderSize = 0; if ( version != SSE_BSAHEADER_VERSION ) folderSize = sizeof( OBBSAFolderInfo ); @@ -315,14 +317,14 @@ bool BSA::open() if ( !bsa.seek( header.FolderRecordOffset + header.FolderNameLength + header.FolderCount * (1 + folderSize) + header.FileCount * sizeof( OBBSAFileInfo ) ) ) throw QString( "file name seek" ); - + QByteArray fileNames( header.FileNameLength, char(0) ); if ( bsa.read( fileNames.data(), header.FileNameLength ) != header.FileNameLength ) throw QString( "file name read" ); quint32 fileNameIndex = 0; - + //qDebug() << bsa.pos() - header.FileNameLength << fileNames; - + if ( ! bsa.seek( header.FolderRecordOffset ) ) throw QString( "folder info seek" ); @@ -360,16 +362,16 @@ bool BSA::open() //qDebug() << "folderName" << folderName; throw QString( "folder name read" ); } - - + + BSAFolder * folder = insertFolder( folderName ); - + quint32 fcnt = folderInfo.fileCount; totalFileCount += fcnt; QVector fileInfos( fcnt ); - if ( bsa.read( (char *) fileInfos.data(), fcnt * sizeof( OBBSAFileInfo ) ) != fcnt * sizeof( OBBSAFileInfo ) ) + if ( bsa.read( (char *) fileInfos.data(), fcnt * sizeof( OBBSAFileInfo ) ) != qint64( fcnt * sizeof( OBBSAFileInfo ) ) ) throw QString( "file info read" ); - + for ( const OBBSAFileInfo fileInfo : fileInfos ) { if ( fileNameIndex >= header.FileNameLength ) @@ -377,48 +379,48 @@ bool BSA::open() QString fileName = QString::fromLatin1( fileNames.data() + fileNameIndex ); fileNameIndex += fileName.length() + 1; - + insertFile( folder, fileName, fileInfo.sizeFlags, fileInfo.offset ); } } - + if ( totalFileCount != header.FileCount ) throw QString( "file count" ); } else if ( magic == MW_BSAHEADER_FILEID ) { MWBSAHeader header; - + if ( bsa.read( (char *) & header, sizeof( header ) ) != sizeof( header ) ) throw QString( "header" ); - + numFiles = header.FileCount; compressToggle = false; namePrefix = false; - + // header is 12 bytes, hash table is 8 bytes per entry quint32 dataOffset = 12 + header.HashOffset + header.FileCount * 8; - + // file size/offset table QVector sizeOffset( header.FileCount ); - if ( bsa.read( (char *) sizeOffset.data(), header.FileCount * sizeof( MWBSAFileSizeOffset ) ) != header.FileCount * sizeof( MWBSAFileSizeOffset ) ) + if ( bsa.read( (char *) sizeOffset.data(), header.FileCount * sizeof( MWBSAFileSizeOffset ) ) != qint64( header.FileCount * sizeof( MWBSAFileSizeOffset ) ) ) throw QString( "file size/offset" ); - + // filename offset table QVector nameOffset( header.FileCount ); - if ( bsa.read( (char *) nameOffset.data(), header.FileCount * sizeof( quint32 ) ) != header.FileCount * sizeof( quint32 ) ) + if ( bsa.read( (char *) nameOffset.data(), header.FileCount * sizeof( quint32 ) ) != qint64( header.FileCount * sizeof( quint32 ) ) ) throw QString( "file name offset" ); - + // filenames. size is given by ( HashOffset - ( 8 * number of file/size offsets) - ( 4 * number of filenames) ) // i.e. ( HashOffset - ( 12 * number of files ) ) QByteArray fileNames; fileNames.resize( header.HashOffset - 12 * header.FileCount ); - if ( bsa.read( (char *) fileNames.data(), header.HashOffset - 12 * header.FileCount ) != header.HashOffset - 12 * header.FileCount ) + if ( bsa.read( (char *) fileNames.data(), header.HashOffset - 12 * header.FileCount ) != qint64( header.HashOffset - 12 * header.FileCount ) ) throw QString( "file names" ); // table of 8 bytes of hash values follow, but we don't need to know what they are // file data follows that, which is fetched by fileContents - + for ( quint32 c = 0; c < header.FileCount; c++ ) { QString fname = fileNames.data() + nameOffset[ c ]; @@ -429,9 +431,9 @@ bool BSA::open() dname = fname.left( x ); fname = fname.remove( 0, x + 1 ); } - + // qDebug() << "inserting" << dname << fname; - + insertFile( insertFolder( dname ), fname, sizeOffset[ c ].size, dataOffset + sizeOffset[ c ].offset ); } } @@ -443,9 +445,9 @@ bool BSA::open() status = e; return false; } - + status = "loaded successful"; - + return true; } @@ -453,7 +455,7 @@ bool BSA::open() void BSA::close() { QMutexLocker lock( & bsaMutex ); - + bsa.close(); qDeleteAll( root->children ); qDeleteAll( root->files ); @@ -675,7 +677,7 @@ bool BSA::fileContents( const QString & fn, QByteArray & content ) std::memcpy( chunkData.data(), chunkDataTmp.data(), chunk.unpackedSize ); } else { chunkData = gUncompress( chunkData, chunk.packedSize ); - if ( chunkData.size() != chunk.unpackedSize ) + if ( chunkData.size() != qsizetype( chunk.unpackedSize ) ) qCritical() << "Size does not match at " << chunk.offset; } } @@ -714,15 +716,15 @@ BSA::BSAFolder * BSA::insertFolder( QString name ) { if ( name.isEmpty() ) return root; - + name = name.replace( "\\", "/" ).toLower(); - + BSAFolder * folder = folders.value( name ); if ( !folder ) { folder = new BSAFolder; folder->name = name; folders.insert( name, folder ); - + int p = name.lastIndexOf( "/" ); if ( p >= 0 ) { folder->parent = insertFolder( name.left( p ) ); @@ -732,7 +734,7 @@ BSA::BSAFolder * BSA::insertFolder( QString name ) root->children.insert( name, folder ); } } - + return folder; } @@ -808,7 +810,7 @@ QString BSA::owner( const QString & ) const // see bsa.h QDateTime BSA::fileTime( const QString & ) const { - return bsaInfo.created( ); + return bsaInfo.birthTime( ); } bool BSA::scan( const BSA::BSAFolder * folder, QStandardItem * item, QString path ) @@ -907,7 +909,7 @@ void BSAProxyModel::resetFilter() bool BSAProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceParent ) const { if ( !filterRegExp().isEmpty() ) { - + QModelIndex sourceIndex0 = sourceModel()->index( sourceRow, 0, sourceParent ); QModelIndex sourceIndex1 = sourceModel()->index( sourceRow, 1, sourceParent ); if ( sourceIndex0.isValid() ) { @@ -920,7 +922,7 @@ bool BSAProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceP QString key0 = sourceModel()->data( sourceIndex0, filterRole() ).toString(); QString key1 = sourceModel()->data( sourceIndex1, filterRole() ).toString(); - + bool typeMatch = true; if ( filetypes.count() ) { typeMatch = false; @@ -943,8 +945,8 @@ bool BSAProxyModel::lessThan( const QModelIndex & left, const QModelIndex & righ QString leftString = sourceModel()->data( left ).toString(); QString rightString = sourceModel()->data( right ).toString(); - QModelIndex leftChild = left.child( 0, 0 ); - QModelIndex rightChild = right.child( 0, 0 ); + QModelIndex leftChild = QModelIndex_child( left ); + QModelIndex rightChild = QModelIndex_child( right ); if ( !leftChild.isValid() && rightChild.isValid() ) return false; diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 48520eb7..86ef777b 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -2383,12 +2383,12 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf cctxI.version = LZ4F_VERSION; cctxI.maxBufferSize = 5 MB; /* mess with real buffer size to prevent allocation; works because autoflush==1 & stableSrc==1 */ - if (preferencesPtr!=NULL) - prefs = *preferencesPtr; - else - memset(&prefs, 0, sizeof(prefs)); - if (prefs.frameInfo.contentSize != 0) - prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ + if (preferencesPtr!=NULL) + prefs = *preferencesPtr; + else + memset(&prefs, 0, sizeof(prefs)); + if (prefs.frameInfo.contentSize != 0) + prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */ if (prefs.compressionLevel < LZ4HC_MIN_CLEVEL) { cctxI.lz4CtxPtr = &lz4ctx; @@ -3158,6 +3158,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, dctxPtr->tmpInTarget = minFHSize; /* minimum to attempt decode */ dctxPtr->dStage = dstage_storeHeader; /* pass-through */ + [[fallthrough]]; case dstage_storeHeader: { size_t sizeToCopy = dctxPtr->tmpInTarget - dctxPtr->tmpInSize; @@ -3272,6 +3273,7 @@ size_t LZ4F_decompress(LZ4F_decompressionContext_t decompressionContext, dctxPtr->dStage = dstage_decodeCBlock; /* pass-through */ } + [[fallthrough]]; case dstage_decodeCBlock: if ((size_t)(dstEnd-dstPtr) < dctxPtr->maxBlockSize) /* not enough place into dst : decode into tmpOut */ diff --git a/src/data/nifitem.h b/src/data/nifitem.h index 5a7158ce..b637f336 100644 --- a/src/data/nifitem.h +++ b/src/data/nifitem.h @@ -385,8 +385,8 @@ class NifItem { ChildIterator( const QVector & children ) : m_children( children ) {} - _ChildIterator begin() { return _ChildIterator(m_children.begin()); } - _ChildIterator end() { return _ChildIterator(m_children.end()); } + _ChildIterator begin() { return _ChildIterator(&(*(m_children.begin()))); } + _ChildIterator end() { return _ChildIterator(&(*(m_children.end()))); } private: const QVector & m_children; @@ -507,7 +507,7 @@ class NifItem void removeChildren( int row, int count ) { int iStart = std::max( row, 0 ); - int iEnd = std::min( row + count, childItems.count() ); + int iEnd = std::min( row + count, int( childItems.count() ) ); if ( iStart < iEnd ) { for ( int i = iStart; i < iEnd; i++ ) { NifItem * item = childItems.at( i ); diff --git a/src/data/niftypes.h b/src/data/niftypes.h index f5a81e73..ab6717d4 100644 --- a/src/data/niftypes.h +++ b/src/data/niftypes.h @@ -1180,6 +1180,14 @@ class Triangle return (v[0] == other.v[0]) && (v[1] == other.v[1]) && (v[2] == other.v[2]); } + //! For use as map key + bool operator<( const Triangle & other ) const + { + return ( v[0] < other.v[0] + || ( v[0] == other.v[0] && v[1] < other.v[1] ) + || ( v[0] == other.v[0] && v[1] == other.v[1] && v[2] < other.v[2] ) ); + } + protected: quint16 v[3]; friend class NifIStream; diff --git a/src/data/nifvalue.cpp b/src/data/nifvalue.cpp index 1c2301c8..2a678f0f 100644 --- a/src/data/nifvalue.cpp +++ b/src/data/nifvalue.cpp @@ -154,7 +154,7 @@ QString NifValue::typeDescription( const QString & typId ) if ( txtCache.contains( typId ) ) return txtCache[typId]; - + QString txt = QString( "

%1 (%2)

%3

" ).arg( typId, aliasMap.value( typId ), typeTxt.value( typId ) ); txt += "
"; @@ -252,7 +252,7 @@ QString NifValue::enumOptionName( const QString & eid, quint32 val ) auto it = eo.o.constBegin(); while ( it != eo.o.constEnd() ) { if ( val & ( 1 << it.key() ) ) { - val2 |= ( 1 << it.key() ); + val2 |= ( 1 << it.key() ); if ( !text.isEmpty() ) text += " | "; @@ -305,7 +305,7 @@ quint32 NifValue::enumOptionValue( const QString & eid, const QString & oid, boo *ok = true; quint32 value = 0; - QStringList list = oid.split( QRegularExpression( "\\s*\\|\\s*" ), QString::SkipEmptyParts ); + QStringList list = oid.split( QRegularExpression( "\\s*\\|\\s*" ), Qt::SkipEmptyParts ); QStringListIterator lit( list ); while ( lit.hasNext() ) { @@ -884,6 +884,8 @@ bool NifValue::setFromString( const QString & s, const BaseModel * model, const static_cast( val.data )->fromString( s ); ok = true; break; + default: + break; } if ( !ok && model ) diff --git a/src/gamemanager.h b/src/gamemanager.h index aa04c2f3..e27b661c 100644 --- a/src/gamemanager.h +++ b/src/gamemanager.h @@ -351,7 +351,8 @@ void GameManager::update_status(const QString& game, bool status) } // end namespace Game -static inline QModelIndex QModelIndex_child( const QModelIndex& m, int arow = 0, int acolumn = 0 ) +template < typename T > +static inline QModelIndex QModelIndex_child( const T & m, int arow = 0, int acolumn = 0 ) { const QAbstractItemModel * model = m.model(); if ( !model ) diff --git a/src/gl/bsshape.cpp b/src/gl/bsshape.cpp index 14a1500f..adda6720 100644 --- a/src/gl/bsshape.cpp +++ b/src/gl/bsshape.cpp @@ -6,6 +6,7 @@ #include "io/material.h" #include "model/nifmodel.h" +#include "gamemanager.h" void BSShape::updateImpl( const NifModel * nif, const QModelIndex & index ) { @@ -156,7 +157,7 @@ void BSShape::updateData( const NifModel * nif ) auto b = nif->getIndex( iSkinData, "Bone List" ); for ( int i = 0; i < nTotalWeights; i++ ) - weights[i].setTransform( nif, b.child( i, 0 ) ); + weights[i].setTransform( nif, QModelIndex_child( b, i ) ); } } @@ -170,12 +171,12 @@ QModelIndex BSShape::vertexAt( int idx ) const auto blk = iBlock; if ( iSkinPart.isValid() ) { if ( isDynamic ) - return nif->getIndex( blk, "Vertices" ).child( idx, 0 ); + return QModelIndex_child( nif->getIndex( blk, "Vertices" ), idx ); blk = iSkinPart; } - return nif->getIndex( nif->getIndex( blk, "Vertex Data" ).child( idx, 0 ), "Vertex" ); + return nif->getIndex( QModelIndex_child( nif->getIndex( blk, "Vertex Data" ), idx ), "Vertex" ); } void BSShape::transformShapes() @@ -246,7 +247,7 @@ void BSShape::transformShapes() } } -void BSShape::drawShapes( NodeList * secondPass, bool presort ) +void BSShape::drawShapes( NodeList * secondPass, [[maybe_unused]] bool presort ) { if ( isHidden() ) return; @@ -316,12 +317,12 @@ void BSShape::drawShapes( NodeList * secondPass, bool presort ) else glDisable( GL_FRAMEBUFFER_SRGB ); shader = scene->renderer->setupProgram( this, shader ); - + } else { if ( nif->getBSVersion() >= 151 ) glDisable( GL_FRAMEBUFFER_SRGB ); } - + if ( isDoubleSided ) { glCullFace( GL_FRONT ); glDrawElements( GL_TRIANGLES, triangles.count() * 3, GL_UNSIGNED_SHORT, triangles.constData() ); @@ -345,9 +346,11 @@ void BSShape::drawShapes( NodeList * secondPass, bool presort ) case Scene::Level0: if ( lod2tris.count() ) glDrawElements( GL_TRIANGLES, lod2tris.count() * 3, GL_UNSIGNED_SHORT, lod2tris.constData() ); + [[fallthrough]]; case Scene::Level1: if ( lod1tris.count() ) glDrawElements( GL_TRIANGLES, lod1tris.count() * 3, GL_UNSIGNED_SHORT, lod1tris.constData() ); + [[fallthrough]]; case Scene::Level2: default: if ( lod0tris.count() ) @@ -449,7 +452,7 @@ void BSShape::drawSelection() const // Parent index auto pBlock = nif->getBlockIndex( nif->getParent( blk ) ); - auto push = [this] ( const Transform & t ) { + auto push = [this] ( const Transform & t ) { if ( transformRigid ) { glPushMatrix(); glMultMatrix( t ); @@ -495,7 +498,6 @@ void BSShape::drawSelection() const if ( normalScale < 0.1f ) normalScale = 0.1f; - // Draw All Verts lambda auto allv = [this]( float size ) { @@ -515,7 +517,7 @@ void BSShape::drawSelection() const drawSphereSimple( sph.center, sph.radius, 72 ); } } - + if ( blockName.startsWith( "BSPackedCombined" ) && pBlock == iBlock ) { QVector idxs; if ( n == "Bounding Sphere" ) { @@ -525,13 +527,13 @@ void BSShape::drawSelection() const int dataCt = nif->rowCount( data ); for ( int i = 0; i < dataCt; i++ ) { - auto d = data.child( i, 0 ); + auto d = QModelIndex_child( data, i ); auto c = nif->getIndex( d, "Combined" ); int cCt = nif->rowCount( c ); for ( int j = 0; j < cCt; j++ ) { - idxs += nif->getIndex( c.child( j, 0 ), "Bounding Sphere" ); + idxs += nif->getIndex( QModelIndex_child( c, j ), "Bounding Sphere" ); } } } @@ -541,10 +543,12 @@ void BSShape::drawSelection() const return; } - Vector3 pTrans = nif->get( pBlock.child( 1, 0 ), "Translation" ); +#if 0 + Vector3 pTrans = nif->get( QModelIndex_child( pBlock, 1 ), "Translation" ); +#endif auto iBSphere = nif->getIndex( pBlock, "Bounding Sphere" ); - Vector3 pbvC = nif->get( iBSphere.child( 0, 2 ) ); - float pbvR = nif->get( iBSphere.child( 1, 2 ) ); + Vector3 pbvC = nif->get( QModelIndex_child( iBSphere, 0, 2 ) ); + float pbvR = nif->get( QModelIndex_child( iBSphere, 1, 2 ) ); if ( pbvR > 0.0 ) { glColor4f( 0, 1, 0, 0.33f ); @@ -555,7 +559,7 @@ void BSShape::drawSelection() const for ( auto i : idxs ) { // Transform compound - auto iTrans = i.parent().child( 1, 0 ); + auto iTrans = QModelIndex_child( i.parent(), 1 ); Matrix mat = nif->get( iTrans, "Rotation" ); //auto trans = nif->get( iTrans, "Translation" ); float scale = nif->get( iTrans, "Scale" ); @@ -602,8 +606,8 @@ void BSShape::drawSelection() const glVertex( transVerts.value( s ) ); glEnd(); } - } - + } + glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // Draw Lines lambda @@ -635,7 +639,7 @@ void BSShape::drawSelection() const glLineWidth( lineWidth ); } }; - + // Draw Normals if ( n.contains( "Normal" ) ) { lines( transNorms ); @@ -669,7 +673,7 @@ void BSShape::drawSelection() const int s; QVector cols = { { 255, 0, 0, 128 }, { 0, 255, 0, 128 }, { 0, 0, 255, 128 }, { 255, 255, 0, 128 }, - { 0, 255, 255, 128 }, { 255, 0, 255, 128 }, { 255, 255, 255, 128 } + { 0, 255, 255, 128 }, { 255, 0, 255, 128 }, { 255, 255, 255, 128 } }; glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); @@ -700,9 +704,9 @@ void BSShape::drawSelection() const for ( int l = 0; l < loopNum; l++ ) { if ( n != "Num Primitives" && !isSubSegArray && !isSegmentArray ) { - sidx = idx.child( 1, 0 ); + sidx = QModelIndex_child( idx, 1 ); } else if ( isSegmentArray ) { - sidx = idx.child( l, 0 ).child( 1, 0 ); + sidx = QModelIndex_child( QModelIndex_child( idx, l ), 1 ); } s = sidx.row() + o; @@ -712,13 +716,13 @@ void BSShape::drawSelection() const auto recs = sidx.sibling( s + 3, 0 ); for ( int i = 0; i < numRec; i++ ) { - auto subrec = recs.child( i, 0 ); + auto subrec = QModelIndex_child( recs, i ); int o = 0; if ( subrec.data( Qt::DisplayRole ).toString() != "Sub Segment" ) o = 3; // Offset 3 rows for < 130 BSGeometrySegmentData - auto suboff = subrec.child( o, 2 ).data().toInt() / 3; - auto subcnt = subrec.child( o + 1, 2 ).data().toInt(); + auto suboff = QModelIndex_child( subrec, o, 2 ).data().toInt() / 3; + auto subcnt = QModelIndex_child( subrec, o + 1, 2 ).data().toInt(); for ( int j = suboff; j < subcnt + suboff; j++ ) { if ( j >= maxTris ) @@ -741,7 +745,7 @@ void BSShape::drawSelection() const for ( int i = off; i < cnt + off; i++ ) { if ( i >= maxTris ) continue; - + Triangle tri = triangles[i]; glBegin( GL_TRIANGLES ); glVertex( transVerts.value( tri.v1() ) ); @@ -764,7 +768,7 @@ void BSShape::drawSelection() const int ct = nif->rowCount( iBones ); for ( int i = 0; i < ct; i++ ) { - auto b = iBones.child( i, 0 ); + auto b = QModelIndex_child( iBones, i ); boneSphere( nif, b ); } } @@ -776,7 +780,7 @@ void BSShape::drawSelection() const if ( n == "Bone List" ) { if ( nif->isArray( idx ) ) { for ( int i = 0; i < nif->rowCount( idx ); i++ ) - boneSphere( nif, idx.child( i, 0 ) ); + boneSphere( nif, QModelIndex_child( idx, i ) ); } else { boneSphere( nif, idx ); } diff --git a/src/gl/controllers.cpp b/src/gl/controllers.cpp index 7d01d0f4..c3dc6125 100644 --- a/src/gl/controllers.cpp +++ b/src/gl/controllers.cpp @@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "gl/glscene.h" #include "model/nifmodel.h" +#include "gamemanager.h" // `NiControllerManager` blocks @@ -67,7 +68,7 @@ bool ControllerManager::update( const NifModel * nif, const QModelIndex & index QModelIndex iTags = nif->getIndex( iKeys, "Text Keys" ); for ( int r = 0; r < nif->rowCount( iTags ); r++ ) { - tags.insert( nif->get( iTags.child( r, 0 ), "Value" ), nif->get( iTags.child( r, 0 ), "Time" ) ); + tags.insert( nif->get( QModelIndex_child( iTags, r ), "Value" ), nif->get( QModelIndex_child( iTags, r ), "Time" ) ); } scene->animTags[name] = tags; @@ -107,7 +108,7 @@ void ControllerManager::setSequence( const QString & seqname ) QModelIndex iCtrlBlcks = nif->getIndex( iSeq, "Controlled Blocks" ); for ( int r = 0; r < nif->rowCount( iCtrlBlcks ); r++ ) { - QModelIndex iCB = iCtrlBlcks.child( r, 0 ); + QModelIndex iCB = QModelIndex_child( iCtrlBlcks, r ); QModelIndex iInterp = nif->getBlockIndex( nif->getLink( iCB, "Interpolator" ), "NiInterpolator" ); @@ -321,9 +322,11 @@ bool MultiTargetTransformController::update( const NifModel * nif, const QModelI return true; } +#if 0 for ( const TransformTarget& tt : extraTargets ) { // TODO: update the interpolators } +#endif return false; } @@ -457,16 +460,16 @@ bool MorphController::update( const NifModel * nif, const QModelIndex & index ) iInterpolatorWeights = nif->getIndex( iBlock, "Interpolator Weights" ); } - QModelIndex iKey = midx.child( r, 0 ); + QModelIndex iKey = QModelIndex_child( midx, r ); MorphKey * key = new MorphKey; key->index = 0; // this is ugly... if ( iInterpolators.isValid() ) { - key->iFrames = nif->getIndex( nif->getBlockIndex( nif->getLink( nif->getBlockIndex( nif->getLink( iInterpolators.child( r, 0 ) ), "NiFloatInterpolator" ), "Data" ), "NiFloatData" ), "Data" ); + key->iFrames = nif->getIndex( nif->getBlockIndex( nif->getLink( nif->getBlockIndex( nif->getLink( QModelIndex_child( iInterpolators, r ) ), "NiFloatInterpolator" ), "Data" ), "NiFloatData" ), "Data" ); } else if ( iInterpolatorWeights.isValid() ) { - key->iFrames = nif->getIndex( nif->getBlockIndex( nif->getLink( nif->getBlockIndex( nif->getLink( iInterpolatorWeights.child( r, 0 ), "Interpolator" ), "NiFloatInterpolator" ), "Data" ), "NiFloatData" ), "Data" ); + key->iFrames = nif->getIndex( nif->getBlockIndex( nif->getLink( nif->getBlockIndex( nif->getLink( QModelIndex_child( iInterpolatorWeights, r ), "Interpolator" ), "NiFloatInterpolator" ), "Data" ), "NiFloatData" ), "Data" ); } else { key->iFrames = iKey; } @@ -505,7 +508,7 @@ void UVController::updateTime( float time ) if ( uvGroups.isValid() ) { for ( int i = 0; i < 4 && i < nif->rowCount( uvGroups ); i++ ) { - interpolate( val[i], uvGroups.child( i, 0 ), ctrlTime( time ), luv ); + interpolate( val[i], QModelIndex_child( uvGroups, i ), ctrlTime( time ), luv ); } // adjust coords; verified in SceneImmerse @@ -600,11 +603,11 @@ bool ParticleController::update( const NifModel * nif, const QModelIndex & index //{ for ( int p = 0; p < numValid && p < nif->rowCount( iParticles ); p++ ) { Particle particle; - particle.velocity = nif->get( iParticles.child( p, 0 ), "Velocity" ); - particle.lifetime = nif->get( iParticles.child( p, 0 ), "Age" ); - particle.lifespan = nif->get( iParticles.child( p, 0 ), "Life Span" ); - particle.lasttime = nif->get( iParticles.child( p, 0 ), "Last Update" ); - particle.vertex = nif->get( iParticles.child( p, 0 ), "Code" ); + particle.velocity = nif->get( QModelIndex_child( iParticles, p ), "Velocity" ); + particle.lifetime = nif->get( QModelIndex_child( iParticles, p ), "Age" ); + particle.lifespan = nif->get( QModelIndex_child( iParticles, p ), "Life Span" ); + particle.lasttime = nif->get( QModelIndex_child( iParticles, p ), "Last Update" ); + particle.vertex = nif->get( QModelIndex_child( iParticles, p ), "Code" ); // Display saved particle start on initial load list.append( particle ); } @@ -889,9 +892,9 @@ void TexFlipController::updateTime( float time ) // TexturingProperty if ( target ) { - target->textures[flipSlot & 7].iSource = nif->getBlockIndex( nif->getLink( iSources.child( (int)r, 0 ) ), "NiSourceTexture" ); + target->textures[flipSlot & 7].iSource = nif->getBlockIndex( nif->getLink( QModelIndex_child( iSources, int(r) ) ), "NiSourceTexture" ); } else if ( oldTarget ) { - oldTarget->iImage = nif->getBlockIndex( nif->getLink( iSources.child( (int)r, 0 ) ), "NiImage" ); + oldTarget->iImage = nif->getBlockIndex( nif->getLink( QModelIndex_child( iSources, int(r) ) ), "NiImage" ); } } diff --git a/src/gl/glcontroller.cpp b/src/gl/glcontroller.cpp index 9a80c771..d001dfe2 100644 --- a/src/gl/glcontroller.cpp +++ b/src/gl/glcontroller.cpp @@ -35,6 +35,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "gl/glscene.h" #include "model/nifmodel.h" +#include "gamemanager.h" //! @file glcontroller.cpp Controllable management, Interpolation management @@ -302,14 +303,14 @@ bool Controller::timeIndex( float time, const NifModel * nif, const QModelIndex int count; if ( array.isValid() && ( count = nif->rowCount( array ) ) > 0 ) { - if ( time <= nif->get( array.child( 0, 0 ), "Time" ) ) { + if ( time <= nif->get( QModelIndex_child( array ), "Time" ) ) { i = j = 0; x = 0.0; return true; } - if ( time >= nif->get( array.child( count - 1, 0 ), "Time" ) ) { + if ( time >= nif->get( QModelIndex_child( array, count - 1 ), "Time" ) ) { i = j = count - 1; x = 0.0; @@ -319,13 +320,13 @@ bool Controller::timeIndex( float time, const NifModel * nif, const QModelIndex if ( i < 0 || i >= count ) i = 0; - float tI = nif->get( array.child( i, 0 ), "Time" ); + float tI = nif->get( QModelIndex_child( array, i ), "Time" ); if ( time > tI ) { j = i + 1; float tJ; - while ( time >= ( tJ = nif->get( array.child( j, 0 ), "Time" ) ) ) { + while ( time >= ( tJ = nif->get( QModelIndex_child( array, j ), "Time" ) ) ) { i = j++; tI = tJ; } @@ -337,7 +338,7 @@ bool Controller::timeIndex( float time, const NifModel * nif, const QModelIndex j = i - 1; float tJ; - while ( time <= ( tJ = nif->get( array.child( j, 0 ), "Time" ) ) ) { + while ( time <= ( tJ = nif->get( QModelIndex_child( array, j ), "Time" ) ) ) { i = j--; tI = tJ; } @@ -350,7 +351,7 @@ bool Controller::timeIndex( float time, const NifModel * nif, const QModelIndex // Previously, this branch was causing x to decrement from 1.0. // (This works fine for linear interpolation apparently) x = 1.0 - x; - + // Swap I and J // With x inverted, we must swap I and J or the animation will reverse. auto tmpI = i; @@ -380,11 +381,11 @@ template bool interpolate( T & value, const QModelIndex & array, fl float x; if ( Controller::timeIndex( time, nif, frames, last, next, x ) ) { - T v1 = nif->get( frames.child( last, 0 ), "Value" ); - T v2 = nif->get( frames.child( next, 0 ), "Value" ); + T v1 = nif->get( QModelIndex_child( frames, last ), "Value" ); + T v2 = nif->get( QModelIndex_child( frames, next ), "Value" ); switch ( nif->get( array, "Interpolation" ) ) { - + case 2: { // Quadratic @@ -395,9 +396,9 @@ template bool interpolate( T & value, const QModelIndex & array, fl */ // Tangent 1 - T t1 = nif->get( frames.child( last, 0 ), "Backward" ); + T t1 = nif->get( QModelIndex_child( frames, last ), "Backward" ); // Tangent 2 - T t2 = nif->get( frames.child( next, 0 ), "Forward" ); + T t2 = nif->get( QModelIndex_child( frames, next ), "Forward" ); float x2 = x * x; float x3 = x2 * x; @@ -408,7 +409,7 @@ template bool interpolate( T & value, const QModelIndex & array, fl value = v1 * (2.0f * x3 - 3.0f * x2 + 1.0f) + v2 * (-2.0f * x3 + 3.0f * x2) + t1 * (x3 - 2.0f * x2 + x) + t2 * (x3 - x2); } return true; - + case 5: // Constant if ( x < 0.5 ) @@ -457,7 +458,7 @@ template <> bool Controller::interpolate( bool & value, const QModelIndex & arra QModelIndex frames = nif->getIndex( array, "Keys" ); if ( timeIndex( time, nif, frames, last, next, x ) ) { - value = nif->get( frames.child( last, 0 ), "Value" ); + value = nif->get( QModelIndex_child( frames, last ), "Value" ); return true; } @@ -470,7 +471,7 @@ template <> bool Controller::interpolate( Matrix & value, const QModelIndex & ar { int next; float x; - + auto nif = NifModel::fromValidIndex(array); if ( nif ) { switch ( nif->get( array, "Rotation Type" ) ) { @@ -483,7 +484,7 @@ template <> bool Controller::interpolate( Matrix & value, const QModelIndex & ar for ( int s = 0; s < 3 && s < nif->rowCount( subkeys ); s++ ) { r[s] = 0; - interpolate( r[s], subkeys.child( s, 0 ), time, last ); + interpolate( r[s], QModelIndex_child( subkeys, s ), time, last ); } value = Matrix::euler( 0, 0, r[2] ) * Matrix::euler( 0, r[1], 0 ) * Matrix::euler( r[0], 0, 0 ); @@ -497,8 +498,8 @@ template <> bool Controller::interpolate( Matrix & value, const QModelIndex & ar QModelIndex frames = nif->getIndex( array, "Quaternion Keys" ); if ( timeIndex( time, nif, frames, last, next, x ) ) { - Quat v1 = nif->get( frames.child( last, 0 ), "Value" ); - Quat v2 = nif->get( frames.child( next, 0 ), "Value" ); + Quat v1 = nif->get( QModelIndex_child( frames, last ), "Value" ); + Quat v2 = nif->get( QModelIndex_child( frames, next ), "Value" ); if ( Quat::dotproduct( v1, v2 ) < 0 ) v1.negate(); // don't take the long path @@ -554,7 +555,7 @@ struct qarray T operator[]( uint index ) const { - return nif_->get( array_.child( index + off_, 0 ) ); + return nif_->get( QModelIndex_child( array_, index + off_ ) ); } const NifModel * nif_; const QModelIndex & array_; diff --git a/src/gl/glnode.cpp b/src/gl/glnode.cpp index 7335e6b2..2dd923cb 100644 --- a/src/gl/glnode.cpp +++ b/src/gl/glnode.cpp @@ -48,6 +48,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // std::stable_sort +#include "gamemanager.h" //! @file glnode.cpp Scene management for visible NiNodes and their children. @@ -302,7 +303,7 @@ void Node::updateImpl( const NifModel * nif, const QModelIndex & index ) if ( nChildren > 0 ) { QList lChildren = nif->getChildLinks( nodeId ); for ( int c = 0; c < nChildren; c++ ) { - qint32 link = nif->getLink( iChildren.child( c, 0 ) ); + qint32 link = nif->getLink( QModelIndex_child( iChildren, c ) ); if ( lChildren.contains( link ) ) { QModelIndex iChild = nif->getBlockIndex( link ); @@ -617,7 +618,7 @@ void Node::drawSelection() const int ct = nif->rowCount( cp ); for ( int i = 0; i < ct; i++ ) { - auto p = cp.child( i, 0 ); + auto p = QModelIndex_child( cp, i ); auto trans = nif->get( p, "Translation" ); auto rot = nif->get( p, "Rotation" ); @@ -761,7 +762,7 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackrowCount( iShapes ); r++ ) { if ( !Node::SELECTING ) { - if ( scene->currentBlock == nif->getBlockIndex( nif->getLink( iShapes.child( r, 0 ) ) ) ) { + if ( scene->currentBlock == nif->getBlockIndex( nif->getLink( QModelIndex_child( iShapes, r ) ) ) ) { // fix: add selected visual to havok meshes glHighlightColor(); glLineWidth( 2.5 ); @@ -774,7 +775,7 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackgetBlockIndex( nif->getLink( iShapes.child( r, 0 ) ) ), stack, scene, origin_color3fv ); + drawHvkShape( nif, nif->getBlockIndex( nif->getLink( QModelIndex_child( iShapes, r ) ) ), stack, scene, origin_color3fv ); } } } else if ( name == "bhkTransformShape" || name == "bhkConvexTransformShape" ) { @@ -804,7 +805,7 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackgetIndex( iShape, "Spheres" ); for ( int r = 0; r < nif->rowCount( iSpheres ); r++ ) { - drawSphere( nif->get( iSpheres.child( r, 0 ), "Center" ), nif->get( iSpheres.child( r, 0 ), "Radius" ) ); + drawSphere( nif->get( QModelIndex_child( iSpheres, r ), "Center" ), nif->get( QModelIndex_child( iSpheres, r ), "Radius" ) ); } } else if ( name == "bhkBoxShape" ) { if ( Node::SELECTING ) { @@ -884,7 +885,7 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackgetIndex( iData, "Triangles" ); for ( int t = 0; t < nif->rowCount( iTris ); t++ ) { - Triangle tri = nif->get( iTris.child( t, 0 ), "Triangle" ); + Triangle tri = nif->get( QModelIndex_child( iTris, t ), "Triangle" ); if ( tri[0] != tri[1] || tri[1] != tri[2] || tri[2] != tri[0] ) { glBegin( GL_LINE_STRIP ); @@ -915,9 +916,9 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackrowCount( iTris ); t++ ) - // DrawTriangleIndex( verts, nif->get( iTris.child( t, 0 ), "Triangle" ), t ); + // DrawTriangleIndex( verts, nif->get( QModelIndex_child( iTris, t ), "Triangle" ), t ); } else if ( nif->isCompound( nif->itemStrType( scene->currentIndex ) ) ) { - Triangle tri = nif->get( iTris.child( i, 0 ), "Triangle" ); + Triangle tri = nif->get( QModelIndex_child( iTris, i ), "Triangle" ); DrawTriangleSelection( verts, tri ); //DrawTriangleIndex( verts, tri, i ); } else if ( nif->itemName( scene->currentIndex ) == "Normal" ) { @@ -936,22 +937,19 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackget( scene->currentIndex, "Num Vertices" ); - int ct = nif->rowCount( iTris ); int totalVerts = 0; if ( num_vertices > 0 ) { QModelIndex iParent = scene->currentIndex.parent(); for ( int j = 0; j < i; j++ ) { - totalVerts += nif->get( iParent.child( j, 0 ), "Num Vertices" ); + totalVerts += nif->get( QModelIndex_child( iParent, j ), "Num Vertices" ); } end_vertex += totalVerts + num_vertices; start_vertex += totalVerts; - - ct = (end_vertex - start_vertex) / 3; } for ( int t = 0; t < nif->rowCount( iTris ); t++ ) { - Triangle tri = nif->get( iTris.child( t, 0 ), "Triangle" ); + Triangle tri = nif->get( QModelIndex_child( iTris, t ), "Triangle" ); if ( (start_vertex <= tri[0]) && (tri[0] < end_vertex) ) { if ( (start_vertex <= tri[1]) && (tri[1] < end_vertex) && (start_vertex <= tri[2]) && (tri[2] < end_vertex) ) { @@ -966,13 +964,11 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackcurrentBlock == iShape ) { - int i = -1; QString n = scene->currentIndex.data( NifSkopeDisplayRole ).toString(); QModelIndex iParent = scene->currentIndex.parent(); if ( iParent.isValid() && iParent != iShape ) { n = iParent.data( NifSkopeDisplayRole ).toString(); - i = scene->currentIndex.row(); } //qDebug() << n; @@ -986,7 +982,7 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackrowCount( iSubShapes ); subshape++ ) { - QModelIndex iCurrentSubShape = iSubShapes.child( subshape, 0 ); + QModelIndex iCurrentSubShape = QModelIndex_child( iSubShapes, subshape ); int num_vertices = nif->get( iCurrentSubShape, "Num Vertices" ); //qDebug() << num_vertices; end_vertex += num_vertices; @@ -1000,7 +996,7 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStackrowCount( iTris ); t++ ) { - Triangle tri = nif->get( iTris.child( t, 0 ), "Triangle" ); + Triangle tri = nif->get( QModelIndex_child( iTris, t ), "Triangle" ); if ( (start_vertex <= tri[0]) && (tri[0] < end_vertex) ) { if ( (start_vertex <= tri[1]) && (tri[1] < end_vertex) && (start_vertex <= tri[2]) && (tri[2] < end_vertex) ) { @@ -1427,7 +1423,7 @@ void Node::drawHavok() t.translation = center; glMultMatrix( t ); } - + if ( Node::SELECTING ) { int s_nodeId = ID2COLORKEY( nif->getBlockNumber( iBSMultiBoundData ) ); glColor4ubv( (GLubyte *)&s_nodeId ); @@ -1448,7 +1444,7 @@ void Node::drawHavok() if ( iExtraDataList.isValid() ) { for ( int d = 0; d < nif->rowCount( iExtraDataList ); d++ ) { - QModelIndex iBound = nif->getBlockIndex( nif->getLink( iExtraDataList.child( d, 0 ) ), "BSBound" ); + QModelIndex iBound = nif->getBlockIndex( nif->getLink( QModelIndex_child( iExtraDataList, d ) ), "BSBound" ); if ( !iBound.isValid() ) continue; @@ -1781,7 +1777,7 @@ void Node::drawFurn() for ( int p = 0; p < nif->rowCount( iExtraDataList ); p++ ) { // DONE: never seen Furn in nifs, so there may be a need of a fix here later - saw one, fixed a bug - QModelIndex iFurnMark = nif->getBlockIndex( nif->getLink( iExtraDataList.child( p, 0 ) ), "BSFurnitureMarker" ); + QModelIndex iFurnMark = nif->getBlockIndex( nif->getLink( QModelIndex_child( iExtraDataList, p ) ), "BSFurnitureMarker" ); if ( !iFurnMark.isValid() ) continue; @@ -1792,7 +1788,7 @@ void Node::drawFurn() break; for ( int j = 0; j < nif->rowCount( iPositions ); j++ ) { - QModelIndex iPosition = iPositions.child( j, 0 ); + QModelIndex iPosition = QModelIndex_child( iPositions, j ); if ( scene->currentIndex == iPosition ) glHighlightColor(); @@ -1812,7 +1808,7 @@ void Node::drawShapes( NodeList * secondPass, bool presort ) return; auto nif = NifModel::fromIndex( iBlock ); - + // BSOrderedNode support // Only set if true (|=) so that it propagates to all children presort |= nif->getBlockIndex( iBlock, "BSOrderedNode" ).isValid(); @@ -1874,7 +1870,7 @@ BoundSphere Node::bounds() const if ( iExtraDataList.isValid() ) { for ( int d = 0; d < nif->rowCount( iExtraDataList ); d++ ) { - QModelIndex iBound = nif->getBlockIndex( nif->getLink( iExtraDataList.child( d, 0 ) ), "BSBound" ); + QModelIndex iBound = nif->getBlockIndex( nif->getLink( QModelIndex_child( iExtraDataList, d ) ), "BSBound" ); if ( !iBound.isValid() ) continue; @@ -1919,8 +1915,8 @@ void LODNode::updateImpl( const NifModel * nif, const QModelIndex & index ) if ( iLevels.isValid() ) { for ( int r = 0; r < nif->rowCount( iLevels ); r++ ) { - ranges.append( { nif->get( iLevels.child( r, 0 ), "Near Extent" ), - nif->get( iLevels.child( r, 0 ), "Far Extent" ) } + ranges.append( { nif->get( QModelIndex_child( iLevels, r ), "Near Extent" ), + nif->get( QModelIndex_child( iLevels, r ), "Far Extent" ) } ); } } diff --git a/src/gl/glproperty.cpp b/src/gl/glproperty.cpp index 18594f73..8191767c 100644 --- a/src/gl/glproperty.cpp +++ b/src/gl/glproperty.cpp @@ -155,7 +155,7 @@ void PropertyList::del( Property * p ) if ( !p ) return; - QHash::iterator i = properties.find( p->type() ); + QMultiHash::iterator i = properties.find( p->type() ); while ( p && i != properties.end() && i.key() == p->type() ) { if ( i.value() == p ) { diff --git a/src/gl/gltools.cpp b/src/gl/gltools.cpp index d4ae5d52..34fa5b46 100644 --- a/src/gl/gltools.cpp +++ b/src/gl/gltools.cpp @@ -43,6 +43,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include "gamemanager.h" //! \file gltools.cpp GL helper functions @@ -57,7 +58,7 @@ BoneWeights::BoneWeights( const NifModel * nif, const QModelIndex & index, int b QModelIndex idxWeights = nif->getIndex( index, "Vertex Weights" ); if ( vcnt && idxWeights.isValid() ) { for ( int c = 0; c < nif->rowCount( idxWeights ); c++ ) { - QModelIndex idx = idxWeights.child( c, 0 ); + QModelIndex idx = QModelIndex_child( idxWeights, c ); weights.append( VertexWeight( nif->get( idx, "Index" ), nif->get( idx, "Weight" ) ) ); } } @@ -71,7 +72,7 @@ void BoneWeights::setTransform( const NifModel * nif, const QModelIndex & index radius = sph.radius; } -BoneWeightsUNorm::BoneWeightsUNorm(QVector> weights, int v) +BoneWeightsUNorm::BoneWeightsUNorm( QVector> weights, [[maybe_unused]] int v ) { weightsUNORM.resize(weights.size()); for ( int i = 0; i < weights.size(); i++ ) { @@ -102,8 +103,8 @@ SkinPartition::SkinPartition( const NifModel * nif, const QModelIndex & index ) for ( int v = 0; v < vertexMap.count(); v++ ) { for ( int w = 0; w < numWeightsPerVertex; w++ ) { - QModelIndex iw = iWeights.child( v, 0 ).child( w, 0 ); - QModelIndex ib = iBoneIndices.child( v, 0 ).child( w, 0 ); + QModelIndex iw = QModelIndex_child( QModelIndex_child( iWeights, v ), w ); + QModelIndex ib = QModelIndex_child( QModelIndex_child( iBoneIndices, v ), w ); weights[ v * numWeightsPerVertex + w ].first = ( ib.isValid() ? nif->get( ib ) : 0 ); weights[ v * numWeightsPerVertex + w ].second = ( iw.isValid() ? nif->get( iw ) : 0 ); @@ -113,7 +114,7 @@ SkinPartition::SkinPartition( const NifModel * nif, const QModelIndex & index ) QModelIndex iStrips = nif->getIndex( index, "Strips" ); for ( int s = 0; s < nif->rowCount( iStrips ); s++ ) { - tristrips << nif->getArray( iStrips.child( s, 0 ) ); + tristrips << nif->getArray( QModelIndex_child( iStrips, s ) ); } triangles = nif->getArray( index, "Triangles" ); @@ -374,7 +375,7 @@ QModelIndex bhkGetEntity( const NifModel * nif, const QModelIndex & index, const return {}; } - return iEntity; + return iEntity; } QModelIndex bhkGetRBInfo( const NifModel * nif, const QModelIndex & index, const QString & name ) @@ -405,7 +406,7 @@ QModelIndex bhkGetRBInfo( const NifModel * nif, const QModelIndex & index, const y = 1; } - return{ x, y, z }; + return{ int(x), int(y), int(z) }; } void drawAxesOverlay( const Vector3 & c, float axis, QVector axesOrder ) @@ -958,7 +959,7 @@ void drawNiTSS( const NifModel * nif, const QModelIndex & iShape, bool solid ) { QModelIndex iStrips = nif->getIndex( iShape, "Strips Data" ); for ( int r = 0; r < nif->rowCount( iStrips ); r++ ) { - QModelIndex iStripData = nif->getBlockIndex( nif->getLink( iStrips.child( r, 0 ) ), "NiTriStripsData" ); + QModelIndex iStripData = nif->getBlockIndex( nif->getLink( QModelIndex_child( iStrips, r ) ), "NiTriStripsData" ); if ( iStripData.isValid() ) { QVector verts = nif->getArray( iStripData, "Vertices" ); @@ -969,7 +970,7 @@ void drawNiTSS( const NifModel * nif, const QModelIndex & iShape, bool solid ) QModelIndex iPoints = nif->getIndex( iStripData, "Points" ); for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) { // draw the strips like they appear in the tescs // (use the unstich strips spell to avoid the spider web effect) - QVector strip = nif->getArray( iPoints.child( r, 0 ) ); + QVector strip = nif->getArray( QModelIndex_child( iPoints, r ) ); if ( strip.count() >= 3 ) { quint16 a = strip[0]; quint16 b = strip[1]; @@ -1006,7 +1007,7 @@ void drawCMS( const NifModel * nif, const QModelIndex & iShape, bool solid ) glDisable( GL_CULL_FACE ); for ( int r = 0; r < nif->rowCount( iBigTris ); r++ ) { - Triangle tri = nif->get( iBigTris.child( r, 0 ), "Triangle" ); + Triangle tri = nif->get( QModelIndex_child( iBigTris, r ), "Triangle" ); glBegin( GL_TRIANGLES ); @@ -1026,9 +1027,9 @@ void drawCMS( const NifModel * nif, const QModelIndex & iShape, bool solid ) Vector4 chunkOrigin = nif->get( iChunk, "Translation" ); quint32 transformIndex = nif->get( iChunk, "Transform Index" ); - QModelIndex chunkTransform = iChunkTrans.child( transformIndex, 0 ); - Vector4 chunkTranslation = nif->get( chunkTransform.child( 0, 0 ) ); - Quat chunkRotation = nif->get( chunkTransform.child( 1, 0 ) ); + QModelIndex chunkTransform = QModelIndex_child( iChunkTrans, transformIndex ); + Vector4 chunkTranslation = nif->get( QModelIndex_child( chunkTransform ) ); + Quat chunkRotation = nif->get( QModelIndex_child( chunkTransform, 1 ) ); quint32 numOffsets = nif->get( iChunk, "Num Vertices" ) / 3; quint32 numIndices = nif->get( iChunk, "Num Indices" ); diff --git a/src/io/materialfile.cpp b/src/io/materialfile.cpp index ebdb26ed..d169899f 100644 --- a/src/io/materialfile.cpp +++ b/src/io/materialfile.cpp @@ -131,7 +131,7 @@ bool ShaderMaterial::readFile() Material::readFile(); size_t numTex = (version >= 17) ? 10 : 9; - for ( int i = 0; i < numTex; i++ ) { + for ( size_t i = 0; i < numTex; i++ ) { char * str; in >> str; textureList << QString( str ); @@ -220,7 +220,7 @@ bool EffectMaterial::readFile() Material::readFile(); size_t numTex = (version >= 10) ? 8 : 5; - for ( int i = 0; i < numTex; i++ ) { + for ( size_t i = 0; i < numTex; i++ ) { char * str; in >> str; textureList << QString( str ); @@ -246,7 +246,7 @@ bool EffectMaterial::readFile() if ( version >= 11 ) { in >> emitR >> emitG >> emitB; cEmittanceColor.setRGB( emitR, emitG, emitB ); - + if ( version >= 15 ) { in >> fAdaptativeEmissive_ExposureOffset >> fAdaptativeEmissive_FinalExposureMin >> fAdaptativeEmissive_FinalExposureMax; diff --git a/src/io/nifstream.cpp b/src/io/nifstream.cpp index d5d94a46..adb6c882 100644 --- a/src/io/nifstream.cpp +++ b/src/io/nifstream.cpp @@ -1059,6 +1059,7 @@ int NifSStream::size( const NifValue & val ) return 0; case NifValue::tNone: + default: return 0; } diff --git a/src/lib/importex/3ds.cpp b/src/lib/importex/3ds.cpp index 5d8aaa0f..ba209ec4 100644 --- a/src/lib/importex/3ds.cpp +++ b/src/lib/importex/3ds.cpp @@ -20,8 +20,9 @@ #include #include -#define tr( x ) QCoreApplication::tr( "3dsImport", x ) +#include "gamemanager.h" +#define tr( x ) QCoreApplication::tr( "3dsImport", x ) struct objPoint { @@ -106,7 +107,7 @@ static void addLink( NifModel * nif, const QModelIndex & iBlock, const QString & int numIndices = nif->get( iSize ); nif->set( iSize, numIndices + 1 ); nif->updateArraySize( iArray ); - nif->setLink( iArray.child( numIndices, 0 ), link ); + nif->setLink( QModelIndex_child( iArray, numIndices ), link ); } static Color3 GetColorFromChunk( Chunk * cnk ) @@ -244,7 +245,7 @@ void import3ds( NifModel * nif, const QModelIndex & index ) float ObjScale; QVector ObjMeshes; QMap ObjMaterials; - QMap ObjKeyframes; + QMultiMap ObjKeyframes; QSettings settings; settings.beginGroup( "Import-Export" ); @@ -559,7 +560,7 @@ void import3ds( NifModel * nif, const QModelIndex & index ) } } - ObjKeyframes.insertMulti( newKfSeq.objectName, newKfSeq ); + ObjKeyframes.insert( newKfSeq.objectName, newKfSeq ); } } @@ -712,8 +713,8 @@ void import3ds( NifModel * nif, const QModelIndex & index ) nif->set( iData, "Data Flags", 1 ); QModelIndex iTexCo = nif->getIndex( iData, "UV Sets" ); nif->updateArraySize( iTexCo ); - nif->updateArraySize( iTexCo.child( 0, 0 ) ); - nif->setArray( iTexCo.child( 0, 0 ), mesh->texcoords ); + nif->updateArraySize( QModelIndex_child( iTexCo ) ); + nif->setArray( QModelIndex_child( iTexCo ), mesh->texcoords ); nif->set( iData, "Has Triangles", 1 ); nif->set( iData, "Num Triangles", triangles.count() ); diff --git a/src/lib/importex/3ds.h b/src/lib/importex/3ds.h index 7389782d..9910f0f6 100644 --- a/src/lib/importex/3ds.h +++ b/src/lib/importex/3ds.h @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -223,7 +223,7 @@ class Chunk Chunk * getChild( ChunkType ct ) { - return c[ct]; + return c.value( ct ); } void reset() @@ -275,7 +275,7 @@ class Chunk ChunkDataLength dl; ChunkDataCount dc; - QMap c; + QMultiMap c; void subproc() { @@ -476,9 +476,9 @@ class Chunk { f->seek( p + CHUNKHEADERSIZE + dl ); - QMap temp; + QMultiMap temp; - while ( f->pos() < ( p + h.l ) ) { + while ( f->pos() < ( qint64(p) + qint64(h.l) ) ) { ChunkPos q = f->pos(); ChunkHeader k; @@ -487,7 +487,7 @@ class Chunk Chunk * z = new Chunk( f, k, q ); - temp.insertMulti( k.t, z ); + temp.insert( k.t, z ); f->seek( q + k.l ); } @@ -496,7 +496,7 @@ class Chunk while ( tempIter.hasNext() ) { tempIter.next(); - c.insertMulti( tempIter.key(), tempIter.value() ); + c.insert( tempIter.key(), tempIter.value() ); } f->seek( p + h.l ); diff --git a/src/lib/importex/col.cpp b/src/lib/importex/col.cpp index 5d465c58..2d176411 100644 --- a/src/lib/importex/col.cpp +++ b/src/lib/importex/col.cpp @@ -48,8 +48,9 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#define tr( x ) QApplication::tr( x ) +#include "gamemanager.h" +#define tr( x ) QApplication::tr( x ) /** * TODO LIST: @@ -531,7 +532,7 @@ QDomElement textureElement( const NifModel * nif, QDomElement effect, QModelInde if ( iTexture.isValid() ) { // we have texture - QFileInfo textureFile = nif->get( iTexture, "File Name" ); + QFileInfo textureFile( nif->get( iTexture, "File Name" ) ); // surface QDomElement newparam = doc.createElement( "newparam" ); @@ -771,7 +772,7 @@ void attachNiShape ( const NifModel * nif, QDomElement parentNode, int idx ) QModelIndex iUV = nif->getIndex( iProp, "UV Sets" ); for ( int row = 0; row < uvCount; row++ ) { - QVector uvMap = nif->getArray( iUV.child( row, 0 ) ); + QVector uvMap = nif->getArray( QModelIndex_child( iUV, row ) ); mesh.appendChild( uvMapElement( uvMap, idx, row ) ); if ( uvMap.size() > 0 ) @@ -846,7 +847,7 @@ void attachNiShape ( const NifModel * nif, QDomElement parentNode, int idx ) QVector > strips; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) - strips.append( nif->getArray( iPoints.child( r, 0 ) ) ); + strips.append( nif->getArray( QModelIndex_child( iPoints, r ) ) ); tri = triangulate( strips ); } else { @@ -961,7 +962,7 @@ void attachNiNode ( const NifModel * nif, QDomElement parentNode, int idx ) } } -void exportCol( const NifModel * nif, const Scene* scene, QFileInfo fileInfo ) +void exportCol( const NifModel * nif, [[maybe_unused]] const Scene* scene, QFileInfo fileInfo ) { //culling = Options::get()->exportCullEnabled(); //cullRegExp = Options::get()->cullExpression(); diff --git a/src/main.cpp b/src/main.cpp index 0237605e..1e0fef1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. QCoreApplication * createApplication( int &argc, char *argv[] ) { - QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + QApplication::setAttribute( Qt::AA_UseDesktopOpenGL ); // Iterate over args for ( int i = 1; i < argc; ++i ) { // -no-gui: start as core app without all the GUI overhead @@ -87,7 +87,9 @@ int main( int argc, char * argv[] ) // Register types qRegisterMetaType( "NifValue" ); +#if 0 QMetaType::registerComparators(); +#endif // Set locale QSettings cfg( QString( "%1/nifskope.ini" ).arg( QCoreApplication::applicationDirPath() ), QSettings::IniFormat ); @@ -100,7 +102,7 @@ int main( int argc, char * argv[] ) KfmModel::loadXML(); // Init game manager - auto mgr = Game::GameManager::get(); + (void) Game::GameManager::get(); int port = NIFSKOPE_IPC_PORT; diff --git a/src/model/kfmmodel.cpp b/src/model/kfmmodel.cpp index 27f05f75..137a1792 100644 --- a/src/model/kfmmodel.cpp +++ b/src/model/kfmmodel.cpp @@ -230,7 +230,7 @@ void KfmModel::insertType( NifItem * parent, const NifData & data, int at ) * load and save */ -bool KfmModel::setHeaderString( const QString & s, uint ver ) +bool KfmModel::setHeaderString( const QString & s, [[maybe_unused]] uint ver ) { if ( s.startsWith( ";Gamebryo KFM File Version " ) ) { version = version2number( s.right( s.length() - 27 ) ); diff --git a/src/model/nifdelegate.cpp b/src/model/nifdelegate.cpp index bc77d778..07f10281 100644 --- a/src/model/nifdelegate.cpp +++ b/src/model/nifdelegate.cpp @@ -166,7 +166,7 @@ class NifDelegate final : public QItemDelegate // Color the field background if the value type is a color // Otherwise normal behavior - QVariant color = index.data( Qt::BackgroundColorRole ); + QVariant color = index.data( Qt::BackgroundRole ); if ( color.canConvert() ) painter->fillRect( option.rect, color.value() ); else if ( option.state & QStyle::State_Selected ) @@ -196,7 +196,7 @@ class NifDelegate final : public QItemDelegate // Increase height by 25% height *= 1.25; - return {option.fontMetrics.width( text ), height}; + return {option.fontMetrics.horizontalAdvance( text ), int( height )}; } QWidget * createEditor( QWidget * parent, const QStyleOptionViewItem &, const QModelIndex & index ) const override final @@ -274,7 +274,7 @@ class NifDelegate final : public QItemDelegate } else { cedit->setCurrentIndex( cedit->findText( NifValue::enumOptionName( t, value ) ) ); } - + } else if ( ledit ) { ledit->setText( v.toString() ); diff --git a/src/model/nifmodel.cpp b/src/model/nifmodel.cpp index 06d43e3a..0d507395 100644 --- a/src/model/nifmodel.cpp +++ b/src/model/nifmodel.cpp @@ -1325,7 +1325,7 @@ QVariant NifModel::data( const QModelIndex & index, int role ) const auto block = root->child( link + firstBlockRow() ); if ( !block ) - return tr( "%1 " ).arg( link ); + return tr( "%1 <\?\?\?>" ).arg( link ); QString blockName = get( block, "Name" ); if ( !blockName.isEmpty() ) diff --git a/src/model/nifmodel.h b/src/model/nifmodel.h index cb07fa1f..d422c434 100644 --- a/src/model/nifmodel.h +++ b/src/model/nifmodel.h @@ -903,7 +903,7 @@ inline const NifItem * NifModel::getBlockItem( qint32 link, const QLatin1String } inline const NifItem * NifModel::getBlockItem( qint32 link, const char * ancestor ) const { - return _getBlockItem( getBlockItem(link), QLatin1Literal(ancestor) ); + return _getBlockItem( getBlockItem(link), QLatin1String(ancestor) ); } inline const NifItem * NifModel::getBlockItem( qint32 link, const std::initializer_list & ancestors ) const { diff --git a/src/model/nifproxymodel.cpp b/src/model/nifproxymodel.cpp index 1cb73621..b3c53804 100644 --- a/src/model/nifproxymodel.cpp +++ b/src/model/nifproxymodel.cpp @@ -485,7 +485,7 @@ QList NifProxyModel::mapFrom( const QModelIndex & idx ) const Qt::ItemFlags NifProxyModel::flags( const QModelIndex & index ) const { if ( !nif ) - return 0; + return Qt::NoItemFlags; return nif->flags( mapTo( index ) ); } diff --git a/src/nifskope.cpp b/src/nifskope.cpp index 7758bd5b..5b61b881 100644 --- a/src/nifskope.cpp +++ b/src/nifskope.cpp @@ -50,6 +50,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "gamemanager.h" #include +#include #include #include #include @@ -562,7 +563,7 @@ QString strippedName( const QString & fullFileName ) int updateRecentActions( QAction * acts[], const QStringList & files ) { - int numRecentFiles = std::min( files.size(), (int)NifSkope::NumRecentFiles ); + int numRecentFiles = std::min< qsizetype >( files.size(), NifSkope::NumRecentFiles ); for ( int i = 0; i < numRecentFiles; ++i ) { QString text = QString( "&%1 %2" ).arg( i + 1 ).arg( strippedName( files[i] ) ); @@ -789,7 +790,7 @@ void NifSkope::openArchive( const QString & archive ) { // Clear memory from previously opened archives bsaModel->clear(); - bsaProxyModel->clear(); + bsaProxyModel->invalidate(); bsaProxyModel->setSourceModel( emptyModel ); bsaView->setModel( emptyModel ); bsaView->setSortingEnabled( false ); @@ -1159,7 +1160,7 @@ void NifSkope::SetAppLocale( QLocale curLocale ) qApp->installTranslator( mTranslator ); } - mTranslator->load( fileName ); + (void) mTranslator->load( fileName ); } QLocale::setDefault( QLocale::C ); @@ -1171,7 +1172,7 @@ void NifSkope::sltLocaleChanged() QMessageBox mb( "NifSkope", tr( "NifSkope must be restarted for this setting to take full effect." ), - QMessageBox::Information, QMessageBox::Ok + QMessageBox::Default, 0, 0, + QMessageBox::Information, QMessageBox::Ok | QMessageBox::Default, 0, 0, qApp->activeWindow() ); mb.setIconPixmap( QPixmap( ":/res/nifskope.png" ) ); diff --git a/src/nifskope.h b/src/nifskope.h index 2b265898..760cc067 100644 --- a/src/nifskope.h +++ b/src/nifskope.h @@ -78,7 +78,6 @@ class QActionGroup; class QComboBox; class QGraphicsScene; class QProgressBar; -class QStringList; class QTimer; class QTreeView; class QUdpSocket; diff --git a/src/nifskope_ui.cpp b/src/nifskope_ui.cpp index 86e71d7d..dfdc7548 100644 --- a/src/nifskope_ui.cpp +++ b/src/nifskope_ui.cpp @@ -144,12 +144,15 @@ void NifSkope::initActions() aSelectFont = ui->aSelectFont; // Build all actions list - allActions = QSet::fromList( - ui->tFile->actions() - << ui->mRender->actions() - << ui->tRender->actions() - << ui->tAnim->actions() - ); + allActions = QSet(); + for ( auto i : ui->tFile->actions() ) + allActions.insert( i ); + for ( auto i : ui->mRender->actions() ) + allActions.insert( i ); + for ( auto i : ui->tRender->actions() ) + allActions.insert( i ); + for ( auto i : ui->tAnim->actions() ) + allActions.insert( i ); // Undo/Redo undoAction = nif->undoStack->createUndoAction( this, tr( "&Undo" ) ); @@ -820,7 +823,7 @@ void NifSkope::onLoadComplete( bool success, QString & fname ) header->setRootIndex( nif->getHeaderIndex() ); // Refresh the header rows - header->updateConditions( nif->getHeaderIndex().child( 0, 0 ), nif->getHeaderIndex().child( 20, 0 ) ); + header->updateConditions( QModelIndex_child( nif->getHeaderIndex() ), QModelIndex_child( nif->getHeaderIndex(), 20 ) ); ogl->setOrientation( GLView::ViewFront ); @@ -1025,13 +1028,13 @@ void NifSkope::setViewFont( const QFont & font ) { list->setFont( font ); QFontMetrics metrics( list->font() ); - list->setIconSize( QSize( metrics.width( "000" ), metrics.lineSpacing() ) ); + list->setIconSize( QSize( metrics.horizontalAdvance( "000" ), metrics.lineSpacing() ) ); tree->setFont( font ); - tree->setIconSize( QSize( metrics.width( "000" ), metrics.lineSpacing() ) ); + tree->setIconSize( QSize( metrics.horizontalAdvance( "000" ), metrics.lineSpacing() ) ); header->setFont( font ); - header->setIconSize( QSize( metrics.width( "000" ), metrics.lineSpacing() ) ); + header->setIconSize( QSize( metrics.horizontalAdvance( "000" ), metrics.lineSpacing() ) ); kfmtree->setFont( font ); - kfmtree->setIconSize( QSize( metrics.width( "000" ), metrics.lineSpacing() ) ); + kfmtree->setIconSize( QSize( metrics.horizontalAdvance( "000" ), metrics.lineSpacing() ) ); ogl->setFont( font ); } diff --git a/src/spellbook.cpp b/src/spellbook.cpp index 060964dc..1fca3d79 100644 --- a/src/spellbook.cpp +++ b/src/spellbook.cpp @@ -129,7 +129,7 @@ void SpellBook::cast( NifModel * nif, const QModelIndex & index, SpellPtr spell if ( accepted ) cfg.setValue( "Settings/Suppress Undoable Confirmation", true ); } - + if ( (response == QDialogButtonBox::Yes) && spell && spell->isApplicable( nif, index ) ) { bool noSignals = spell->batch(); if ( noSignals ) @@ -233,7 +233,7 @@ void SpellBook::newSpellRegistered( SpellPtr spell ) void SpellBook::registerSpell( SpellPtr spell ) { spells().append( spell ); - hash().insertMulti( spell->name(), spell ); + hash().insert( spell->name(), spell ); if ( spell->instant() ) instants().append( spell ); diff --git a/src/spells/animation.cpp b/src/spells/animation.cpp index 2b152ed2..0e746c5d 100644 --- a/src/spells/animation.cpp +++ b/src/spells/animation.cpp @@ -1,4 +1,5 @@ #include "spellbook.h" +#include "gamemanager.h" #include @@ -87,13 +88,13 @@ class spAttachKf final : public Spell QModelIndex iCtrlBlcks = kf.getIndex( iSeq, "Controlled Blocks" ); for ( int r = 0; r < kf.rowCount( iCtrlBlcks ); r++ ) { - QString nodeName = kf.resolveString( iCtrlBlcks.child( r, 0 ), "Node Name" ); + QString nodeName = kf.resolveString( QModelIndex_child( iCtrlBlcks, r ), "Node Name" ); if ( nodeName.isEmpty() ) - nodeName = kf.resolveString( iCtrlBlcks.child( r, 0 ), "Target Name" ); // 10.0.1.0 + nodeName = kf.resolveString( QModelIndex_child( iCtrlBlcks, r ), "Target Name" ); // 10.0.1.0 if ( nodeName.isEmpty() ) { - QModelIndex iNodeName = kf.getIndex( iCtrlBlcks.child( r, 0 ), "Node Name Offset" ); + QModelIndex iNodeName = kf.getIndex( QModelIndex_child( iCtrlBlcks, r ), "Node Name Offset" ); nodeName = iNodeName.sibling( iNodeName.row(), NifModel::ValueCol ).data( NifSkopeDisplayRole ).toString(); } @@ -140,14 +141,14 @@ class spAttachKf final : public Spell int numSeq = nif->get( iCtrlManager, "Num Controller Sequences" ); nif->set( iCtrlManager, "Num Controller Sequences", numSeq + 1 ); nif->updateArraySize( iCtrlManager, "Controller Sequences" ); - nif->setLink( nif->getIndex( iCtrlManager, "Controller Sequences" ).child( numSeq, 0 ), nSeq ); + nif->setLink( QModelIndex_child( nif->getIndex( iCtrlManager, "Controller Sequences" ), numSeq ), nSeq ); QModelIndex iSeq = nif->getBlockIndex( nSeq, "NiControllerSequence" ); nif->setLink( iSeq, "Manager", nif->getBlockNumber( iCtrlManager ) ); QModelIndex iCtrlBlcks = nif->getIndex( iSeq, "Controlled Blocks" ); for ( int r = 0; r < nif->rowCount( iCtrlBlcks ); r++ ) { - QModelIndex iCtrlBlck = iCtrlBlcks.child( r, 0 ); + QModelIndex iCtrlBlck = QModelIndex_child( iCtrlBlcks, r ); if ( nif->getLink( iCtrlBlck, "Controller" ) == -1 ) nif->setLink( iCtrlBlck, "Controller", iMultiTransformerIdx ); @@ -223,7 +224,7 @@ class spAttachKf final : public Spell return QModelIndex(); } - static QModelIndex attachController( NifModel * nif, const QPersistentModelIndex & iNode, const QString & ctrltype, bool fast = false ) + static QModelIndex attachController( NifModel * nif, const QPersistentModelIndex & iNode, const QString & ctrltype, [[maybe_unused]] bool fast = false ) { QModelIndex iCtrl = nif->insertNiBlock( ctrltype, nif->getBlockNumber( iNode ) + 1 ); @@ -249,7 +250,7 @@ class spAttachKf final : public Spell QVector links = nif->getLinkArray( iArray ); - for ( const QModelIndex& iBlock : iBlocks ) { + for ( const QPersistentModelIndex& iBlock : iBlocks ) { if ( !links.contains( nif->getBlockNumber( iBlock ) ) ) links.append( nif->getBlockNumber( iBlock ) ); } @@ -274,7 +275,7 @@ class spAttachKf final : public Spell int r; for ( r = 0; r < nif->rowCount( iArray ); r++ ) { - if ( nif->get( iArray.child( r, 0 ), "Name" ) == name ) + if ( nif->get( QModelIndex_child( iArray, r ), "Name" ) == name ) break; } @@ -286,8 +287,8 @@ class spAttachKf final : public Spell nif->set( iNum, r + blocksToAdd.count() ); nif->updateArraySize( iArray ); for ( const QPersistentModelIndex& idx : blocksToAdd ) { - nif->set( iArray.child( r, 0 ), "Name", nif->get( idx, "Name" ) ); - nif->setLink( iArray.child( r, 0 ), "AV Object", nif->getBlockNumber( idx ) ); + nif->set( QModelIndex_child( iArray, r ), "Name", nif->get( idx, "Name" ) ); + nif->setLink( QModelIndex_child( iArray, r ), "AV Object", nif->getBlockNumber( idx ) ); r++; } } @@ -327,7 +328,7 @@ class spConvertQuatsToEulers final : public Spell for( int i = 0; i < 3; i++ ) { - QModelIndex iRot = iRots.child( i, 0 ); + QModelIndex iRot = QModelIndex_child( iRots, i ); nif->set( iRot, "Num Keys", nif->get(index, "Num Rotation Keys") ); nif->set( iRot, "Interpolation", rotationType ); nif->updateArraySize( iRot, "Keys" ); @@ -335,7 +336,7 @@ class spConvertQuatsToEulers final : public Spell for ( int q = 0; q < nif->rowCount( iQuats ); q++ ) { - QModelIndex iQuat = iQuats.child( q, 0 ); + QModelIndex iQuat = QModelIndex_child( iQuats, q ); float time = nif->get( iQuat, "Time" ); Quat value = nif->get( iQuat, "Value" ); @@ -346,9 +347,9 @@ class spConvertQuatsToEulers final : public Spell float x, y, z; tlocal.toEuler( x, y, z ); - QModelIndex xRot = iRots.child( 0, 0 ); - QModelIndex yRot = iRots.child( 1, 0 ); - QModelIndex zRot = iRots.child( 2, 0 ); + QModelIndex xRot = QModelIndex_child( iRots ); + QModelIndex yRot = QModelIndex_child( iRots, 1 ); + QModelIndex zRot = QModelIndex_child( iRots, 2 ); xRot = nif->getIndex( xRot, "Keys" ); @@ -373,11 +374,13 @@ class spFixAVObjectPalette final : public Spell return iBlock.isValid(); } - + QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final { auto iHeader = nif->getHeaderIndex(); +#if 0 auto numStrings = nif->get( iHeader, "Num Strings" ); +#endif auto strings = nif->getArray( iHeader, "Strings" ); auto numBlocks = nif->get( iHeader, "Num Blocks" ); @@ -388,7 +391,7 @@ class spFixAVObjectPalette final : public Spell auto objs = nif->getIndex( index, "Objs" ); auto numObjs = nif->rowCount( objs ); for ( int i = 0; i < numObjs; i++ ) { - auto c = objs.child( i, 0 ); + auto c = QModelIndex_child( objs, i ); auto iAV = nif->getIndex( c, "AV Object" ); diff --git a/src/spells/blocks.cpp b/src/spells/blocks.cpp index 9163041a..a810ba9c 100644 --- a/src/spells/blocks.cpp +++ b/src/spells/blocks.cpp @@ -12,6 +12,8 @@ #include // std::stable_sort +#include "gamemanager.h" + // Brief description is deliberately not autolinked to class Spell /*! \file blocks.cpp * \brief Block manipulation spells @@ -79,7 +81,7 @@ QMultiMap ctlrMappingBS = { { "BSLightingShaderProperty", "BSLightingShaderPropertyColorController" }, { "BSLightingShaderProperty", "BSLightingShaderPropertyFloatController" }, // FO4 - { "NiLight", "NiLightRadiusController" }, + { "NiLight", "NiLightRadiusController" }, }; //! Blocks that are never used beyond 10.1.0.0 @@ -125,13 +127,13 @@ QStringList boolValue = { "NiBlendBoolInterpolator" }; //! The interpolators that return true for NiInterpolator::IsFloatValueSupported() -QStringList floatValue = { +QStringList floatValue = { "NiFloatInterpolator", "NiBlendFloatInterpolator", "NiBSplineFloatInterpolator" }; //! The interpolators that return true for NiInterpolator::IsPoint3ValueSupported() -QStringList point3Value = { +QStringList point3Value = { "NiPoint3Interpolator", "NiBlendPoint3Interpolator", "NiBSplinePoint3Interpolator" @@ -147,7 +149,7 @@ QStringList transformValue = { }; //! The kind of interpolator values supported on each controller -QMultiMap interpMapping = +QMultiMap interpMapping = { { "NiBoolInterpController", boolValue }, { "NiFloatInterpController", floatValue }, @@ -199,10 +201,10 @@ QStringList getStringsArray( NifModel * nif, const QModelIndex & parent, if ( name.isEmpty() ) { for ( int i = 0; i < nif->rowCount( iArr ); i++ ) - strings << nif->resolveString( iArr.child( i, 0 ) ); + strings << nif->resolveString( QModelIndex_child( iArr, i ) ); } else { for ( int i = 0; i < nif->rowCount( iArr ); i++ ) - strings << nif->resolveString( iArr.child( i, 0 ), name ); + strings << nif->resolveString( QModelIndex_child( iArr, i ), name ); } return strings; @@ -217,10 +219,10 @@ void setStringsArray( NifModel * nif, const QModelIndex & parent, QStringList & if ( name.isEmpty() ) { for ( int i = 0; i < nif->rowCount( iArr ); i++ ) - nif->set( iArr.child( i, 0 ), strings.takeFirst() ); + nif->set( QModelIndex_child( iArr, i ), strings.takeFirst() ); } else { for ( int i = 0; i < nif->rowCount( iArr ); i++ ) - nif->set( iArr.child( i, 0 ), name, strings.takeFirst() ); + nif->set( QModelIndex_child( iArr, i ), name, strings.takeFirst() ); } } //! Get "Name" et al. for NiObjectNET, NiExtraData, NiPSysModifier, etc. @@ -228,7 +230,7 @@ QStringList getNiObjectRootStrings( NifModel * nif, const QModelIndex & iBlock ) { QStringList strings; for ( int i = 0; i < nif->rowCount( iBlock ); i++ ) { - auto iString = iBlock.child( i, 0 ); + auto iString = QModelIndex_child( iBlock, i ); if ( rootStringList.contains( nif->itemName( iString ) ) ) strings << nif->resolveString( iString ); } @@ -239,7 +241,7 @@ QStringList getNiObjectRootStrings( NifModel * nif, const QModelIndex & iBlock ) void setNiObjectRootStrings( NifModel * nif, const QModelIndex & iBlock, QStringList & strings ) { for ( int i = 0; i < nif->rowCount( iBlock ); i++ ) { - auto iString = iBlock.child( i, 0 ); + auto iString = QModelIndex_child( iBlock, i ); if ( rootStringList.contains( nif->itemName( iString ) ) ) nif->set( iString, strings.takeFirst() ); } @@ -254,7 +256,7 @@ QStringList getStringsNiMesh( NifModel * nif, const QModelIndex & iBlock ) return {}; for ( int i = 0; i < nif->rowCount( iData ); i++ ) - strings << getStringsArray( nif, iData.child( i, 0 ), "Component Semantics", "Name" ); + strings << getStringsArray( nif, QModelIndex_child( iData, i ), "Component Semantics", "Name" ); return strings; } @@ -266,7 +268,7 @@ void setStringsNiMesh( NifModel * nif, const QModelIndex & iBlock, QStringList & return; for ( int i = 0; i < nif->rowCount( iData ); i++ ) - setStringsArray( nif, iData.child( i, 0 ), strings, "Component Semantics", "Name" ); + setStringsArray( nif, QModelIndex_child( iData, i ), strings, "Component Semantics", "Name" ); } //! Get strings for NiSequence QStringList getStringsNiSequence( NifModel * nif, const QModelIndex & iBlock ) @@ -277,7 +279,7 @@ QStringList getStringsNiSequence( NifModel * nif, const QModelIndex & iBlock ) return {}; for ( int i = 0; i < nif->rowCount( iControlledBlocks ); i++ ) { - auto iChild = iControlledBlocks.child( i, 0 ); + auto iChild = QModelIndex_child( iControlledBlocks, i ); strings << nif->resolveString( iChild, "Target Name" ) << nif->resolveString( iChild, "Node Name" ) << nif->resolveString( iChild, "Property Type" ) @@ -296,7 +298,7 @@ void setStringsNiSequence( NifModel * nif, const QModelIndex & iBlock, QStringLi return; for ( int i = 0; i < nif->rowCount( iControlledBlocks ); i++ ) { - auto iChild = iControlledBlocks.child( i, 0 ); + auto iChild = QModelIndex_child( iControlledBlocks, i ); nif->set( iChild, "Target Name", strings.takeFirst() ); nif->set( iChild, "Node Name", strings.takeFirst() ); nif->set( iChild, "Property Type", strings.takeFirst() ); @@ -320,7 +322,7 @@ QStringList serializeStrings( NifModel * nif, const QModelIndex & iBlock, const strings << getStringsArray( nif, iBlock, "Data" ); else if ( type == "NiMorphWeightsController" ) strings << getStringsArray( nif, iBlock, "Target Names" ); - + if ( type == "NiMesh" || nif->inherits( type, "NiGeometry" ) ) strings << getStringsArray( nif, nif->getIndex( iBlock, "Material Data" ), "Material Name" );; @@ -364,7 +366,7 @@ bool addLink( NifModel * nif, const QModelIndex & iParent, const QString & array int numlinks = nif->get( iSize ); nif->set( iSize, numlinks + 1 ); nif->updateArraySize( iArray ); - nif->setLink( iArray.child( numlinks, 0 ), link ); + nif->setLink( QModelIndex_child( iArray, numlinks ), link ); return true; } @@ -375,7 +377,7 @@ bool addLink( NifModel * nif, const QModelIndex & iParent, const QString & array if ( nif->isArray( iArray ) && item ) { for ( int c = 0; c < item->childCount(); c++ ) { if ( item->child( c )->getLinkValue() == -1 ) { - nif->setLink( iArray.child( c, 0 ), link ); + nif->setLink( QModelIndex_child( iArray, c ), link ); return true; } } @@ -657,6 +659,14 @@ QMap blockMenu( NifModel * nif, const std::list & blo return map; } +static std::list< QString > qStringListToStdList( const QStringList & v ) +{ + std::list< QString > tmp; + for ( const auto & i : v ) + tmp.push_back( i ); + return tmp; +} + //! Insert an unattached block class spInsertBlock final : public Spell { @@ -674,7 +684,7 @@ class spInsertBlock final : public Spell { QMenu menu; menu.addSection( tr( "Alphabetical" ) ); - for ( QMenu * m : blockMenu( nif, NifModel::allNiBlocks().toStdList(), true, true ) ) { + for ( QMenu * m : blockMenu( nif, qStringListToStdList( NifModel::allNiBlocks() ), true, true ) ) { if ( m->title().isEmpty() ) menu.addSection( tr( "Categories" ) ); else if ( m->actions().size() == 1 ) @@ -827,7 +837,7 @@ class spAddNewRef final : public Spell NifItem * item = static_cast(index.internalPointer()); auto type = item->templ(); - std::list allIds = nif->allNiBlocks().toStdList(); + std::list allIds = qStringListToStdList( nif->allNiBlocks() ); blockFilter( nif, allIds, type ); auto iBlock = nif->getBlockIndex( index ); @@ -870,14 +880,14 @@ class spAddNewRef final : public Spell if ( nif->getBSVersion() > 0 ) ctlrFilter( ctlrMappingBS ); - } else if ( nif->blockInherits( iBlock, "NiTimeController" ) + } else if ( nif->blockInherits( iBlock, "NiTimeController" ) && nif->inherits( type, "NiInterpolator" ) ) { // Show only applicable types for interpolator links for the given block interpFilter( interpMapping ); } else { ids = allIds; } - + ids.sort(); ids.unique(); @@ -1012,7 +1022,7 @@ class spAttachExtraData final : public Spell addLink( nif, iParent, "Extra Data List", nif->getBlockNumber( iExtra ) ); return iExtra; - } + } return index; } @@ -1048,7 +1058,7 @@ class spCopyBlock final : public Spell QString name() const override final { return Spell::tr( "Copy" ); } QString page() const override final { return Spell::tr( "Block" ); } bool constant() const override final { return true; } - QKeySequence hotkey() const override final { return{ Qt::CTRL + Qt::SHIFT + Qt::Key_C }; } + QKeySequence hotkey() const override final { return{ Qt::CTRL | Qt::SHIFT | Qt::Key_C }; } bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { @@ -1182,7 +1192,7 @@ class spPasteOverBlock final : public Spell public: QString name() const override final { return Spell::tr( "Paste Over" ); } QString page() const override final { return Spell::tr( "Block" ); } - QKeySequence hotkey() const override final { return{ Qt::CTRL + Qt::SHIFT + Qt::Key_V }; } + QKeySequence hotkey() const override final { return{ Qt::CTRL | Qt::SHIFT | Qt::Key_V }; } QPair acceptFormat( const QString & format, const NifModel * nif, const QModelIndex & iBlock ) { @@ -1399,7 +1409,7 @@ QModelIndex spPasteBranch::cast( NifModel * nif, const QModelIndex & index ) tr( "Nif versions differ!

Current File Version: %1
Clipboard Data Version: %2

The results will be unpredictable..." ) .arg( nif->getVersion() ).arg( v ), tr( "Continue" ), tr( "Cancel" ) - ) == 0 + ) == 0 ) ) { @@ -1615,7 +1625,7 @@ class spMoveBlockUp final : public Spell public: QString name() const override final { return Spell::tr( "Move Up" ); } QString page() const override final { return Spell::tr( "Block" ); } - QKeySequence hotkey() const override final { return { Qt::CTRL + Qt::Key_Up }; } + QKeySequence hotkey() const override final { return { Qt::ControlModifier | Qt::Key_Up }; } bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { @@ -1638,7 +1648,7 @@ class spMoveBlockDown final : public Spell public: QString name() const override final { return Spell::tr( "Move Down" ); } QString page() const override final { return Spell::tr( "Block" ); } - QKeySequence hotkey() const override final { return { Qt::CTRL + Qt::Key_Down }; } + QKeySequence hotkey() const override final { return { Qt::ControlModifier | Qt::Key_Down }; } bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { @@ -1722,7 +1732,7 @@ class spCropToBranch final : public Spell // add all its children, grandchildren, ... for ( const auto child : nif->getChildLinks( link ) ) { // check that child is not in branch to avoid infinite recursion - if ( !branch.contains( child ) ) + if ( !branch.contains( quint32(child) ) ) // it's not in there yet so add the child and grandchildren etc... branch << getBranch( nif, child ); } @@ -1741,7 +1751,7 @@ class spCropToBranch final : public Spell int m = 0; // tracks the block number in the old system i.e. as they are numbered in the branch list while ( n < nif->getBlockCount() ) { - if ( !branch.contains( m ) ) + if ( !branch.contains( quint32(m) ) ) nif->removeNiBlock( n ); else n++; @@ -1825,7 +1835,7 @@ class spDuplicateBlock final : public Spell public: QString name() const override final { return Spell::tr( "Duplicate" ); } QString page() const override final { return Spell::tr( "Block" ); } - QKeySequence hotkey() const override final { return{ Qt::CTRL + Qt::SHIFT + Qt::Key_D }; } + QKeySequence hotkey() const override final { return{ Qt::CTRL | Qt::SHIFT | Qt::Key_D }; } bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { @@ -2019,7 +2029,7 @@ class spSortBlockNames final : public Spell QList > links; for ( int r = 0; r < nif->rowCount( iChildren ); r++ ) { - qint32 l = nif->getLink( iChildren.child( r, 0 ) ); + qint32 l = nif->getLink( QModelIndex_child( iChildren, r ) ); if ( l >= 0 ) links.append( QPair( nif->get( nif->getBlockIndex( l ), "Name" ), l ) ); @@ -2028,8 +2038,8 @@ class spSortBlockNames final : public Spell std::stable_sort( links.begin(), links.end() ); for ( int r = 0; r < links.count(); r++ ) { - if ( links[r].second != nif->getLink( iChildren.child( r, 0 ) ) ) - nif->setLink( iChildren.child( r, 0 ), links[r].second ); + if ( links[r].second != nif->getLink( QModelIndex_child( iChildren, r ) ) ) + nif->setLink( QModelIndex_child( iChildren, r ), links[r].second ); nif->set( iNumChildren, links.count() ); nif->updateArraySize( iChildren ); @@ -2039,7 +2049,7 @@ class spSortBlockNames final : public Spell if ( index.isValid() ) { return index; - } + } return QModelIndex(); } @@ -2094,7 +2104,7 @@ class spAttachParentNode final : public Spell int attachedNodeNumber = thisBlockNumber++; // replace this block with the attached node - nif->setLink( nif->getIndex( iParent, "Children" ).child( thisBlockIndex, 0 ), attachedNodeNumber ); + nif->setLink( QModelIndex_child( nif->getIndex( iParent, "Children" ), thisBlockIndex ), attachedNodeNumber ); // attach ourselves to the attached node addLink( nif, attachedNode, "Children", thisBlockNumber ); diff --git a/src/spells/color.cpp b/src/spells/color.cpp index cffe3be6..6bd3ad8c 100644 --- a/src/spells/color.cpp +++ b/src/spells/color.cpp @@ -1,4 +1,5 @@ #include "spellbook.h" +#include "gamemanager.h" #include "ui/widgets/colorwheel.h" @@ -35,7 +36,7 @@ class spChooseColor final : public Spell auto col = ColorWheel::choose( nif->get( index ) ); nif->set( index, *static_cast(&col) ); } - + return index; } @@ -54,12 +55,12 @@ class spSetAllColor final : public Spell bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { - return nif->isArray( index ) && nif->getValue( index.child( 0, 0 ) ).isColor(); + return nif->isArray( index ) && nif->getValue( QModelIndex_child( index ) ).isColor(); } QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final { - QModelIndex colorIdx = (nif->isArray( index )) ? index.child( 0, 0 ) : index; + QModelIndex colorIdx = (nif->isArray( index )) ? QModelIndex_child( index ) : index; auto typ = nif->getValue( colorIdx ).type(); if ( typ == NifValue::tColor3 ) diff --git a/src/spells/flags.cpp b/src/spells/flags.cpp index 73c302c8..0fb80efd 100644 --- a/src/spells/flags.cpp +++ b/src/spells/flags.cpp @@ -675,7 +675,7 @@ class spEditFlags : public Spell Spell::tr( "Not Equal" ), // 5 Spell::tr( "Greater or Equal" ), // 6 Spell::tr( "Always" ) // 7 - }; + }; QComboBox * cmbFunc = dlgCombo( vbox, Spell::tr( "Stencil Function" ), compareFunc ); @@ -989,7 +989,7 @@ class spEditVertexDesc final : public spEditFlags Spell::tr( "Skinned" ), // VA_SKINNING = 0x6, Spell::tr( "Land Data" ), // VA_LANDDATA = 0x7, Spell::tr( "Eye Data" ), // VA_EYEDATA = 0x8, - Spell::tr( "" ), + Spell::tr( "" ), Spell::tr( "Full Precision" ) // 1 << 10 }; diff --git a/src/spells/havok.cpp b/src/spells/havok.cpp index d23ff8a4..c4389447 100644 --- a/src/spells/havok.cpp +++ b/src/spells/havok.cpp @@ -16,6 +16,7 @@ #include // std::sort +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell /*! \file havok.cpp @@ -245,8 +246,8 @@ class spCreateCVS final : public Spell nif->updateArraySize( iListShape, "Unknown Ints" ); replace = false; } - } - + } + if ( replace ) { // Replace link nif->setLink( shapeLink, nif->getBlockNumber( iCVS ) ); @@ -258,7 +259,7 @@ class spCreateCVS final : public Spell Message::info( nullptr, Spell::tr( "Created hull with %1 vertices, %2 normals" ) .arg( convex_verts.count() ) - .arg( convex_norms.count() ) + .arg( convex_norms.count() ) ); return (iCVS.isValid()) ? iCVS : rigidBody; @@ -282,7 +283,7 @@ class spConstraintHelper final : public Spell "bhkRagdollConstraint", "bhkLimitedHingeConstraint", "bhkHingeConstraint", - "bhkPrismaticConstraint" + "bhkPrismaticConstraint" }; return nif && nif->isNiBlock( nif->getBlockIndex( index ), blockNames ); } @@ -451,7 +452,7 @@ class spPackHavokStrips final : public Spell QModelIndex iPoints = nif->getIndex( iData, "Points" ); for ( int x = 0; x < nif->rowCount( iPoints ); x++ ) { - tris += triangulate( nif->getArray( iPoints.child( x, 0 ) ) ); + tris += triangulate( nif->getArray( QModelIndex_child( iPoints, x ) ) ); } QMutableVectorIterator it( tris ); @@ -488,9 +489,9 @@ class spPackHavokStrips final : public Spell nif->set( iPackedShape, "Num Sub Shapes", 1 ); QModelIndex iSubShapes = nif->getIndex( iPackedShape, "Sub Shapes" ); nif->updateArraySize( iSubShapes ); - nif->set( iSubShapes.child( 0, 0 ), "Layer", 1 ); - nif->set( iSubShapes.child( 0, 0 ), "Num Vertices", vertices.count() ); - nif->set( iSubShapes.child( 0, 0 ), "Material", nif->get( iShape, "Material" ) ); + nif->set( QModelIndex_child( iSubShapes ), "Layer", 1 ); + nif->set( QModelIndex_child( iSubShapes ), "Num Vertices", vertices.count() ); + nif->set( QModelIndex_child( iSubShapes ), "Material", nif->get( iShape, "Material" ) ); nif->setArray( iPackedShape, "Unknown Floats", { 0.0f, 0.0f, 0.1f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.1f } ); nif->set( iPackedShape, "Scale", 1.0f ); nif->setArray( iPackedShape, "Unknown Floats 2", { 1.0f, 1.0f, 1.0f } ); @@ -503,8 +504,8 @@ class spPackHavokStrips final : public Spell nif->updateArraySize( iTriangles ); for ( int t = 0; t < triangles.size(); t++ ) { - nif->set( iTriangles.child( t, 0 ), "Triangle", triangles[ t ] ); - nif->set( iTriangles.child( t, 0 ), "Normal", normals.value( t ) ); + nif->set( QModelIndex_child( iTriangles, t ), "Triangle", triangles[ t ] ); + nif->set( QModelIndex_child( iTriangles, t ), "Normal", normals.value( t ) ); } nif->set( iPackedData, "Num Vertices", vertices.count() ); diff --git a/src/spells/mesh.cpp b/src/spells/mesh.cpp index 5d9cda56..6fd898af 100644 --- a/src/spells/mesh.cpp +++ b/src/spells/mesh.cpp @@ -6,6 +6,7 @@ #include +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell /*! \file mesh.cpp @@ -77,7 +78,7 @@ static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, cons QModelIndex iUVSets = nif->getIndex( iData, "UV Sets" ); for ( int r = 0; r < nif->rowCount( iUVSets ); r++ ) { - texco << nif->getArray( iUVSets.child( r, 0 ) ); + texco << nif->getArray( QModelIndex_child( iUVSets, r ) ); if ( texco.last().count() != verts.count() ) throw QString( Spell::tr( "UV array size differs" ) ); @@ -107,7 +108,7 @@ static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, cons QModelIndex iPoints = nif->getIndex( iData, "Points" ); for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) { - strips << nif->getArray( iPoints.child( r, 0 ) ); + strips << nif->getArray( QModelIndex_child( iPoints, r ) ); for ( const auto p : strips.last() ) { used.insert( p, true ); } @@ -165,7 +166,7 @@ static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, cons nif->setArray( iData, "Triangles", tris ); for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) - nif->setArray( iPoints.child( r, 0 ), strips[r] ); + nif->setArray( QModelIndex_child( iPoints, r ), strips[r] ); nif->set( iData, "Num Vertices", verts.count() ); nif->updateArraySize( iData, "Vertices" ); @@ -176,8 +177,8 @@ static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, cons nif->setArray( iData, "Vertex Colors", colors ); for ( int r = 0; r < nif->rowCount( iUVSets ); r++ ) { - nif->updateArraySize( iUVSets.child( r, 0 ) ); - nif->setArray( iUVSets.child( r, 0 ), texco[r] ); + nif->updateArraySize( QModelIndex_child( iUVSets, r ) ); + nif->setArray( QModelIndex_child( iUVSets, r ), texco[r] ); } // process NiSkinData @@ -189,10 +190,10 @@ static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, cons for ( int b = 0; b < nif->rowCount( iBones ); b++ ) { QVector > weights; - QModelIndex iWeights = nif->getIndex( iBones.child( b, 0 ), "Vertex Weights" ); + QModelIndex iWeights = nif->getIndex( QModelIndex_child( iBones, b ), "Vertex Weights" ); for ( int w = 0; w < nif->rowCount( iWeights ); w++ ) { - weights.append( QPair( nif->get( iWeights.child( w, 0 ), "Index" ), nif->get( iWeights.child( w, 0 ), "Weight" ) ) ); + weights.append( QPair( nif->get( QModelIndex_child( iWeights, w ), "Index" ), nif->get( QModelIndex_child( iWeights, w ), "Weight" ) ) ); } for ( int x = weights.count() - 1; x >= 0; x-- ) { @@ -209,12 +210,12 @@ static void removeWasteVertices( NifModel * nif, const QModelIndex & iData, cons w.first = map[ w.first ]; } - nif->set( iBones.child( b, 0 ), "Num Vertices", weights.count() ); + nif->set( QModelIndex_child( iBones, b ), "Num Vertices", weights.count() ); nif->updateArraySize( iWeights ); for ( int w = 0; w < weights.count(); w++ ) { - nif->set( iWeights.child( w, 0 ), "Index", weights[w].first ); - nif->set( iWeights.child( w, 0 ), "Weight", weights[w].second ); + nif->set( QModelIndex_child( iWeights, w ), "Index", weights[w].first ); + nif->set( QModelIndex_child( iWeights, w ), "Weight", weights[w].second ); } } @@ -279,7 +280,7 @@ class spFlipTexCoords final : public Spell void flip( NifModel * nif, const QModelIndex & index, int f ) { if ( nif->isArray( index ) ) { - QModelIndex idx = index.child( 0, 0 ); + QModelIndex idx = QModelIndex_child( index ); if ( idx.isValid() ) { if ( nif->isArray( idx ) ) @@ -332,7 +333,7 @@ class spFlipFace final : public Spell bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { return ( nif->getValue( index ).type() == NifValue::tTriangle ) - || ( nif->isArray( index ) && nif->getValue( index.child( 0, 0 ) ).type() == NifValue::tTriangle ); + || ( nif->isArray( index ) && nif->getValue( QModelIndex_child( index ) ).type() == NifValue::tTriangle ); } QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final @@ -487,7 +488,7 @@ class spRemoveDuplicateVertices final : public Spell QModelIndex iUVSets = nif->getIndex( iData, "UV Sets" ); for ( int r = 0; r < nif->rowCount( iUVSets ); r++ ) { - texco << nif->getArray( iUVSets.child( r, 0 ) ); + texco << nif->getArray( QModelIndex_child( iUVSets, r ) ); if ( texco.last().count() != verts.count() ) throw QString( Spell::tr( "UV array size differs" ) ); @@ -555,7 +556,7 @@ class spRemoveDuplicateVertices final : public Spell QModelIndex iPoints = nif->getIndex( iData, "Points" ); for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) { - QVector strip = nif->getArray( iPoints.child( r, 0 ) ); + QVector strip = nif->getArray( QModelIndex_child( iPoints, r ) ); QMutableVectorIterator istrp( strip ); while ( istrp.hasNext() ) { @@ -565,7 +566,7 @@ class spRemoveDuplicateVertices final : public Spell p = map.value( p ); } - nif->setArray( iPoints.child( r, 0 ), strip ); + nif->setArray( QModelIndex_child( iPoints, r ), strip ); } // finally, remove the now unused vertices @@ -696,7 +697,7 @@ class spUpdateBounds final : public Spell // Retrieve the verts QVector verts; for ( int i = 0; i < nif->rowCount( vertData ); i++ ) { - verts << nif->get( vertData.child( i, 0 ), "Vertex" ); + verts << nif->get( QModelIndex_child( vertData, i ), "Vertex" ); } if ( verts.isEmpty() ) @@ -740,7 +741,7 @@ class spUpdateAllBounds final : public Spell indices << idx; } - for ( const QModelIndex& idx : indices ) { + for ( const QPersistentModelIndex& idx : indices ) { updBounds.castIfApplicable( nif, idx ); } @@ -768,7 +769,7 @@ QModelIndex spUpdateTrianglesFromSkin::cast( NifModel * nif, const QModelIndex & QVector tris; auto iParts = nif->getIndex( iSkinPart, "Partitions" ); for ( int i = 0; i < nif->rowCount( iParts ) && iParts.isValid(); i++ ) - tris << SkinPartition( nif, iParts.child( i, 0 ) ).getRemappedTriangles(); + tris << SkinPartition( nif, QModelIndex_child( iParts, i ) ).getRemappedTriangles(); nif->set( iData, "Has Triangles", true ); nif->set( iData, "Num Triangles", tris.size() ); diff --git a/src/spells/misc.cpp b/src/spells/misc.cpp index 016560be..50f75c4a 100644 --- a/src/spells/misc.cpp +++ b/src/spells/misc.cpp @@ -1,5 +1,6 @@ #include "misc.h" #include "model/undocommands.h" +#include "gamemanager.h" #include @@ -161,7 +162,7 @@ class spExportBinary final : public Spell QString name() const override final { return Spell::tr( "Export Binary" ); } bool constant() const override final { return true; } - bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final + bool isApplicable( [[maybe_unused]] const NifModel * nif, const QModelIndex & index ) override final { NifItem * item = static_cast(index.internalPointer()); @@ -209,7 +210,7 @@ class spImportBinary final : public Spell public: QString name() const override final { return Spell::tr( "Import Binary" ); } - bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final + bool isApplicable( [[maybe_unused]] const NifModel * nif, const QModelIndex & index ) override final { NifItem * item = static_cast(index.internalPointer()); @@ -226,7 +227,7 @@ class spImportBinary final : public Spell if ( item->isArray() && item->isBinary() ) { parent = item; iParent = index; - idx = index.child( 0, 0 ); + idx = QModelIndex_child( index ); } QString filename = QFileDialog::getOpenFileName( qApp->activeWindow(), tr( "Import Binary File" ), "", "*.*" ); @@ -239,9 +240,9 @@ class spImportBinary final : public Spell nif->set( iParent.parent(), parent->arr1(), data.count() ); nif->updateArraySize( iParent ); } - + nif->set( idx, data ); - + file.close(); } @@ -280,7 +281,7 @@ QModelIndex spCollapseArray::numCollapser( NifModel * nif, QModelIndex & iNumEle QVector links; for ( int r = 0; r < nif->rowCount( iArray ); r++ ) { - qint32 l = nif->getLink( iArray.child( r, 0 ) ); + qint32 l = nif->getLink( QModelIndex_child( iArray, r ) ); if ( l >= 0 ) links.append( l ); diff --git a/src/spells/moppcode.cpp b/src/spells/moppcode.cpp index 33a00625..9f7ac503 100644 --- a/src/spells/moppcode.cpp +++ b/src/spells/moppcode.cpp @@ -1,4 +1,5 @@ #include "spellbook.h" +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell @@ -178,7 +179,7 @@ class spMoppCode final : public Spell subshapeVerts.resize( nSubShapes ); for ( int t = 0; t < nSubShapes; t++ ) { - subshapeVerts[t] = nif->get( ihkSubShapes.child( t, 0 ), "Num Vertices" ); + subshapeVerts[t] = nif->get( QModelIndex_child( ihkSubShapes, t ), "Num Vertices" ); } } else if ( nif->checkVersion( 0x14020007, 0x14020007 ) ) { int nSubShapes = nif->get( ihkPackedNiTriStripsData, "Num Sub Shapes" ); @@ -186,7 +187,7 @@ class spMoppCode final : public Spell subshapeVerts.resize( nSubShapes ); for ( int t = 0; t < nSubShapes; t++ ) { - subshapeVerts[t] = nif->get( ihkSubShapes.child( t, 0 ), "Num Vertices" ); + subshapeVerts[t] = nif->get( QModelIndex_child( ihkSubShapes, t ), "Num Vertices" ); } } @@ -198,7 +199,7 @@ class spMoppCode final : public Spell triangles.resize( nTriangles ); for ( int t = 0; t < nTriangles; t++ ) { - triangles[t] = nif->get( iTriangles.child( t, 0 ), "Triangle" ); + triangles[t] = nif->get( QModelIndex_child( iTriangles, t ), "Triangle" ); } if ( verts.isEmpty() || triangles.isEmpty() ) { @@ -220,7 +221,7 @@ class spMoppCode final : public Spell nif->set( nif->getIndex( iMoppCode, "Offset" ), Vector4(origin, scale) ); QModelIndex iCodeSize = nif->getIndex( iMoppCode, "Data Size" ); - QModelIndex iCode = nif->getIndex( iMoppCode, "Data" ).child( 0, 0 ); + QModelIndex iCode = QModelIndex_child( nif->getIndex( iMoppCode, "Data" ) ); if ( iCodeSize.isValid() && iCode.isValid() ) { nif->set( iCodeSize, moppcode.size() ); @@ -270,7 +271,7 @@ class spAllMoppCodes final : public Spell indices << idx; } - for ( const QModelIndex& idx : indices ) { + for ( const QPersistentModelIndex& idx : indices ) { TSpacer.castIfApplicable( nif, idx ); } diff --git a/src/spells/morphctrl.cpp b/src/spells/morphctrl.cpp index d10f36b2..972c132c 100644 --- a/src/spells/morphctrl.cpp +++ b/src/spells/morphctrl.cpp @@ -1,4 +1,5 @@ #include "spellbook.h" +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell @@ -50,23 +51,23 @@ class spMorphFrameSave final : public Spell qCWarning( nsSpell ) << Spell::tr( "overriding base key frame, all other frames will be cleared" ); nif->set( iMorphData, "Num Vertices", nif->get( iMeshData, "Num Vertices" ) ); QVector verts = nif->getArray( iMeshData, "Vertices" ); - nif->updateArraySize( iFrames.child( 0, 0 ), "Vectors" ); - nif->setArray( iFrames.child( 0, 0 ), "Vectors", verts ); + nif->updateArraySize( QModelIndex_child( iFrames ), "Vectors" ); + nif->setArray( QModelIndex_child( iFrames ), "Vectors", verts ); verts.fill( Vector3() ); for ( int f = 1; f < nif->rowCount( iFrames ); f++ ) { - nif->updateArraySize( iFrames.child( f, 0 ), "Vectors" ); - nif->setArray( iFrames.child( f, 0 ), "Vectors", verts ); + nif->updateArraySize( QModelIndex_child( iFrames, f ), "Vectors" ); + nif->setArray( QModelIndex_child( iFrames, f ), "Vectors", verts ); } } else { QVector verts = nif->getArray( iMeshData, "Vertices" ); - QVector base = nif->getArray( iFrames.child( 0, 0 ), "Vectors" ); + QVector base = nif->getArray( QModelIndex_child( iFrames ), "Vectors" ); QVector frame( base.count(), Vector3() ); for ( int n = 0; n < base.count(); n++ ) frame[ n ] = verts.value( n ) - base[ n ]; - nif->setArray( iFrames.child( selFrame, 0 ), "Vectors", frame ); + nif->setArray( QModelIndex_child( iFrames, selFrame ), "Vectors", frame ); } } @@ -111,7 +112,7 @@ class spMorphFrameSave final : public Spell QStringList list; for ( int i = 0; i < nif->rowCount( iFrames ); i++ ) { - list << nif->get( iFrames.child( i, 0 ), "Frame Name" ); + list << nif->get( QModelIndex_child( iFrames, i ), "Frame Name" ); } return list; diff --git a/src/spells/normals.cpp b/src/spells/normals.cpp index b7d0aac5..b8e2ead2 100644 --- a/src/spells/normals.cpp +++ b/src/spells/normals.cpp @@ -8,6 +8,7 @@ #include #include +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell /*! \file normals.cpp @@ -85,7 +86,7 @@ class spFaceNormals final : public Spell QVector > strips; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) - strips.append( nif->getArray( iPoints.child( r, 0 ) ) ); + strips.append( nif->getArray( QModelIndex_child( iPoints, r ) ) ); triangles = triangulate( strips ); } else { @@ -94,7 +95,7 @@ class spFaceNormals final : public Spell QVector norms( verts.count() ); - + faceNormals( verts, triangles, norms ); nif->set( iData, "Has Normals", 1 ); @@ -116,7 +117,7 @@ class spFaceNormals final : public Spell auto numParts = nif->get( iPart, "Num Partitions" ); auto iParts = nif->getIndex( iPart, "Partitions" ); for ( int i = 0; i < numParts; i++ ) - triangles << nif->getArray( iParts.child( i, 0 ), "Triangles" ); + triangles << nif->getArray( QModelIndex_child( iParts, i ), "Triangles" ); } QVector verts; @@ -313,7 +314,6 @@ class spSmoothNormals final : public Spell nif->set( nif->index( i, 0, iData ), "Normal", snorms[i] ); nif->resetState(); } - return index; } @@ -333,7 +333,7 @@ class spNormalize final : public Spell bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final { return ( nif->getValue( index ).type() == NifValue::tVector3 ) - || ( nif->isArray( index ) && nif->getValue( index.child( 0, 0 ) ).type() == NifValue::tVector3 ); + || ( nif->isArray( index ) && nif->getValue( QModelIndex_child( index ) ).type() == NifValue::tVector3 ); } QModelIndex cast( NifModel * nif, const QModelIndex & index ) override final diff --git a/src/spells/optimize.cpp b/src/spells/optimize.cpp index f17e84c5..fc6b84bc 100644 --- a/src/spells/optimize.cpp +++ b/src/spells/optimize.cpp @@ -11,6 +11,7 @@ #include // std::sort #include //std::greater +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell /*! \file optimize.cpp @@ -329,7 +330,7 @@ class spCombiTris final : public Spell spRemoveBranch BranchRemover; - for ( const QModelIndex& rem : remove ) { + for ( const QPersistentModelIndex& rem : remove ) { BranchRemover.cast( nif, rem ); } @@ -393,7 +394,7 @@ class spCombiTris final : public Spell .arg( nif->itemName( iBlock ) ) .arg( nif->get( iTriA, "Name" ) ) .arg( nif->get( iTriB, "Name" ) ); - + return false; } @@ -447,8 +448,8 @@ class spCombiTris final : public Spell QModelIndex iUVb = nif->getIndex( iDataB, "UV Sets" ); for ( int r = 0; r < nif->rowCount( iUVa ); r++ ) { - nif->updateArraySize( iUVa.child( r, 0 ) ); - nif->setArray( iUVa.child( r, 0 ), nif->getArray( iUVa.child( r, 0 ) ).mid( 0, numA ) + nif->getArray( iUVb.child( r, 0 ) ) ); + nif->updateArraySize( QModelIndex_child( iUVa, r ) ); + nif->setArray( QModelIndex_child( iUVa, r ), nif->getArray( QModelIndex_child( iUVa, r ) ).mid( 0, numA ) + nif->getArray( QModelIndex_child( iUVb, r ) ) ); } int triCntA = nif->get( iDataA, "Num Triangles" ); @@ -477,15 +478,15 @@ class spCombiTris final : public Spell nif->updateArraySize( iDataA, "Points" ); for ( int r = 0; r < stripCntB; r++ ) { - QVector strip = nif->getArray( nif->getIndex( iDataB, "Points" ).child( r, 0 ) ); + QVector strip = nif->getArray( QModelIndex_child( nif->getIndex( iDataB, "Points" ), r ) ); QMutableVectorIterator it( strip ); while ( it.hasNext() ) it.next() += numA; - nif->set( nif->getIndex( iDataA, "Strip Lengths" ).child( r + stripCntA, 0 ), strip.size() ); - nif->updateArraySize( nif->getIndex( iDataA, "Points" ).child( r + stripCntA, 0 ) ); - nif->setArray( nif->getIndex( iDataA, "Points" ).child( r + stripCntA, 0 ), strip ); + nif->set( QModelIndex_child( nif->getIndex( iDataA, "Strip Lengths" ), r + stripCntA ), strip.size() ); + nif->updateArraySize( QModelIndex_child( nif->getIndex( iDataA, "Points" ), r + stripCntA ) ); + nif->setArray( QModelIndex_child( nif->getIndex( iDataA, "Points" ), r + stripCntA ), strip ); } spUpdateCenterRadius CenterRadius; @@ -499,7 +500,7 @@ REGISTER_SPELL( spCombiTris ) void scan( const QModelIndex & idx, NifModel * nif, QMap & usedStrings, bool hasCED ) { for ( int i = 0; i < nif->rowCount( idx ); i++ ) { - auto child = idx.child( i, 2 ); + auto child = QModelIndex_child( idx, i, 2 ); if ( nif->rowCount( child ) > 0 ) { scan( child, nif, usedStrings, hasCED ); continue; diff --git a/src/spells/sanitize.cpp b/src/spells/sanitize.cpp index 8ef49113..c711936d 100644 --- a/src/spells/sanitize.cpp +++ b/src/spells/sanitize.cpp @@ -1,6 +1,7 @@ #include "spellbook.h" #include "sanitize.h" #include "spells/misc.h" +#include "gamemanager.h" #include @@ -62,7 +63,7 @@ class spReorderLinks : public Spell QList> links; for ( int r = 0; r < nif->rowCount( iChildren ); r++ ) { - qint32 l = nif->getLink( iChildren.child( r, 0 ) ); + qint32 l = nif->getLink( QModelIndex_child( iChildren, r ) ); if ( l >= 0 ) { links.append( QPair( l, nif->blockInherits(nif->getBlockIndex(l), {"NiTriBasedGeom", "BSTriShape"}) ) ); @@ -76,8 +77,8 @@ class spReorderLinks : public Spell std::stable_sort( links.begin(), links.end(), compareFn ); for ( int r = 0; r < links.count(); r++ ) { - if ( links[r].first != nif->getLink( iChildren.child( r, 0 ) ) ) { - nif->setLink( iChildren.child( r, 0 ), links[r].first ); + if ( links[r].first != nif->getLink( QModelIndex_child( iChildren, r ) ) ) { + nif->setLink( QModelIndex_child( iChildren, r ), links[r].first ); } } @@ -307,7 +308,7 @@ class spSanityCheckLinks final : public Spell QModelIndex check( NifModel * nif, const QModelIndex & iParent ) { for ( int r = 0; r < nif->rowCount( iParent ); r++ ) { - QModelIndex idx = iParent.child( r, 0 ); + QModelIndex idx = QModelIndex_child( iParent, r ); if ( nif->isLink( idx ) ) { qint32 l = nif->getLink( idx ); @@ -422,7 +423,7 @@ class spFixInvalidNames final : public Spell int newIdx = -1; bool isOutOfBounds = nameIdx >= numStrings; - bool isProp = nif->isNiBlock( iBlock, + bool isProp = nif->isNiBlock( iBlock, { "BSLightingShaderProperty", "BSEffectShaderProperty", "NiAlphaProperty" } ); bool isNiAV = nif->blockInherits( iBlock, "NiAVObject" ); @@ -503,13 +504,13 @@ class spFixInvalidNames final : public Spell nif->set( iHeader, "Num Strings", strings.count() ); nif->updateArraySize( iHeader, "Strings" ); nif->setArray( iHeader, "Strings", strings ); - + nif->updateHeader(); for ( const auto & b : modifiedBlocks.toStdMap() ) { auto blockName = b.first.parent().data( Qt::DisplayRole ).toString(); - Message::append( Spell::tr( "One or more blocks have had their Name sanitized." ), + Message::append( Spell::tr( "One or more blocks have had their Name sanitized." ), QString( "%1 (%2) = '%3'" ).arg( blockName ).arg( b.second ).arg( nif->get( b.first ) ) ); } @@ -542,7 +543,7 @@ class spFillBlankControllerTypes final : public Spell bool ok = true; QString str = QInputDialog::getText( 0, Spell::tr( "Fill Blank NiControllerSequence Types" ), - Spell::tr( "Choose the default Controller Type" ), + Spell::tr( "Choose the default Controller Type" ), QLineEdit::Normal, "NiTransformController", &ok ); if ( !ok ) @@ -564,8 +565,8 @@ class spFillBlankControllerTypes final : public Spell auto numBlocks = nif->rowCount( controlledBlocks ); for ( int i = 0; i < numBlocks; i++ ) { - auto ctrlrType = nif->getIndex( controlledBlocks.child( i, 0 ), "Controller Type" ); - auto nodeName = nif->getIndex( controlledBlocks.child( i, 0 ), "Node Name" ); + auto ctrlrType = nif->getIndex( QModelIndex_child( controlledBlocks, i ), "Controller Type" ); + auto nodeName = nif->getIndex( QModelIndex_child( controlledBlocks, i ), "Node Name" ); auto ctrlrTypeIdx = nif->get( ctrlrType ); if ( ctrlrTypeIdx == -1 ) { @@ -656,7 +657,7 @@ QModelIndex spErrorInvalidPaths::cast( NifModel * nif, const QModelIndex & ) auto iBSSTS = nif->getBlockIndex( i, "BSShaderTextureSet" ); if ( iBSSTS.isValid() ) checkPath( nif, iBSSTS, "Textures" ); - + auto iBSSNLP = nif->getBlockIndex( i, "BSShaderNoLightingProperty" ); if ( iBSSNLP.isValid() ) checkPath( nif, iBSSNLP, "File Name" ); @@ -718,7 +719,7 @@ bool spWarningEnvironmentMapping::isApplicable(const NifModel * nif, const QMode return nif->getBSVersion() > 0 && !index.isValid(); } -QModelIndex spWarningEnvironmentMapping::cast(NifModel * nif, const QModelIndex & idx) +QModelIndex spWarningEnvironmentMapping::cast(NifModel * nif, [[maybe_unused]] const QModelIndex & idx) { for ( int i = 0; i < nif->getBlockCount(); i++ ) { if ( nif->getBSVersion() < 83 ) { @@ -731,7 +732,7 @@ QModelIndex spWarningEnvironmentMapping::cast(NifModel * nif, const QModelIndex nif->logMessage(message(), tr("[%1] Flags lack 'Envmap_Light_Fade' which may be a mistake.").arg(i)); } } else { - + } } return QModelIndex(); diff --git a/src/spells/skeleton.cpp b/src/spells/skeleton.cpp index ff6fb0a0..d393dea4 100644 --- a/src/spells/skeleton.cpp +++ b/src/spells/skeleton.cpp @@ -15,8 +15,9 @@ #include // std::sort -#define SKEL_DAT ":/res/skel.dat" +#include "gamemanager.h" +#define SKEL_DAT ":/res/skel.dat" // Brief description is deliberately not autolinked to class Spell /*! \file skeleton.cpp @@ -147,7 +148,7 @@ class spFixSkeleton final : public Spell if ( iNames.isValid() ) for ( int n = 0; n < nif->rowCount( iNames ); n++ ) { - QModelIndex iBone = nif->getBlockIndex( nif->getLink( iNames.child( n, 0 ) ), "NiNode" ); + QModelIndex iBone = nif->getBlockIndex( nif->getLink( QModelIndex_child( iNames, n ) ), "NiNode" ); if ( iBone.isValid() ) names.append( nif->get( iBone, "Name" ) ); @@ -171,7 +172,7 @@ class spFixSkeleton final : public Spell t.writeBack( nif, iSkinData ); for ( int b = 0; b < nif->rowCount( iBones ) && b < names.count(); b++ ) { - QModelIndex iBone = iBones.child( b, 0 ); + QModelIndex iBone = QModelIndex_child( iBones, b ); t = Transform( nif, iBone ); @@ -235,19 +236,6 @@ class spScanSkeleton final : public Spell //REGISTER_SPELL( spScanSkeleton ) -//! Unknown; unused? -template <> inline bool qMapLessThanKey( const Triangle & s1, const Triangle & s2 ) -{ - // TODO: This function makes no sense. Doxygen comments seem to think it's unused. - int d = 0; - - if ( d == 0 ) d = (s1[0] - s2[0]); - if ( d == 0 ) d = (s1[1] - s2[1]); - if ( d == 0 ) d = (s1[2] - s2[2]); - - return d < 0; -} - //! Rotate a Triangle inline void qRotate( Triangle & t ) { @@ -354,11 +342,11 @@ class spSkinPartition final : public Spell int numBones = nif->rowCount( iBoneList ); for ( int bone = 0; bone < numBones; bone++ ) { - QModelIndex iVertexWeights = nif->getIndex( iBoneList.child( bone, 0 ), "Vertex Weights" ); + QModelIndex iVertexWeights = nif->getIndex( QModelIndex_child( iBoneList, bone ), "Vertex Weights" ); for ( int r = 0; r < nif->rowCount( iVertexWeights ); r++ ) { - int vertex = nif->get( iVertexWeights.child( r, 0 ), "Index" ); - float weight = nif->get( iVertexWeights.child( r, 0 ), "Weight" ); + int vertex = nif->get( QModelIndex_child( iVertexWeights, r ), "Index" ); + float weight = nif->get( QModelIndex_child( iVertexWeights, r ), "Weight" ); if ( vertex >= weights.count() ) throw QString( Spell::tr( "bad NiSkinData - vertex count does not match" ) ); @@ -371,7 +359,7 @@ class spSkinPartition final : public Spell int minBones, maxBones; minBones = maxBones = weights.value( 0 ).count(); - for ( const QList list : weights ) { + for ( const QList & list : weights ) { if ( list.count() < minBones ) minBones = list.count(); @@ -414,7 +402,7 @@ class spSkinPartition final : public Spell } float totalWeight = 0; - for ( const auto bw : lst ) { + for ( const auto & bw : lst ) { totalWeight += bw.second; } @@ -445,10 +433,10 @@ class spSkinPartition final : public Spell for ( int s = 0; s < nif->rowCount( iPoints ); s++ ) { QVector strip; - QModelIndex iStrip = iPoints.child( s, 0 ); + QModelIndex iStrip = QModelIndex_child( iPoints, s ); for ( int p = 0; p < nif->rowCount( iStrip ); p++ ) { - strip.append( nif->get( iStrip.child( p, 0 ) ) ); + strip.append( nif->get( QModelIndex_child( iStrip, p ) ) ); } strips.append( strip ); @@ -466,7 +454,7 @@ class spSkinPartition final : public Spell QModelIndex iPartData = nif->getIndex( iSkinInst, "Partitions" ); for ( quint32 i = 0; i < nparts; ++i ) { - QModelIndex iPart = iPartData.child( i, 0 ); + QModelIndex iPart = QModelIndex_child( iPartData, i ); if ( !iPart.isValid() ) continue; @@ -484,7 +472,7 @@ class spSkinPartition final : public Spell iPartData = nif->getIndex( iSkinPart, "Partitions" ); for ( quint32 i = 0; i < nskinparts; ++i ) { - QModelIndex iPart = iPartData.child( i, 0 ); + QModelIndex iPart = QModelIndex_child( iPartData, i ); if ( !iPart.isValid() ) continue; @@ -506,10 +494,10 @@ class spSkinPartition final : public Spell for ( int s = 0; s < nif->rowCount( iPoints ); s++ ) { QVector strip; - QModelIndex iStrip = iPoints.child( s, 0 ); + QModelIndex iStrip = QModelIndex_child( iPoints, s ); for ( int p = 0; p < nif->rowCount( iStrip ); p++ ) { - strip.append( nif->get( iStrip.child( p, 0 ) ) ); + strip.append( nif->get( QModelIndex_child( iStrip, p ) ) ); } strips.append( strip ); @@ -534,7 +522,7 @@ class spSkinPartition final : public Spell } } - QMap match; + QMultiMap match; bool doMatch = true; QList tribones; @@ -547,7 +535,7 @@ class spSkinPartition final : public Spell tribones.clear(); for ( int c = 0; c < 3; c++ ) { - for ( const auto bw : weights[tri[c]] ) { + for ( const auto & bw : weights[tri[c]] ) { if ( !tribones.contains( bw.first ) ) tribones.append( bw.first ); } @@ -564,7 +552,7 @@ class spSkinPartition final : public Spell if ( weights[tri[t]].count() == 1 ) nono.append( weights[tri[t]].first().first ); - for ( const auto bw : weights[tri[t]] ) { + for ( const auto & bw : weights[tri[t]] ) { sum[ bw.first ] += bw.second; } } @@ -590,12 +578,12 @@ class spSkinPartition final : public Spell QVector verts = nif->getArray( iData, "Vertices" ); for ( int a = 0; a < verts.count(); a++ ) { - match.insertMulti( a, a ); + match.insert( a, a ); for ( int b = a + 1; b < verts.count(); b++ ) { if ( verts[a] == verts[b] && weights[a] == weights[b] ) { - match.insertMulti( a, b ); - match.insertMulti( b, a ); + match.insert( a, b ); + match.insert( b, a ); } } } @@ -620,7 +608,7 @@ class spSkinPartition final : public Spell } float totalWeight = 0; - for ( const auto bw : bws ) { + for ( const auto & bw : bws ) { totalWeight += bw.second; } @@ -670,7 +658,7 @@ class spSkinPartition final : public Spell QList tribones; for ( int c = 0; c < 3; c++ ) { - for ( const auto bw : weights[tri[c]] ) { + for ( const auto & bw : weights[tri[c]] ) { if ( !tribones.contains( bw.first ) ) tribones.append( bw.first ); } @@ -701,7 +689,7 @@ class spSkinPartition final : public Spell QList tribones; for ( int c = 0; c < 3; c++ ) { - for ( const auto bw : weights[tri[c]] ) { + for ( const auto & bw : weights[tri[c]] ) { if ( !tribones.contains( bw.first ) ) tribones.append( bw.first ); } @@ -730,7 +718,7 @@ class spSkinPartition final : public Spell QList tribones; for ( int c = 0; c < 3; c++ ) { - for ( const auto bw : weights[tri[c]] ) { + for ( const auto & bw : weights[tri[c]] ) { if ( !tribones.contains( bw.first ) ) tribones.append( bw.first ); } @@ -811,7 +799,7 @@ class spSkinPartition final : public Spell QList prevPartBones; for ( int p = 0; p < parts.count(); p++ ) { - QModelIndex iPart = nif->getIndex( iSkinPart, "Partitions" ).child( p, 0 ); + QModelIndex iPart = QModelIndex_child( nif->getIndex( iSkinPart, "Partitions" ), p ); QList bones = parts[p].bones; std::sort( bones.begin(), bones.end() /*, std::less()*/ ); @@ -820,7 +808,7 @@ class spSkinPartition final : public Spell if ( iBSSkinInstPartData.isValid() ) { if ( bones != prevPartBones ) { prevPartBones = bones; - nif->set( iBSSkinInstPartData.child( p, 0 ), "Part Flag", 257 ); + nif->set( QModelIndex_child( iBSSkinInstPartData, p ), "Part Flag", 257 ); } } @@ -911,12 +899,12 @@ class spSkinPartition final : public Spell nif->updateArraySize( iVWeights ); for ( int v = 0; v < nif->rowCount( iVWeights ); v++ ) { - QModelIndex iVertex = iVWeights.child( v, 0 ); + QModelIndex iVertex = QModelIndex_child( iVWeights, v ); nif->updateArraySize( iVertex ); QList list = weights.value( vertices[v] ); for ( int b = 0; b < maxBones; b++ ) - nif->set( iVertex.child( b, 0 ), list.count() > b ? list[ b ].second : 0.0 ); + nif->set( QModelIndex_child( iVertex, b ), list.count() > b ? list[ b ].second : 0.0 ); } nif->set( iPart, "Has Faces", 1 ); @@ -931,14 +919,14 @@ class spSkinPartition final : public Spell nif->updateArraySize( iStripLengths ); for ( int s = 0; s < nif->rowCount( iStripLengths ); s++ ) - nif->set( iStripLengths.child( s, 0 ), strips.value( s ).count() ); + nif->set( QModelIndex_child( iStripLengths, s ), strips.value( s ).count() ); QModelIndex iStrips = nif->getIndex( iPart, "Strips" ); nif->updateArraySize( iStrips ); for ( int s = 0; s < nif->rowCount( iStrips ); s++ ) { - nif->updateArraySize( iStrips.child( s, 0 ) ); - nif->setArray( iStrips.child( s, 0 ), strips.value( s ) ); + nif->updateArraySize( QModelIndex_child( iStrips, s ) ); + nif->setArray( QModelIndex_child( iStrips, s ), strips.value( s ) ); } } else { //Clear out any existing strip data that might be left over from an existing Skin Partition @@ -959,12 +947,12 @@ class spSkinPartition final : public Spell nif->updateArraySize( iVBones ); for ( int v = 0; v < nif->rowCount( iVBones ); v++ ) { - QModelIndex iVertex = iVBones.child( v, 0 ); + QModelIndex iVertex = QModelIndex_child( iVBones, v ); nif->updateArraySize( iVertex ); QList list = weights.value( vertices[v] ); for ( int b = 0; b < maxBones; b++ ) - nif->set( iVertex.child( b, 0 ), list.count() > b ? bones.indexOf( list[ b ].first ) : 0 ); + nif->set( QModelIndex_child( iVertex, b ), list.count() > b ? bones.indexOf( list[ b ].first ) : 0 ); } } @@ -1032,7 +1020,7 @@ class spAllSkinPartitions final : public Spell int mbpp = 0, mbpv = 0; bool make_strips = false; - for ( const QModelIndex& idx : indices ) { + for ( const QPersistentModelIndex& idx : indices ) { Partitioner.cast( nif, idx, mbpp, mbpv, make_strips ); } @@ -1170,7 +1158,7 @@ class spFixBoneBounds final : public Spell QModelIndex iBoneMap = nif->getIndex( iSkinInstance, "Bones" ); for ( int n = 0; n < nif->rowCount( iBoneMap ); n++ ) { - QModelIndex iBone = nif->getBlockIndex( nif->getLink( iBoneMap.child( n, 0 ) ), "NiNode" ); + QModelIndex iBone = nif->getBlockIndex( nif->getLink( QModelIndex_child( iBoneMap, n ) ), "NiNode" ); if ( skelRoot != nif->getParent( nif->getBlockNumber( iBone ) ) ) return iSkinData; @@ -1189,10 +1177,10 @@ class spFixBoneBounds final : public Spell Vector3 center; float radius = 0; - QModelIndex iWeightList = nif->getIndex( iBoneDataList.child( b, 0 ), "Vertex Weights" ); + QModelIndex iWeightList = nif->getIndex( QModelIndex_child( iBoneDataList, b ), "Vertex Weights" ); for ( int w = 0; w < nif->rowCount( iWeightList ); w++ ) { - int v = nif->get( iWeightList.child( w, 0 ), "Index" ); + int v = nif->get( QModelIndex_child( iWeightList, w ), "Index" ); if ( w == 0 ) { mn = verts.value( v ); @@ -1213,7 +1201,7 @@ class spFixBoneBounds final : public Spell center = ( mn + mx ) / 2; radius = qMax( ( mn - center ).length(), ( mx - center ).length() ); - auto sphIdx = nif->getIndex( iBoneDataList.child( b, 0 ) , "Bounding Sphere" ); + auto sphIdx = nif->getIndex( QModelIndex_child( iBoneDataList, b ) , "Bounding Sphere" ); nif->set( sphIdx, "Center", center ); nif->set( sphIdx, "Radius", radius ); @@ -1389,7 +1377,7 @@ class spMirrorSkeleton final : public Spell return; for ( int b = 0; b < nif->rowCount( iBones ); b++ ) { - QModelIndex iBone = iBones.child( b, 0 ); + QModelIndex iBone = QModelIndex_child( iBones, b ); Transform tlocal( nif, iBone ); @@ -1426,7 +1414,7 @@ class spMirrorSkeleton final : public Spell if ( iQuats.isValid() ) { for ( int q = 0; q < nif->rowCount( iQuats ); q++ ) { - QModelIndex iQuat = iQuats.child( q, 0 ); + QModelIndex iQuat = QModelIndex_child( iQuats, q ); Quat value = nif->get( iQuat, "Value" ); Matrix tlocal; @@ -1449,7 +1437,7 @@ class spMirrorSkeleton final : public Spell if ( iTransKeys.isValid() ) { for ( int k = 0; k < nif->rowCount( iTransKeys ); k++ ) { - QModelIndex iKey = iTransKeys.child( k, 0 ); + QModelIndex iKey = QModelIndex_child( iTransKeys, k ); Vector3 value = nif->get( iKey, "Value" ); value = Vector3( value[0], value[1], -value[2] ); diff --git a/src/spells/stringpalette.cpp b/src/spells/stringpalette.cpp index 6f7c3493..4b33ccb3 100644 --- a/src/spells/stringpalette.cpp +++ b/src/spells/stringpalette.cpp @@ -12,6 +12,7 @@ #include #include +#include "gamemanager.h" // Brief description is deliberately not autolinked to class Spell /*! \file stringpalette.cpp @@ -351,7 +352,6 @@ class spEditStringEntries final : public Spell // rebuild palette bytes.clear(); - x = 0; QMap offsetMap; @@ -362,10 +362,9 @@ class spEditStringEntries final : public Spell // set references to empty offsetMap.insert( oldOffsets[i], -1 ); } else { - offsetMap.insert( oldOffsets[i], x ); - bytes += s; + offsetMap.insert( oldOffsets[i], int(bytes.size()) ); + bytes += s.toUtf8(); bytes.append( '\0' ); - x += ( s.length() + 1 ); } } @@ -408,23 +407,23 @@ class spEditStringEntries final : public Spell QPersistentModelIndex blocks = nif->getIndex( nextBlock, "Controlled Blocks" ); for ( int i = 0; i < nif->rowCount( blocks ); i++ ) { - QPersistentModelIndex thisBlock = blocks.child( i, 0 ); + QPersistentModelIndex thisBlock = QModelIndex_child( blocks, i ); for ( int j = 0; j < nif->rowCount( thisBlock ); j++ ) { - if ( nif->getValue( thisBlock.child( j, 0 ) ).type() == NifValue::tStringOffset ) { + if ( nif->getValue( QModelIndex_child( thisBlock, j ) ).type() == NifValue::tStringOffset ) { // we shouldn't ever exceed the limit of an int, even though the type // is properly a uint - int oldValue = nif->get( thisBlock.child( j, 0 ) ); - qDebug() << "Index " << thisBlock.child( j, 0 ) + int oldValue = nif->get( QModelIndex_child( thisBlock, j ) ); + qDebug() << "Index " << QModelIndex_child( thisBlock, j ) << " is a string offset with name " - << nif->itemName( thisBlock.child( j, 0 ) ) + << nif->itemName( QModelIndex_child( thisBlock, j ) ) << " and value " - << nif->get( thisBlock.child( j, 0 ) ); + << nif->get( QModelIndex_child( thisBlock, j ) ); if ( oldValue != -1 ) { int newValue = offsetMap.value( oldValue ); - nif->set( thisBlock.child( j, 0 ), newValue ); + nif->set( QModelIndex_child( thisBlock, j ), newValue ); numRefsUpdated++; } } diff --git a/src/spells/strippify.cpp b/src/spells/strippify.cpp index ff544dff..be66d70c 100644 --- a/src/spells/strippify.cpp +++ b/src/spells/strippify.cpp @@ -2,6 +2,7 @@ #include "blocks.h" #include "gl/gltools.h" +#include "gamemanager.h" #include "lib/nvtristripwrapper.h" @@ -55,7 +56,7 @@ class spStrippify final : public Spell int skip = 0; for ( int t = 0; t < nif->rowCount( iTriangles ); t++ ) { - Triangle tri = nif->get( iTriangles.child( t, 0 ) ); + Triangle tri = nif->get( QModelIndex_child( iTriangles, t ) ); if ( tri[0] != tri[1] && tri[1] != tri[2] && tri[2] != tri[0] ) triangles.append( tri ); @@ -112,7 +113,7 @@ class spStrippify final : public Spell nif->updateArraySize( iDstUV ); for ( int r = 0; r < nif->rowCount( iDstUV ); r++ ) { - copyArray( nif, iDstUV.child( r, 0 ), iSrcUV.child( r, 0 ) ); + copyArray( nif, QModelIndex_child( iDstUV, r ), QModelIndex_child( iSrcUV, r ) ); } } @@ -130,8 +131,8 @@ class spStrippify final : public Spell nif->updateArraySize( iPoints ); int x = 0; for ( const QVector& strip : strips ) { - nif->set( iLengths.child( x, 0 ), strip.count() ); - QModelIndex iStrip = iPoints.child( x, 0 ); + nif->set( QModelIndex_child( iLengths, x ), strip.count() ); + QModelIndex iStrip = QModelIndex_child( iPoints, x ); nif->updateArraySize( iStrip ); nif->setArray( iStrip, strip ); x++; @@ -166,13 +167,13 @@ class spStrippify final : public Spell auto stripsA = strips.at(0); if ( iLengths.isValid() && iPoints.isValid() ) { nif->updateArraySize( iLengths ); - nif->set( iLengths.child( 0, 0 ), stripsA.count() ); + nif->set( QModelIndex_child( iLengths ), stripsA.count() ); nif->updateArraySize( iPoints ); - nif->updateArraySize( iPoints.child( 0, 0 ) ); - nif->setArray( iPoints.child( 0, 0 ), stripsA ); + nif->updateArraySize( QModelIndex_child( iPoints ) ); + nif->setArray( QModelIndex_child( iPoints ), stripsA ); nif->set( iStripData, "Num Triangles", stripsA.count() - 2 ); } - + // Update New Shape nif->set( iStrip2Data, "Num Strips", 1 ); nif->set( iStrip2Data, "Has Points", 1 ); @@ -183,10 +184,10 @@ class spStrippify final : public Spell auto stripsB = strips.at(1); if ( iLengths.isValid() && iPoints.isValid() ) { nif->updateArraySize( iLengths ); - nif->set( iLengths.child( 0, 0 ), stripsB.count() ); + nif->set( QModelIndex_child( iLengths ), stripsB.count() ); nif->updateArraySize( iPoints ); - nif->updateArraySize( iPoints.child( 0, 0 ) ); - nif->setArray( iPoints.child( 0, 0 ), stripsB ); + nif->updateArraySize( QModelIndex_child( iPoints ) ); + nif->setArray( QModelIndex_child( iPoints ), stripsB ); nif->set( iStrip2Data, "Num Triangles", stripsB.count() - 2 ); } } @@ -222,7 +223,7 @@ class spStrippifyAll final : public Spell spStrippify Stripper; - for ( const QModelIndex& idx : iTriShapes ) { + for ( const QPersistentModelIndex& idx : iTriShapes ) { Stripper.castIfApplicable( nif, idx ); } @@ -260,10 +261,10 @@ class spTriangulate final : public Spell for ( int s = 0; s < nif->rowCount( iPoints ); s++ ) { QVector strip; - QModelIndex iStrip = iPoints.child( s, 0 ); + QModelIndex iStrip = QModelIndex_child( iPoints, s ); for ( int p = 0; p < nif->rowCount( iStrip ); p++ ) - strip.append( nif->get( iStrip.child( p, 0 ) ) ); + strip.append( nif->get( QModelIndex_child( iStrip, p ) ) ); strips.append( strip ); } @@ -299,7 +300,7 @@ class spTriangulate final : public Spell nif->updateArraySize( iDstUV ); for ( int r = 0; r < nif->rowCount( iDstUV ); r++ ) { - copyArray( nif, iDstUV.child( r, 0 ), iSrcUV.child( r, 0 ) ); + copyArray( nif, QModelIndex_child( iDstUV, r ), QModelIndex_child( iSrcUV, r ) ); } } @@ -336,7 +337,7 @@ class spTriangulateAll final : public Spell QString name() const override final { return Spell::tr( "Triangulate All Strips" ); } QString page() const override final { return Spell::tr( "Batch" ); } - bool isApplicable( const NifModel * nif, const QModelIndex & index ) override final + bool isApplicable( [[maybe_unused]] const NifModel * nif, const QModelIndex & index ) override final { return !index.isValid(); } @@ -352,7 +353,7 @@ class spTriangulateAll final : public Spell } spTriangulate tri; - for ( const QModelIndex& idx : triStrips ) + for ( const QPersistentModelIndex& idx : triStrips ) tri.castIfApplicable( nif, idx ); return QModelIndex(); @@ -394,7 +395,7 @@ class spStichStrips final : public Spell QList > strips; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) - strips += nif->getArray( iPoints.child( r, 0 ) ); + strips += nif->getArray( QModelIndex_child( iPoints, r ) ); if ( strips.isEmpty() ) return index; @@ -412,10 +413,10 @@ class spStichStrips final : public Spell nif->set( iData, "Num Strips", 1 ); nif->updateArraySize( iLength ); - nif->set( iLength.child( 0, 0 ), strip.size() ); + nif->set( QModelIndex_child( iLength ), strip.size() ); nif->updateArraySize( iPoints ); - nif->updateArraySize( iPoints.child( 0, 0 ) ); - nif->setArray( iPoints.child( 0, 0 ), strip ); + nif->updateArraySize( QModelIndex_child( iPoints ) ); + nif->setArray( QModelIndex_child( iPoints ), strip ); return index; } @@ -445,7 +446,7 @@ class spUnstichStrips final : public Spell if ( !( iLength.isValid() && iPoints.isValid() ) ) return index; - QVector strip = nif->getArray( iPoints.child( 0, 0 ) ); + QVector strip = nif->getArray( QModelIndex_child( iPoints ) ); if ( strip.size() <= 3 ) return index; @@ -487,9 +488,9 @@ class spUnstichStrips final : public Spell nif->updateArraySize( iPoints ); for ( int r = 0; r < strips.count(); r++ ) { - nif->set( iLength.child( r, 0 ), strips[r].size() ); - nif->updateArraySize( iPoints.child( r, 0 ) ); - nif->setArray( iPoints.child( r, 0 ), strips[r] ); + nif->set( QModelIndex_child( iLength, r ), strips[r].size() ); + nif->updateArraySize( QModelIndex_child( iPoints, r ) ); + nif->setArray( QModelIndex_child( iPoints, r ), strips[r] ); } return index; diff --git a/src/spells/tangentspace.cpp b/src/spells/tangentspace.cpp index a4951c05..3898433a 100644 --- a/src/spells/tangentspace.cpp +++ b/src/spells/tangentspace.cpp @@ -1,4 +1,5 @@ #include "tangentspace.h" +#include "gamemanager.h" #include "lib/nvtristripwrapper.h" @@ -7,7 +8,7 @@ bool spTangentSpace::isApplicable( const NifModel * nif, const QModelIndex & ind { QModelIndex iData = nif->getBlockIndex( nif->getLink( index, "Data" ) ); - if ( nif->isNiBlock( index, "BSTriShape" ) || nif->isNiBlock( index, "BSSubIndexTriShape" ) + if ( nif->isNiBlock( index, "BSTriShape" ) || nif->isNiBlock( index, "BSSubIndexTriShape" ) || nif->isNiBlock( index, "BSMeshLODTriShape" ) ) { // TODO: Check vertex flags to verify mesh has normals and space for tangents/bitangents return true; @@ -90,7 +91,7 @@ QModelIndex spTangentSpace::cast( NifModel * nif, const QModelIndex & iBlock ) if ( nif->getBSVersion() < 100 ) { QModelIndex iTexCo = nif->getIndex( iData, "UV Sets" ); - iTexCo = iTexCo.child( 0, 0 ); + iTexCo = QModelIndex_child( iTexCo ); texco = nif->getArray( iTexCo ); } @@ -102,7 +103,7 @@ QModelIndex spTangentSpace::cast( NifModel * nif, const QModelIndex & iBlock ) QVector > strips; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) - strips.append( nif->getArray( iPoints.child( r, 0 ) ) ); + strips.append( nif->getArray( QModelIndex_child( iPoints, r ) ) ); triangles = triangulate( strips ); } else if ( nif->getBSVersion() < 100 ) { @@ -113,7 +114,7 @@ QModelIndex spTangentSpace::cast( NifModel * nif, const QModelIndex & iBlock ) auto numParts = nif->get( iPartBlock, "Num Partitions" ); auto iParts = nif->getIndex( iPartBlock, "Partitions" ); for ( int i = 0; i < numParts; i++ ) - triangles << nif->getArray( iParts.child( i, 0 ), "Triangles" ); + triangles << nif->getArray( QModelIndex_child( iParts, i ), "Triangles" ); } else { triangles = nif->getArray( iShape, "Triangles" ); } @@ -265,7 +266,7 @@ QModelIndex spTangentSpace::cast( NifModel * nif, const QModelIndex & iBlock ) int numlinks = nif->get( iNumExtras ); nif->set( iNumExtras, numlinks + 1 ); nif->updateArraySize( iExtras ); - nif->setLink( iExtras.child( numlinks, 0 ), nif->getBlockNumber( iTSpace ) ); + nif->setLink( QModelIndex_child( iExtras, numlinks ), nif->getBlockNumber( iTSpace ) ); } } @@ -337,7 +338,7 @@ class spAllTangentSpaces final : public Spell indices << idx; } - for ( const QModelIndex& idx : indices ) { + for ( const QPersistentModelIndex& idx : indices ) { TSpacer.castIfApplicable( nif, idx ); } diff --git a/src/spells/texture.cpp b/src/spells/texture.cpp index 2016eaf6..73afc701 100644 --- a/src/spells/texture.cpp +++ b/src/spells/texture.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -798,7 +799,7 @@ class spMultiApplyMode final : public Spell indices << idx; } - for ( const QModelIndex& idx : indices ) { + for ( const QPersistentModelIndex& idx : indices ) { replaceApplyMode( nif, idx, cbRep->currentIndex(), cbBy->currentIndex() ); } @@ -1043,7 +1044,7 @@ TexFlipDialog::TexFlipDialog( NifModel * n, QModelIndex & index, QWidget * paren // texture action group; see options.cpp QButtonGroup * actgrp = new QButtonGroup( this ); - connect( actgrp, static_cast(&QButtonGroup::buttonClicked), this, &TexFlipDialog::textureAction ); + connect( actgrp, QOverload::of( &QButtonGroup::buttonClicked ), this, &TexFlipDialog::textureAction ); int btnid = 0; for ( const QString& tfaname : QStringList{ Spell::tr( "Add Textures" ), Spell::tr( "Remove Texture" ), @@ -1081,8 +1082,12 @@ TexFlipDialog::TexFlipDialog( NifModel * n, QModelIndex & index, QWidget * paren grid->addLayout( hbox2, 3, 0, 1, 0 ); } -void TexFlipDialog::textureAction( int i ) +void TexFlipDialog::textureAction( QAbstractButton * button ) { + int i; + if ( !( button && button->group() && ( i = button->group()->id( button ) ) >= 0 ) ) + return; + QModelIndex idx = listview->currentIndex(); switch ( i ) { diff --git a/src/spells/texture.h b/src/spells/texture.h index accc5793..f8d7088c 100644 --- a/src/spells/texture.h +++ b/src/spells/texture.h @@ -9,6 +9,7 @@ class NifFloatEdit; class NifModel; class QGridLayout; class QListView; +class QAbstractButton; class QPushButton; class QStringListModel; @@ -33,7 +34,7 @@ class TexFlipDialog final : public QDialog QPushButton * textureButtons[4]; protected slots: - void textureAction( int i ); + void textureAction( QAbstractButton * button ); void texIndex( const QModelIndex & idx ); void listFromNif(); }; diff --git a/src/spells/transform.cpp b/src/spells/transform.cpp index a3a4ef90..64099f90 100644 --- a/src/spells/transform.cpp +++ b/src/spells/transform.cpp @@ -16,6 +16,7 @@ #include #include +#include "gamemanager.h" /* XPM */ static char const * transform_xpm[] = { @@ -197,7 +198,7 @@ QModelIndex spApplyTransformation::cast( NifModel * nif, const QModelIndex & ind nif->setState( BaseModel::Processing ); for ( int i = 0; i < nif->rowCount( iVertData ); i++ ) { - auto iVert = iVertData.child( i, 0 ); + auto iVert = QModelIndex_child( iVertData, i ); auto vertex = t * nif->get( iVert, "Vertex" ); if ( !nif->set( iVert, "Vertex", vertex ) ) diff --git a/src/ui/checkablemessagebox.cpp b/src/ui/checkablemessagebox.cpp index c8698eb5..b864105a 100644 --- a/src/ui/checkablemessagebox.cpp +++ b/src/ui/checkablemessagebox.cpp @@ -53,14 +53,14 @@ QString CheckableMessageBox::text() const void CheckableMessageBox::setText( const QString & t ) { - m_d->ui.messageLabel->setText( t ); + m_d->ui.messageLabel->setText( t ); } QPixmap CheckableMessageBox::iconPixmap() const { - if ( const QPixmap * p = m_d->ui.pixmapLabel->pixmap() ) - return QPixmap( *p ); - return QPixmap(); + if ( const QPixmap * p = m_d->ui.pixmapLabel->pixmap() ) + return QPixmap( *p ); + return QPixmap(); } void CheckableMessageBox::setIconPixmap( const QPixmap & p ) diff --git a/src/ui/widgets/colorwheel.cpp b/src/ui/widgets/colorwheel.cpp index 183ffa7c..59dc1848 100644 --- a/src/ui/widgets/colorwheel.cpp +++ b/src/ui/widgets/colorwheel.cpp @@ -47,6 +47,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include /* XPM */ @@ -208,7 +209,6 @@ void ColorWheel::paintEvent( QPaintEvent * e ) QPainter p( this ); p.translate( width() / 2, height() / 2 ); p.setRenderHint( QPainter::Antialiasing ); - p.setRenderHint( QPainter::HighQualityAntialiasing ); p.setPen( Qt::NoPen ); @@ -222,7 +222,7 @@ void ColorWheel::paintEvent( QPaintEvent * e ) p.setBrush( QBrush( cgrad ) ); p.drawEllipse( QRectF( -s, -s, s * 2, s * 2 ) ); - p.setBrush( palette().color( QPalette::Background ) ); + p.setBrush( palette().color( QPalette::Window ) ); p.drawEllipse( QRectF( -c, -c, c * 2, c * 2 ) ); double x = ( H - 0.5 ) * 2 * M_PI; @@ -338,10 +338,8 @@ void ColorWheel::setColor( int x, int y ) { if ( pressed == Circle ) { QLineF l( QPointF( width() / 2.0, height() / 2.0 ), QPointF( x, y ) ); - H = l.angle( QLineF( 0, 1, 0, 0 ) ) / 360.0; - - if ( l.dx() > 0 ) - H = 1.0 - H; + H = l.angle() / 360.0 - 0.25; + H -= std::floor( H ); update(); emit sigColor( getColor() ); @@ -349,8 +347,8 @@ void ColorWheel::setColor( int x, int y ) } else if ( pressed == Triangle ) { QPointF mp( x - width() / 2, y - height() / 2 ); - QMatrix m; - m.rotate( (H ) * 360.0 + 120 ); + QTransform m; + m.rotate( ( H ) * 360.0 + 120 ); QPointF p( m.map( mp ) ); double c = qMin( width(), height() ) / 2.0; c -= c / 5; @@ -582,7 +580,7 @@ void ColorLineEdit::setColor( const QColor & c ) alpha->setValue( c.alphaF() ); QColor wc = wheel->getColor(); - + // Sync color wheel // Do NOT compare entire QColor, will create // infinite loop between their ::setColor() diff --git a/src/ui/widgets/fileselect.cpp b/src/ui/widgets/fileselect.cpp index 0c122bbc..e883e514 100644 --- a/src/ui/widgets/fileselect.cpp +++ b/src/ui/widgets/fileselect.cpp @@ -75,7 +75,7 @@ FileSelector::FileSelector( Modes mode, const QString & buttonText, QBoxLayout:: : QWidget(), Mode( mode ), dirmdl( 0 ), completer( 0 ) { QBoxLayout * lay = new QBoxLayout( dir, this ); - lay->setMargin( 0 ); + lay->setContentsMargins( 0, 0, 0, 0 ); setLayout( lay ); line = new QLineEdit( this ); diff --git a/src/ui/widgets/floatslider.cpp b/src/ui/widgets/floatslider.cpp index a3d09286..3414ab85 100644 --- a/src/ui/widgets/floatslider.cpp +++ b/src/ui/widgets/floatslider.cpp @@ -59,7 +59,7 @@ FloatSliderEditBox::FloatSliderEditBox( QWidget * parent ) setMaximumWidth( 100 ); QVBoxLayout * layout = new QVBoxLayout(); - layout->setMargin( 4 ); + layout->setContentsMargins( 4, 4, 4, 4 ); layout->setSpacing( 2 ); setLayout( layout ); } @@ -234,7 +234,7 @@ QStyleOptionSlider FloatSlider::getStyleOption() const opt.activeSubControls = QStyle::SC_None; if ( showVal ) { - int w = fontMetrics().width( "0.000" ); + int w = fontMetrics().horizontalAdvance( "0.000" ); //#pragma message("NOTICE: Qt Bugfix is needed here, see http://pastebin.mozilla.org/101393") opt.rect.adjust( (6 * w) / 10, VAL_HEIGHT, (-6 * w) / 10, 0 ); } diff --git a/src/ui/widgets/groupbox.h b/src/ui/widgets/groupbox.h index 05128536..89b25d57 100644 --- a/src/ui/widgets/groupbox.h +++ b/src/ui/widgets/groupbox.h @@ -47,9 +47,9 @@ class GroupBox final : public QGroupBox GroupBox( const QString & title, Qt::Orientation o ); ~GroupBox(); - void addWidget( QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0 ); + void addWidget( QWidget * widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment() ); - QWidget * pushLayout( const QString & name, Qt::Orientation o, int stretch = 0, Qt::Alignment alignment = 0 ); + QWidget * pushLayout( const QString & name, Qt::Orientation o, int stretch = 0, Qt::Alignment alignment = Qt::Alignment() ); void pushLayout( Qt::Orientation o, int stretch = 0 ); void popLayout(); diff --git a/src/ui/widgets/inspect.h b/src/ui/widgets/inspect.h index 3b6e4cb0..add46eb4 100644 --- a/src/ui/widgets/inspect.h +++ b/src/ui/widgets/inspect.h @@ -50,7 +50,7 @@ class InspectView final : public QDialog Q_OBJECT public: - explicit InspectView( QWidget * parent = 0, Qt::WindowFlags f = 0 ); + explicit InspectView( QWidget * parent = 0, Qt::WindowFlags f = Qt::Widget ); ~InspectView(); QSize minimumSizeHint() const override final { return { 50, 50 }; } diff --git a/src/ui/widgets/nifcheckboxlist.cpp b/src/ui/widgets/nifcheckboxlist.cpp index f60fca7a..ca4e24d9 100644 --- a/src/ui/widgets/nifcheckboxlist.cpp +++ b/src/ui/widgets/nifcheckboxlist.cpp @@ -249,7 +249,7 @@ void NifCheckBoxList::parseText( const QString & text ) if ( !text.isEmpty() ) { // Build RegEx for efficient search. Then set model to match QString str; - QStringList list = text.split( QRegularExpression( "\\s*\\|\\s*" ), QString::SkipEmptyParts ); + QStringList list = text.split( QRegularExpression( "\\s*\\|\\s*" ), Qt::SkipEmptyParts ); QStringListIterator lit( list ); while ( lit.hasNext() ) { diff --git a/src/ui/widgets/nifview.cpp b/src/ui/widgets/nifview.cpp index 61e55e08..491e44a2 100644 --- a/src/ui/widgets/nifview.cpp +++ b/src/ui/widgets/nifview.cpp @@ -44,6 +44,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include "gamemanager.h" + NifTreeView::NifTreeView( QWidget * parent, Qt::WindowFlags flags ) : QTreeView() { Q_UNUSED( flags ); @@ -102,7 +104,7 @@ void NifTreeView::setRowHiding( bool show ) } -bool NifTreeView::isRowHidden( int r, const QModelIndex & index ) const +bool NifTreeView::isRowHidden( [[maybe_unused]] int r, const QModelIndex & index ) const { const NifItem * item = static_cast( index.internalPointer() ); return isRowHidden( item ); @@ -138,13 +140,6 @@ void NifTreeView::setAllExpanded( const QModelIndex & index, bool e ) } } -QStyleOptionViewItem NifTreeView::viewOptions() const -{ - QStyleOptionViewItem opt = QTreeView::viewOptions(); - opt.showDecorationSelected = true; - return opt; -} - void NifTreeView::copy() { QModelIndex idx = selectionModel()->selectedIndexes().first(); @@ -165,7 +160,7 @@ void NifTreeView::copy() } void NifTreeView::pasteTo( const QModelIndex iDest, const NifValue & srcValue ) -{ +{ // Only run once per row for the correct column if ( iDest.column() != NifModel::ValueCol ) return; @@ -268,8 +263,8 @@ void NifTreeView::pasteArray() ChangeValueCommand::createTransaction(); nif->setState( BaseModel::Processing ); - for ( int i = 0; i < cnt && i < valueClipboard->getValues().size(); i++ ) { - auto iDest = root.child( i, NifModel::ValueCol ); + for ( int i = 0; i < cnt && i < int( valueClipboard->getValues().size() ); i++ ) { + auto iDest = QModelIndex_child( root, i, NifModel::ValueCol ); auto srcValue = valueClipboard->getValues().at( iDest.row() ); pasteTo( iDest, srcValue ); @@ -277,7 +272,7 @@ void NifTreeView::pasteArray() nif->restoreState(); if ( cnt > 0 ) - emit nif->dataChanged( root.child( 0, NifModel::ValueCol ), root.child( cnt - 1, NifModel::ValueCol ) ); + emit nif->dataChanged( QModelIndex_child( root, 0, NifModel::ValueCol ), QModelIndex_child( root, cnt - 1, NifModel::ValueCol ) ); } void NifTreeView::drawBranches( QPainter * painter, const QRect & rect, const QModelIndex & index ) const @@ -406,7 +401,7 @@ void NifTreeView::keyPressEvent( QKeyEvent * e ) nif->setData( newValue, v ); // Change the selected row - selectionModel()->select( parent.child( row, 0 ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); + selectionModel()->select( QModelIndex_child( parent, row ), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); // Add row swap to undo ChangeValueCommand::createTransaction(); @@ -416,13 +411,13 @@ void NifTreeView::keyPressEvent( QKeyEvent * e ) } } - SpellPtr spell = SpellBook::lookup( QKeySequence( e->modifiers() + e->key() ) ); + SpellPtr spell = SpellBook::lookup( QKeySequence( e->modifiers() | e->key() ) ); if ( spell ) { QPersistentModelIndex oldidx; // Clear this on any spell cast to prevent it overriding other paste behavior like block -> link row - // TODO: Value clipboard does not get cleared when using the context menu. + // TODO: Value clipboard does not get cleared when using the context menu. valueClipboard->clear(); if ( model()->inherits( "NifModel" ) ) { diff --git a/src/ui/widgets/nifview.h b/src/ui/widgets/nifview.h index d8c11b3f..1afc20ad 100644 --- a/src/ui/widgets/nifview.h +++ b/src/ui/widgets/nifview.h @@ -47,7 +47,7 @@ class NifTreeView final : public QTreeView public: //! Constructor - NifTreeView( QWidget * parent = 0, Qt::WindowFlags flags = 0 ); + NifTreeView( QWidget * parent = 0, Qt::WindowFlags flags = Qt::Widget ); //! Destructor ~NifTreeView(); @@ -102,8 +102,6 @@ protected slots: void mouseReleaseEvent( QMouseEvent * event ) override final; void mouseMoveEvent( QMouseEvent * event ) override final; - QStyleOptionViewItem viewOptions() const override final; - void autoExpandBlock( const QModelIndex & blockIndex ); void autoExpandItem( const NifItem * item ); diff --git a/src/ui/widgets/uvedit.cpp b/src/ui/widgets/uvedit.cpp index 7b97f777..5609e117 100644 --- a/src/ui/widgets/uvedit.cpp +++ b/src/ui/widgets/uvedit.cpp @@ -673,7 +673,7 @@ void UVWidget::mouseMoveEvent( QMouseEvent * e ) } break; - case Qt::MidButton: + case Qt::MiddleButton: pos += zoom * QPointF( dPos.x(), -dPos.y() ); updateViewRect( width(), height() ); @@ -859,7 +859,7 @@ bool UVWidget::setNifData( NifModel * nifModel, const QModelIndex & nifIndex ) } if ( nif->blockInherits( iShapeData, "NiTriBasedGeomData" ) ) { - iTexCoords = nif->getIndex( iShapeData, "UV Sets" ).child( 0, 0 ); + iTexCoords = QModelIndex_child( nif->getIndex( iShapeData, "UV Sets" ) ); if ( !iTexCoords.isValid() || !nif->rowCount( iTexCoords ) ) { return false; @@ -901,7 +901,7 @@ bool UVWidget::setNifData( NifModel * nifModel, const QModelIndex & nifIndex ) if ( iTexSource.isValid() ) { currentCoordSet = nif->get( iTex, "UV Set" ); - iTexCoords = nif->getIndex( iShapeData, "UV Sets" ).child( currentCoordSet, 0 ); + iTexCoords = QModelIndex_child( nif->getIndex( iShapeData, "UV Sets" ), currentCoordSet ); texsource = iTexSource; if ( setTexCoords() ) @@ -939,7 +939,7 @@ bool UVWidget::setNifData( NifModel * nifModel, const QModelIndex & nifIndex ) QModelIndex iTextures = nif->getIndex( iTexSource, "Textures" ); if ( iTextures.isValid() ) { - texfile = TexCache::find( nif->get( iTextures.child( 0, 0 ) ), game ); + texfile = TexCache::find( nif->get( QModelIndex_child( iTextures ) ), game ); return true; } } @@ -978,7 +978,7 @@ bool UVWidget::setTexCoords() return false; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) { - tris += triangulate( nif->getArray( iPoints.child( r, 0 ) ) ); + tris += triangulate( nif->getArray( QModelIndex_child( iPoints, r ) ) ); } } else if ( nif->blockInherits( iShape, "BSTriShape" ) ) { if ( !isDataOnSkin ) { @@ -1564,7 +1564,7 @@ void UVWidget::selectTexSlot() if ( iTexSource.isValid() ) { currentCoordSet = nif->get( iTex, "UV Set" ); - iTexCoords = nif->getIndex( iShapeData, "UV Sets" ).child( currentCoordSet, 0 ); + iTexCoords = QModelIndex_child( nif->getIndex( iShapeData, "UV Sets" ), currentCoordSet ); texsource = iTexSource; setTexCoords(); updateGL(); @@ -1620,7 +1620,7 @@ void UVWidget::changeCoordSet( int setToUse ) currentCoordSet = setToUse; nif->set( iTex, "UV Set", currentCoordSet ); // read new coordinate set - iTexCoords = nif->getIndex( iShapeData, "UV Sets" ).child( currentCoordSet, 0 ); + iTexCoords = QModelIndex_child( nif->getIndex( iShapeData, "UV Sets" ), currentCoordSet ); setTexCoords(); } @@ -1638,7 +1638,7 @@ void UVWidget::duplicateCoordSet() nif->set( iShapeData, "Data Flags", numUvSets ); QModelIndex uvSets = nif->getIndex( iShapeData, "UV Sets" ); nif->updateArraySize( uvSets ); - nif->setArray( uvSets.child( numUvSets, 0 ), nif->getArray( uvSets.child( currentCoordSet, 0 ) ) ); + nif->setArray( QModelIndex_child( uvSets, numUvSets ), nif->getArray( QModelIndex_child( uvSets, currentCoordSet ) ) ); // switch to that coordinate set changeCoordSet( numUvSets ); // reconnect data changed signal diff --git a/src/ui/widgets/valueedit.cpp b/src/ui/widgets/valueedit.cpp index bbc3604c..8435103e 100644 --- a/src/ui/widgets/valueedit.cpp +++ b/src/ui/widgets/valueedit.cpp @@ -81,7 +81,7 @@ UnsignedValidator::UnsignedValidator( QObject * parent ) { } -QValidator::State UnsignedValidator::validate( QString & input, int & pos ) const +QValidator::State UnsignedValidator::validate( QString & input, [[maybe_unused]] int & pos ) const { if ( input.trimmed().isEmpty() || input.trimmed() == QLatin1String( "0x" ) ) return Intermediate; @@ -528,7 +528,7 @@ void ValueEdit::resizeEvent( QResizeEvent * ) ColorEdit::ColorEdit( QWidget * parent ) : ValueEdit( parent ) { QHBoxLayout * lay = new QHBoxLayout; - lay->setMargin( 0 ); + lay->setContentsMargins( 0, 0, 0, 0 ); lay->setSpacing( 0 ); setLayout( lay ); @@ -603,7 +603,7 @@ Color3 ColorEdit::getColor3() const VectorEdit::VectorEdit( QWidget * parent ) : ValueEdit( parent ) { QHBoxLayout * lay = new QHBoxLayout( this ); - lay->setMargin( 0 ); + lay->setContentsMargins( 0, 0, 0, 0 ); lay->setSpacing( 0 ); CenterLabel * xl, * yl; @@ -703,7 +703,7 @@ RotationEdit::RotationEdit( QWidget * parent ) : ValueEdit( parent ), mode( mAut btMode->setDefaultAction( actMode ); QHBoxLayout * lay = new QHBoxLayout( this ); - lay->setMargin( 0 ); + lay->setContentsMargins( 0, 0, 0, 0 ); lay->setSpacing( 0 ); lay->addWidget( btMode, 2 ); @@ -883,7 +883,7 @@ void RotationEdit::sltChanged() TriangleEdit::TriangleEdit( QWidget * parent ) : ValueEdit( parent ) { QHBoxLayout * lay = new QHBoxLayout( this ); - lay->setMargin( 0 ); + lay->setContentsMargins( 0, 0, 0, 0 ); lay->setSpacing( 0 ); lay->addWidget( v1 = new QSpinBox ); diff --git a/src/ui/widgets/xmlcheck.cpp b/src/ui/widgets/xmlcheck.cpp index d7a19c1a..57d4298b 100644 --- a/src/ui/widgets/xmlcheck.cpp +++ b/src/ui/widgets/xmlcheck.cpp @@ -26,6 +26,8 @@ #include #include +#include "gamemanager.h" + #define NUM_THREADS 4 @@ -77,7 +79,7 @@ TestShredder::TestShredder() valueOps->setCurrentIndex(0); QString op_tip; - for ( const auto t : ops_ord ) + for ( const auto & t : ops_ord ) op_tip += QString("%1\t%2\r\n").arg(t).arg(ops[t].second); valueOps->setToolTip(op_tip); @@ -280,7 +282,7 @@ void TestShredder::threadStarted() void TestShredder::threadFinished() { - uint32_t finishedThreads = 0; + std::uint32_t finishedThreads = 0; if ( queue.isEmpty() ) { for ( TestThread * thread : threads ) { if ( thread->isRunning() ) @@ -296,7 +298,7 @@ void TestShredder::threadFinished() if ( thread->isFinished() ) finishedThreads++; } - if ( finishedThreads == threads.count() ) + if ( qsizetype( finishedThreads ) == threads.count() ) text->append(tr("Completed with %1 errors.").arg(errorCount)); } } @@ -478,7 +480,7 @@ void TestThread::run() bool isInt = value.isCount() && !value.isFloat(); bool isStr = value.isString() || value.type() == NifValue::tStringIndex || value.isFloat(); - auto asInt = value.toCount( nullptr, nullptr); + qint64 asInt = qint64( value.toCount( nullptr, nullptr) ); auto asStr = ( value.type() == NifValue::tStringIndex ) ? nif.resolveString(nameIdx) : value.toString(); bool current_match = false; @@ -604,7 +606,7 @@ QList TestThread::checkLinks( const NifModel * nif, const QModelInd QList messages; for ( int r = 0; r < nif->rowCount( iParent ); r++ ) { - QModelIndex idx = iParent.child( r, 0 ); + QModelIndex idx = QModelIndex_child( iParent, r ); if ( nif->isLink( idx ) ) { qint32 l = nif->getLink( idx ); diff --git a/src/version.cpp b/src/version.cpp index 80c2bfed..61924619 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -93,7 +93,7 @@ int NifSkopeVersion::hexVersion( QList majMinRev ) { // This can only work up to but not including 32-bit values // i.e. in this case a 4th value ( n << 24 ) is possible - // but I've decided to leave it as 3 parts only, to reflect + // but I've decided to leave it as 3 parts only, to reflect // Qt's own QT_VERSION_CHECK macro. // // Granularity past MAJ.MIN.REV will require a NifSkopeVersion object @@ -233,7 +233,7 @@ QString NifSkopeVersion::rawToMajMin( const QString & ver ) QList NifSkopeVersion::versionParts( const QString & ver, int parts /* = 7 */ ) { QList verList; - + if ( formatVersion( ver, verList, parts ) ) return verList; @@ -317,7 +317,7 @@ bool NifSkopeVersion::formatVersion( const QString & ver, QList & verNums, // Check if Revision has an a, b, rc appended bool isFinal; rev.toInt( &isFinal ); - if ( !isFinal && rev >= 0 ) { + if ( !isFinal ) { // Pre-Release Build QStringList revParts; // "0a1" -> ("0", "1") QString revPart; // "0a1" -> "0" @@ -347,7 +347,7 @@ bool NifSkopeVersion::formatVersion( const QString & ver, QList & verNums, // Splitting at stagePart gives you a list with the rev and stageVer // e.g. "0a1" becomes ("0", "1") - revParts = rev.split( stagePart, QString::SkipEmptyParts ); + revParts = rev.split( stagePart, Qt::SkipEmptyParts ); // This is the revision number without e.g. "a1" appended revPart = revParts.value( 0, "0" ); // This is the version of the Alpha/Beta/RC diff --git a/src/xml/kfmxml.cpp b/src/xml/kfmxml.cpp index 5e0d597a..f2bba8fc 100644 --- a/src/xml/kfmxml.cpp +++ b/src/xml/kfmxml.cpp @@ -37,6 +37,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // QXmlDefaultHandler Inherited #include #include +#include #define err( X ) { errorStr = X; return false; } diff --git a/src/xml/nifxml.cpp b/src/xml/nifxml.cpp index a0051b0e..87fb6fa3 100644 --- a/src/xml/nifxml.cpp +++ b/src/xml/nifxml.cpp @@ -38,6 +38,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include // QXmlDefaultHandler Inherited #include #include +#include //! \file nifxml.cpp NifXmlHandler, NifModel XML @@ -195,10 +196,11 @@ class NifXmlHandler final : public QXmlDefaultHandler if ( x == tagToken ) tags.insert( list.value( "name" ), tagTokenTag ); - if ( x == tagNone ) + if ( x == tagNone ) { x = tags.value( tagid ); if ( x == tagNone ) err( tr( "error unknown element '%1'" ).arg( tagid ) ); + } if ( depth == 0 ) { if ( x != tagFile ) @@ -327,6 +329,7 @@ class NifXmlHandler final : public QXmlDefaultHandler if ( x != tagAdd ) err( tr( "only field tags allowed in struct type declaration" ) ); + [[fallthrough]]; case tagBlock: push( x ); @@ -464,6 +467,8 @@ class NifXmlHandler final : public QXmlDefaultHandler case tagAddDefault: // Subclass defaults break; + default: + break; } break; case tagEnum: @@ -556,6 +561,7 @@ class NifXmlHandler final : public QXmlDefaultHandler NifValue::setTypeDescription( blk->id, blk->text ); else if ( !typId.isEmpty() && !typTxt.isEmpty() ) NifValue::setTypeDescription( typId, typTxt ); + [[fallthrough]]; case tagBlock: if ( blk ) {