Commit 7f6611ab authored by ElenaSubbotina's avatar ElenaSubbotina

..

parent bb37e348
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "../../DocxFormat/IFileContainer.h" #include "../../DocxFormat/IFileContainer.h"
#include <map> #include <unordered_map>
namespace OOX namespace OOX
{ {
...@@ -74,7 +74,7 @@ namespace OOX ...@@ -74,7 +74,7 @@ namespace OOX
return m_nRow.IsInit() && m_nCol.IsInit() && m_sAuthor.IsInit(); return m_nRow.IsInit() && m_nCol.IsInit() && m_sAuthor.IsInit();
} }
}; };
class CAuthors : public WritingElementWithChilds<std::wstring> class CAuthors : public WritingElement
{ {
public: public:
WritingElement_AdditionConstructors(CAuthors) WritingElement_AdditionConstructors(CAuthors)
...@@ -87,7 +87,7 @@ namespace OOX ...@@ -87,7 +87,7 @@ namespace OOX
} }
virtual void ClearItems() virtual void ClearItems()
{ {
m_arrItems.clear(); m_mapItems.clear();
} }
virtual void fromXML(XmlUtils::CXmlNode& node) virtual void fromXML(XmlUtils::CXmlNode& node)
{ {
...@@ -100,14 +100,11 @@ namespace OOX ...@@ -100,14 +100,11 @@ namespace OOX
{ {
writer.WriteString(L"<authors>"); writer.WriteString(L"<authors>");
for ( SpreadsheetElemArray::const_iterator it = m_arrItems.begin(); it != m_arrItems.end(); it++) for ( std::unordered_map<int, std::wstring>::const_iterator it = m_mapItems.begin(); it != m_mapItems.end(); it++)
{ {
if ( *it ) writer.WriteString(L"<author>");
{ writer.WriteEncodeXmlString(it->second);
writer.WriteString(L"<author>"); writer.WriteString(L"</author>");
writer.WriteEncodeXmlString(*(*it));
writer.WriteString(L"</author>");
}
} }
writer.WriteString(L"</authors>"); writer.WriteString(L"</authors>");
} }
...@@ -118,6 +115,8 @@ namespace OOX ...@@ -118,6 +115,8 @@ namespace OOX
if ( oReader.IsEmptyNode() ) if ( oReader.IsEmptyNode() )
return; return;
int index = 0;
int nCurDepth = oReader.GetDepth(); int nCurDepth = oReader.GetDepth();
while( oReader.ReadNextSiblingNode( nCurDepth ) ) while( oReader.ReadNextSiblingNode( nCurDepth ) )
{ {
...@@ -125,8 +124,7 @@ namespace OOX ...@@ -125,8 +124,7 @@ namespace OOX
if ( L"author" == sName ) if ( L"author" == sName )
{ {
std::wstring *str = new std::wstring(oReader.GetText3()); m_mapItems.insert(std::make_pair(index++, oReader.GetText3()));
m_arrItems.push_back(str);
} }
} }
} }
...@@ -140,6 +138,8 @@ namespace OOX ...@@ -140,6 +138,8 @@ namespace OOX
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader) void ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{ {
} }
public:
std::unordered_map<int, std::wstring> m_mapItems;
}; };
class CComment : public WritingElement class CComment : public WritingElement
{ {
......
...@@ -189,7 +189,7 @@ namespace OOX ...@@ -189,7 +189,7 @@ namespace OOX
} }
void PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing) void PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing)
{ {
std::list<std::wstring*> & aAuthors = pComments->m_oAuthors->m_arrItems; std::unordered_map<int, std::wstring> & mapAuthors = pComments->m_oAuthors->m_mapItems;
if(pComments->m_oCommentList.IsInit()) if(pComments->m_oCommentList.IsInit())
{ {
...@@ -212,12 +212,12 @@ namespace OOX ...@@ -212,12 +212,12 @@ namespace OOX
unsigned int nAuthorId = pComment->m_oAuthorId->GetValue(); unsigned int nAuthorId = pComment->m_oAuthorId->GetValue();
std::list<std::wstring*>::iterator itA = aAuthors.begin(); std::unordered_map<int, std::wstring>::iterator pFind = mapAuthors.find(nAuthorId);
for(int a = 0; a < nAuthorId; a++)
itA++; if (pFind != mapAuthors.end())
{
if(itA != aAuthors.end()) pCommentItem->m_sAuthor = pFind->second;
pCommentItem->m_sAuthor = *itA; }
OOX::Spreadsheet::CSi* pSi = pComment->m_oText.GetPointerEmptyNullable(); OOX::Spreadsheet::CSi* pSi = pComment->m_oText.GetPointerEmptyNullable();
if(NULL != pSi) if(NULL != pSi)
......
...@@ -2535,14 +2535,14 @@ namespace BinXlsxRW { ...@@ -2535,14 +2535,14 @@ namespace BinXlsxRW {
{ {
m_pCurVmlDrawing->m_mapComments = &m_pCurWorksheet->m_mapComments; m_pCurVmlDrawing->m_mapComments = &m_pCurWorksheet->m_mapComments;
std::map<std::wstring, unsigned int> mapAuthors; std::map<std::wstring, unsigned int> mapByAuthors;
OOX::Spreadsheet::CComments* pComments = new OOX::Spreadsheet::CComments(); OOX::Spreadsheet::CComments* pComments = new OOX::Spreadsheet::CComments();
pComments->m_oCommentList.Init(); pComments->m_oCommentList.Init();
std::list<OOX::Spreadsheet::CComment*>& aComments = pComments->m_oCommentList->m_arrItems; std::list<OOX::Spreadsheet::CComment*>& aComments = pComments->m_oCommentList->m_arrItems;
pComments->m_oAuthors.Init(); pComments->m_oAuthors.Init();
std::list<std::wstring*>& aAuthors = pComments->m_oAuthors->m_arrItems; std::unordered_map<int, std::wstring> & mapByIndex = pComments->m_oAuthors->m_mapItems;
for (std::map<std::wstring, OOX::Spreadsheet::CCommentItem*>::const_iterator it = m_pCurWorksheet->m_mapComments.begin(); it != m_pCurWorksheet->m_mapComments.end(); ++it) for (std::map<std::wstring, OOX::Spreadsheet::CCommentItem*>::const_iterator it = m_pCurWorksheet->m_mapComments.begin(); it != m_pCurWorksheet->m_mapComments.end(); ++it)
{ {
...@@ -2559,15 +2559,18 @@ namespace BinXlsxRW { ...@@ -2559,15 +2559,18 @@ namespace BinXlsxRW {
if(pCommentItem->m_sAuthor.IsInit()) if(pCommentItem->m_sAuthor.IsInit())
{ {
const std::wstring& sAuthor = pCommentItem->m_sAuthor.get(); const std::wstring& sAuthor = pCommentItem->m_sAuthor.get();
std::map<std::wstring, unsigned int>::const_iterator pair = mapAuthors.find(sAuthor); std::map<std::wstring, unsigned int>::const_iterator pFind = mapByAuthors.find(sAuthor);
int nAuthorId; int nAuthorId;
if(mapAuthors.end() != pair) if(pFind != mapByAuthors.end())
nAuthorId = (int)pair->second; nAuthorId = pFind->second;
else else
{ {
nAuthorId = (int)mapAuthors.size(); nAuthorId = (int)mapByAuthors.size();
mapAuthors[sAuthor] = nAuthorId;
aAuthors.push_back(new std::wstring(sAuthor)); mapByAuthors.insert(std::make_pair(sAuthor, nAuthorId));
mapByIndex.insert(std::make_pair(nAuthorId, sAuthor));
} }
pNewComment->m_oAuthorId.Init(); pNewComment->m_oAuthorId.Init();
pNewComment->m_oAuthorId->SetValue(nAuthorId); pNewComment->m_oAuthorId->SetValue(nAuthorId);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment