]> Some of my projects - anidbudpclient.git/commitdiff
Add model for viewing commands sent by the client. That is commands, which were sent...
authorAPTX <marek321@gmail.com>
Mon, 11 Oct 2010 14:57:51 +0000 (16:57 +0200)
committerAPTX <marek321@gmail.com>
Mon, 11 Oct 2010 14:57:51 +0000 (16:57 +0200)
anidbudpclient.pro
clientcommandmodel.cpp [new file with mode: 0644]
clientcommandmodel.h [new file with mode: 0644]

index eabee97cce7270052230e15a529e5e3cf6a5713f..8023a9730e5b94b88d4fa1b972142169831b3a08 100644 (file)
@@ -1,61 +1,63 @@
-# -------------------------------------------------
-# Project created by QtCreator 2009-03-22T14:53:52
-# -------------------------------------------------
-QT += network \
-    script
-QT -= gui
-TEMPLATE = lib
-TARGET = anidbudpclient
-static { 
-    message(anidbpudpclinet: Static build)
-       DESTDIR = build-static
-}
-!static { 
-    message(anidbpudpclinet: Dynamic build)
-       DESTDIR = build
-}
-INCLUDEPATH += $$PWD
-DEPENDPATH += $$PWD
-DEFINES += ANIDBUDPCLIENT_LIBRARY
-SOURCES += client.cpp \
-    abstractcommand.cpp \
-    authcommand.cpp \
-    rawcommand.cpp \
-    mylistaddcommand.cpp \
-    logoutcommand.cpp \
-    uptimecommand.cpp \
-       mylistcommand.cpp \
-       filecommand.cpp \
-       votecommand.cpp \
-       file.cpp \
-    hash.cpp \
-    hashproducer.cpp \
-       hashconsumer.cpp
-
-HEADERS += client.h \
-    anidbudpclient_global.h \
-    abstractcommand.h \
-    authcommand.h \
-    rawcommand.h \
-    mylistaddcommand.h \
-    logoutcommand.h \
-    uptimecommand.h \
-       mylistcommand.h \
-       filecommand.h \
-       votecommand.h \
-       file.h \
-    hash.h \
-    hashproducer.h \
-    hashconsumer.h \
-       circularbuffer.h
-
-CONV_HEADERS += include/AniDBUdpClient/Client \
-    include/AniDBUdpClient/AbstractCommand \
-    include/AniDBUdpClient/RawCommand \
-    include/AniDBUdpClient/MyListCommand \
-    include/AniDBUdpClient/MyListAddCommand \
-       include/AniDBUdpClient/FileCommand \
-       include/AniDBUdpClient/VoteCommand \
-       include/AniDBUdpClient/UptimeCommand \
-       include/AniDBUdpClient/File \
-       include/AniDBUdpClient/Hash
+# -------------------------------------------------\r
+# Project created by QtCreator 2009-03-22T14:53:52\r
+# -------------------------------------------------\r
+QT += network \\r
+    script\r
+QT -= gui\r
+TEMPLATE = lib\r
+TARGET = anidbudpclient\r
+static { \r
+    message(anidbpudpclinet: Static build)\r
+       DESTDIR = build-static\r
+}\r
+!static { \r
+    message(anidbpudpclinet: Dynamic build)\r
+       DESTDIR = build\r
+}\r
+INCLUDEPATH += $$PWD\r
+DEPENDPATH += $$PWD\r
+DEFINES += ANIDBUDPCLIENT_LIBRARY\r
+SOURCES += client.cpp \\r
+    abstractcommand.cpp \\r
+    authcommand.cpp \\r
+    rawcommand.cpp \\r
+    mylistaddcommand.cpp \\r
+    logoutcommand.cpp \\r
+    uptimecommand.cpp \\r
+       mylistcommand.cpp \\r
+       filecommand.cpp \\r
+       votecommand.cpp \\r
+       file.cpp \\r
+    hash.cpp \\r
+    hashproducer.cpp \\r
+       hashconsumer.cpp \\r
+    clientcommandmodel.cpp\r
+\r
+HEADERS += client.h \\r
+    anidbudpclient_global.h \\r
+    abstractcommand.h \\r
+    authcommand.h \\r
+    rawcommand.h \\r
+    mylistaddcommand.h \\r
+    logoutcommand.h \\r
+    uptimecommand.h \\r
+       mylistcommand.h \\r
+       filecommand.h \\r
+       votecommand.h \\r
+       file.h \\r
+    hash.h \\r
+    hashproducer.h \\r
+    hashconsumer.h \\r
+       circularbuffer.h \\r
+    clientcommandmodel.h\r
+\r
+CONV_HEADERS += include/AniDBUdpClient/Client \\r
+    include/AniDBUdpClient/AbstractCommand \\r
+    include/AniDBUdpClient/RawCommand \\r
+    include/AniDBUdpClient/MyListCommand \\r
+    include/AniDBUdpClient/MyListAddCommand \\r
+       include/AniDBUdpClient/FileCommand \\r
+       include/AniDBUdpClient/VoteCommand \\r
+       include/AniDBUdpClient/UptimeCommand \\r
+       include/AniDBUdpClient/File \\r
+       include/AniDBUdpClient/Hash\r
diff --git a/clientcommandmodel.cpp b/clientcommandmodel.cpp
new file mode 100644 (file)
index 0000000..8410a97
--- /dev/null
@@ -0,0 +1,89 @@
+#include "clientcommandmodel.h"\r
+\r
+#include "client.h"\r
+\r
+namespace AniDBUdpClient {\r
+\r
+ClientCommandModel::ClientCommandModel(Client *client, QObject *parent) :\r
+       QAbstractTableModel(parent), m_client(client)\r
+{\r
+}\r
+\r
+Client *ClientCommandModel::client() const\r
+{\r
+       return m_client;\r
+}\r
+\r
+void ClientCommandModel::setClient(Client *client)\r
+{\r
+       beginResetModel();\r
+       m_client = client;\r
+       endResetModel();\r
+}\r
+\r
+int ClientCommandModel::rowCount(const QModelIndex &/*parent*/) const\r
+{\r
+       if (!m_client)\r
+               return 0;\r
+       return m_client->sentCommands.count();\r
+}\r
+\r
+int ClientCommandModel::columnCount(const QModelIndex &/*parent*/) const\r
+{\r
+       return 3;\r
+}\r
+\r
+QVariant ClientCommandModel::headerData(int section, Qt::Orientation orientation, int role) const\r
+{\r
+       if (role != Qt::DisplayRole)\r
+               return QVariant();\r
+\r
+       if (orientation == Qt::Vertical)\r
+               return section + 1;\r
+\r
+       switch (section)\r
+       {\r
+               case 0:\r
+                       return tr("Time Sent");\r
+               case 1:\r
+                       return tr("Command");\r
+               case 2:\r
+                       return tr("Arguments");\r
+       }\r
+\r
+       return QVariant();\r
+}\r
+\r
+QVariant ClientCommandModel::data(const QModelIndex &index, int role) const\r
+{\r
+       if (role != Qt::DisplayRole)\r
+               return QVariant();\r
+\r
+       AbstractReply *currentReply = m_client->sentCommands[m_client->sentCommandOrder[index.row()]];\r
+\r
+       switch (index.column())\r
+       {\r
+               case 0:\r
+                       return currentReply->timeSent();\r
+               case 1:\r
+                       return currentReply->command().rawCommand().first;\r
+               case 2:\r
+                       return currentReply->command().rawCommand().second;\r
+       }\r
+       return QVariant();\r
+}\r
+\r
+\r
+void ClientCommandModel::commandAdded(int index)\r
+{\r
+       beginInsertRows(QModelIndex(), index, index + 1);\r
+       endInsertRows();\r
+}\r
+\r
+void ClientCommandModel::commandRemoved(int index)\r
+{\r
+       beginRemoveRows(QModelIndex(), index, index + 1);\r
+       endRemoveRows();\r
+}\r
+\r
+} // namespace AniDBUdpClient\r
diff --git a/clientcommandmodel.h b/clientcommandmodel.h
new file mode 100644 (file)
index 0000000..306743e
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef CLIENTCOMMANDMODEL_H\r
+#define CLIENTCOMMANDMODEL_H\r
+\r
+#include "anidbudpclient_global.h"\r
+\r
+#include <QAbstractTableModel>\r
+\r
+namespace AniDBUdpClient {\r
+\r
+class Client;\r
+\r
+class ANIDBUDPCLIENTSHARED_EXPORT ClientCommandModel : public QAbstractTableModel\r
+{\r
+    Q_OBJECT\r
+public:\r
+       explicit ClientCommandModel(Client *client = 0, QObject *parent = 0);\r
+\r
+       Client *client() const;\r
+       void setClient(Client *client);\r
+\r
+       int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
+       int columnCount(const QModelIndex &/*parent*/) const;\r
+\r
+       QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;\r
+       QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;\r
+\r
+signals:\r
+\r
+public slots:\r
+\r
+private:\r
+       void commandAdded(int index);\r
+       void commandRemoved(int index);\r
+\r
+       Client *m_client;\r
+};\r
+\r
+} // namespace AniDBUdpClient\r
+\r
+#endif // CLIENTCOMMANDMODEL_H\r