From 22cc12212002af83b68f254aedbd1b9d20898546 Mon Sep 17 00:00:00 2001 From: Strider Date: Sun, 26 Apr 2020 21:50:49 +0200 Subject: [PATCH] update// addec chatmodel.h chatmodel.cpp to realize the whole chat history --- silentdragon-lite.pro | 6 ++- src/chatmodel.cpp | 49 ++++++++++++++++++++++ src/chatmodel.h | 94 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 src/chatmodel.cpp create mode 100644 src/chatmodel.h diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index e8c50d5..b692159 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -67,7 +67,8 @@ SOURCES += \ src/liteinterface.cpp \ src/camount.cpp \ src/chatbubbleme.cpp \ - src/chatbubblepartner.cpp + src/chatbubblepartner.cpp \ + src/chatmodel.cpp HEADERS += \ src/firsttimewizard.h \ @@ -98,7 +99,8 @@ HEADERS += \ src/camount.h \ lib/silentdragonlitelib.h \ src/chatbubbleme.h \ - src/chatbubblepartner.h + src/chatbubblepartner.h \ + src/chatmodel.h FORMS += \ src/encryption.ui \ diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp new file mode 100644 index 0000000..b65bd4a --- /dev/null +++ b/src/chatmodel.cpp @@ -0,0 +1,49 @@ +#include "chatmodel.h" + +ChatModel::ChatModel(std::map chatItems) +{ + this->chatItems = chatItems; +} + +ChatModel::ChatModel(std::vector chatItems) +{ + this->setItems(chatItems); +} + +std::map ChatModel::getItems() +{ + return this->chatItems; +} + +void ChatModel::setItems(std::map items) +{ + this->chatItems = chatItems; +} + +void ChatModel::setItems(std::vector items) +{ + for(ChatItem c : items) + { + this->chatItems[c.getTimestamp()] = c; + } +} + +void ChatModel::renderChatBox(QListView &view) +{ + for(ChatItem c : items) + { + view.getItems().add(QString("[Timestamp] : lorem ipsum ....")); + } + + //todo render items to view +} + +void ChatModel::renderChatBox(QListView *view) +{ + for(ChatItem c : items) + { + view->getItems().add(QString("[Timestamp] : lorem ipsum ....")); + } + + //todo render items to view +} \ No newline at end of file diff --git a/src/chatmodel.h b/src/chatmodel.h new file mode 100644 index 0000000..5dd8904 --- /dev/null +++ b/src/chatmodel.h @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +class ChatItem +{ + private: + long timestamp; + std::string address; + std::string contact; + std::string memo; + bool outgoing = false; + + public: + ChatItem() {} + ChatItem(long timestamp, std::string address, std::string contact, std::string memo); + ChatItem(long timestamp, std::string address, std::string contact, std::string memo, bool outgoing = false); + + long getTimestamp() + { + return this->timestamp; + } + + std::string getAddress() + { + return this->address; + } + + std::string getContact() + { + return this->contact; + } + + std::string getMemo() + { + return this->memo; + } + + bool isOutgoing() + { + return this->outgoing; + } + + void setTimestamp(long timestamp) + { + this->timestamp = timestamp; + } + + void setAddress(std::string address) + { + this->address = address; + } + + void setContact(std::string contact) + { + this->contact = contact; + } + + void setMemo(std::string memo) + { + this->memo = memo; + } + + void toggleOutgo() + { + this->outgoing = true; + } + + ~ChatItem() + { + delete timestamp; + delete address; + delete contact; + delete memo; + delete outgoing; + } +}; + +class ChatModel +{ + private: + std::map chatItems; + + public: + ChatModel() {}; + ChatModel(std::map chatItems); + ChatModel(std::vector chatItems); + std::map getItems(); + void setItems(std::map items); + void setItems(std::vector items); + void renderChatBox(QListView &view); + void renderChatBox(QListView *view); +}; \ No newline at end of file