fix tags order (#141)

This commit is contained in:
mniip 2013-11-11 23:14:05 +04:00
parent 186f8a1742
commit 4b914d12c2
7 changed files with 42 additions and 32 deletions

View File

@ -1691,7 +1691,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
json::Number tempVersion = objDocument["Version"];
json::Array tagsArray = objDocument["Tags"];
std::vector<std::string> tempTags;
std::list<std::string> tempTags;
for(int j = 0; j < tagsArray.Size(); j++)
{
@ -1767,7 +1767,7 @@ RequestBroker::Request * Client::GetSaveAsync(int saveID, int saveDate)
json::Number tempVersion = objDocument["Version"];
json::Array tagsArray = objDocument["Tags"];
std::vector<std::string> tempTags;
std::list<std::string> tempTags;
for(int j = 0; j < tagsArray.Size(); j++)
{
@ -2205,10 +2205,10 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate)
return NULL;
}
std::vector<std::string> * Client::RemoveTag(int saveID, std::string tag)
std::list<std::string> * Client::RemoveTag(int saveID, std::string tag)
{
lastError = "";
std::vector<std::string> * tags = NULL;
std::list<std::string> * tags = NULL;
std::stringstream urlStream;
char * data = NULL;
int dataStatus, dataLength;
@ -2243,7 +2243,7 @@ std::vector<std::string> * Client::RemoveTag(int saveID, std::string tag)
{
json::Array tagsArray = responseObject["Tags"];
tags = new std::vector<std::string>();
tags = new std::list<std::string>();
for(int j = 0; j < tagsArray.Size(); j++)
{
@ -2266,10 +2266,10 @@ std::vector<std::string> * Client::RemoveTag(int saveID, std::string tag)
return tags;
}
std::vector<std::string> * Client::AddTag(int saveID, std::string tag)
std::list<std::string> * Client::AddTag(int saveID, std::string tag)
{
lastError = "";
std::vector<std::string> * tags = NULL;
std::list<std::string> * tags = NULL;
std::stringstream urlStream;
char * data = NULL;
int dataStatus, dataLength;
@ -2304,7 +2304,7 @@ std::vector<std::string> * Client::AddTag(int saveID, std::string tag)
{
json::Array tagsArray = responseObject["Tags"];
tags = new std::vector<std::string>();
tags = new std::list<std::string>();
for(int j = 0; j < tagsArray.Size(); j++)
{

View File

@ -160,8 +160,8 @@ public:
RequestStatus FavouriteSave(int saveID, bool favourite);
void SetAuthUser(User user);
User GetAuthUser();
std::vector<std::string> * RemoveTag(int saveID, std::string tag); //TODO RequestStatus
std::vector<std::string> * AddTag(int saveID, std::string tag);
std::list<std::string> * RemoveTag(int saveID, std::string tag); //TODO RequestStatus
std::list<std::string> * AddTag(int saveID, std::string tag);
std::string GetLastError() {
return lastError;
}

View File

@ -13,11 +13,13 @@ SaveInfo::SaveInfo(SaveInfo & save):
votesDown(save.votesDown),
gameSave(NULL),
vote(save.vote),
tags(save.tags),
Comments(save.Comments),
Views(save.Views),
Version(save.Version)
{
std::list<std::string> tagsSorted = save.tags;
tagsSorted.sort();
tags=tagsSorted;
if(save.gameSave)
gameSave = new GameSave(*save.gameSave);
}
@ -41,7 +43,7 @@ SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string
}
SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::vector<std::string> tags_):
SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list<std::string> tags_):
id(_id),
votesUp(_votesUp),
votesDown(_votesDown),
@ -52,12 +54,13 @@ SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote,
Published(published_),
gameSave(NULL),
vote(_vote),
tags(tags_),
Comments(0),
Views(0),
Version(0)
{
std::list<std::string> tagsSorted = tags_;
tagsSorted.sort();
tags=tagsSorted;
}
SaveInfo::~SaveInfo()
@ -150,11 +153,14 @@ int SaveInfo::GetVersion()
return Version;
}
void SaveInfo::SetTags(std::vector<std::string> tags)
void SaveInfo::SetTags(std::list<std::string> tags)
{
this->tags = tags;
std::list<std::string> tagsSorted = tags;
tagsSorted.sort();
this->tags=tagsSorted;
}
std::vector<std::string> SaveInfo::GetTags()
std::list<std::string> SaveInfo::GetTags()
{
return tags;
}

View File

@ -1,6 +1,7 @@
#ifndef SAVE_H
#define SAVE_H
#include <list>
#include <vector>
#include <string>
#include <stdlib.h>
@ -26,7 +27,7 @@ public:
SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string _userName, std::string _name);
SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::vector<std::string> tags);
SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list<std::string> tags);
~SaveInfo();
@ -35,7 +36,7 @@ public:
std::string Description;
std::vector<std::string> tags;
std::list<std::string> tags;
int vote;
@ -68,8 +69,8 @@ public:
void SetVersion(int version);
int GetVersion();
void SetTags(std::vector<std::string> tags);
std::vector<std::string> GetTags();
void SetTags(std::list<std::string> tags);
std::list<std::string> GetTags();
GameSave * GetGameSave();
void SetGameSave(GameSave * gameSave);

View File

@ -909,14 +909,14 @@ void GameView::NotifySaveChanged(GameModel * sender)
if(sender->GetSave()->GetID())
{
std::stringstream tagsStream;
std::vector<string> tags = sender->GetSave()->GetTags();
std::list<string> tags = sender->GetSave()->GetTags();
if(tags.size())
{
for(int i = 0; i < tags.size(); i++)
for(std::list<std::string>::const_iterator iter = tags.begin(), begin = tags.begin(), end = tags.end(); iter != end; iter++)
{
tagsStream << sender->GetSave()->GetTags()[i];
if(i < tags.size()-1)
if(iter != begin)
tagsStream << " ";
tagsStream << *iter;
}
tagSimulationButton->SetText(tagsStream.str());
}

View File

@ -25,10 +25,10 @@ void TagsModel::RemoveTag(std::string tag)
{
if(save)
{
std::vector<std::string> * tags = Client::Ref().RemoveTag(save->GetID(), tag);
std::list<std::string> * tags = Client::Ref().RemoveTag(save->GetID(), tag);
if(tags)
{
save->SetTags(std::vector<std::string>(*tags));
save->SetTags(std::list<std::string>(*tags));
notifyTagsChanged();
delete tags;
}
@ -43,10 +43,10 @@ void TagsModel::AddTag(std::string tag)
{
if(save)
{
std::vector<std::string> * tags = Client::Ref().AddTag(save->GetID(), tag);
std::list<std::string> * tags = Client::Ref().AddTag(save->GetID(), tag);
if(tags)
{
save->SetTags(std::vector<std::string>(*tags));
save->SetTags(std::list<std::string>(*tags));
notifyTagsChanged();
delete tags;
}

View File

@ -104,9 +104,11 @@ void TagsView::NotifyTagsChanged(TagsModel * sender)
if(sender->GetSave())
{
for(int i = 0; i < sender->GetSave()->GetTags().size(); i++)
std::list<std::string> Tags = sender->GetSave()->GetTags();
int i = 0;
for(std::list<std::string>::const_iterator iter = Tags.begin(), begin = Tags.begin(), end = Tags.end(); iter != end; iter++)
{
ui::Label * tempLabel = new ui::Label(ui::Point(35, 35+(16*i)), ui::Point(120, 16), sender->GetSave()->GetTags()[i]);
ui::Label * tempLabel = new ui::Label(ui::Point(35, 35+(16*i)), ui::Point(120, 16), *iter);
tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
tags.push_back(tempLabel);
AddComponent(tempLabel);
@ -119,10 +121,11 @@ void TagsView::NotifyTagsChanged(TagsModel * sender)
tempButton->Appearance.Margin.Top += 2;
tempButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
tempButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
tempButton->SetActionCallback(new DeleteTagAction(this, sender->GetSave()->GetTags()[i]));
tempButton->SetActionCallback(new DeleteTagAction(this, *iter));
tags.push_back(tempButton);
AddComponent(tempButton);
}
i++;
}
}
}