Browse Source

update// addec chatmodel.h chatmodel.cpp to realize the whole chat history

hushchat
Strider 4 years ago
parent
commit
22cc122120
  1. 6
      silentdragon-lite.pro
  2. 49
      src/chatmodel.cpp
  3. 94
      src/chatmodel.h

6
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 \

49
src/chatmodel.cpp

@ -0,0 +1,49 @@
#include "chatmodel.h"
ChatModel::ChatModel(std::map<long, ChatItem> chatItems)
{
this->chatItems = chatItems;
}
ChatModel::ChatModel(std::vector<ChatItem> chatItems)
{
this->setItems(chatItems);
}
std::map<long, ChatItem> ChatModel::getItems()
{
return this->chatItems;
}
void ChatModel::setItems(std::map<long, ChatItem> items)
{
this->chatItems = chatItems;
}
void ChatModel::setItems(std::vector<ChatItem> items)
{
for(ChatItem c : items)
{
this->chatItems[c.getTimestamp()] = c;
}
}
void ChatModel::renderChatBox(QListView &view)
{
for(ChatItem c : items)
{
view.getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
}
//todo render items to view
}
void ChatModel::renderChatBox(QListView *view)
{
for(ChatItem c : items)
{
view->getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
}
//todo render items to view
}

94
src/chatmodel.h

@ -0,0 +1,94 @@
#include <string>
#include <map>
#include <vector>
#include <QListView>
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<long, ChatItem> chatItems;
public:
ChatModel() {};
ChatModel(std::map<long, ChatItem> chatItems);
ChatModel(std::vector<ChatItem> chatItems);
std::map<long, ChatItem> getItems();
void setItems(std::map<long, ChatItem> items);
void setItems(std::vector<ChatItem> items);
void renderChatBox(QListView &view);
void renderChatBox(QListView *view);
};
Loading…
Cancel
Save