00001 #include "CommandHistory.h" 00002 #include <QJsonObject> 00003 #include <QJsonArray> 00004 00005 namespace Elve { 00006 00007 using namespace std; 00008 00009 CommandHistory::CommandHistory() 00010 { 00011 } 00012 00013 CommandHistory::CommandHistory(const QJsonValue& json) 00014 { 00015 QJsonArray arr = json.toObject().value("cmds").toArray(); 00016 for(const QJsonValue& v : arr) { 00017 mCmds.push_back(v.toString().toStdString()); 00018 } 00019 } 00020 00021 CommandHistory::CommandHistory(const CommandHistory& before) : mCmds(before.mCmds) 00022 { 00023 } 00024 00025 void CommandHistory::add(const std::string& cmd) 00026 { 00027 mCmds.push_back(cmd); 00028 } 00029 00030 void CommandHistory::pop() 00031 { 00032 mCmds.pop_back(); 00033 } 00034 00035 const std::string& CommandHistory::last() const 00036 { 00037 return mCmds.back(); 00038 } 00039 00040 QJsonValue CommandHistory::json() const 00041 { 00042 QJsonObject obj; 00043 QJsonArray cmdarray; 00044 std::string cmds; 00045 for(const string& cmd : mCmds) { 00046 cmdarray.append(cmd.c_str()); 00047 cmds += ";" + cmd; 00048 } 00049 obj.insert("cmds",cmdarray); 00050 obj.insert("oneline",cmds.c_str()); 00051 return obj; 00052 } 00053 00054 }