#ifndef ENTITYWIDGET_H
#define ENTITYWIDGET_H

#include <QWidget>
#include "tcpsocket.h"
#include "databasestruct.h"

class QVBoxLayout;
class QHBoxLayout;
class QLabel;
class QPushButton;
class QLineEdit;
class QTreeView;
class QToolButton;
class QMenu;
class QAction;

class LightPoint;
class SwitchButton;
class TreeModel;
class TreeItem;

class TcpSocket;

class EntityWidget : public QWidget
{
    Q_OBJECT
public:
    EntityWidget(QWidget* parent = nullptr);


signals:
    void allEntityInfo(QList<Entity> entityList);
    void allLongitudeLatitudeAltitude(QList<MoveEntity> list);

    void entityVisible(const QString& id, bool visible);

    void entityLocation(const QString& id);
    void entityRouteVisible(const QString& id);
    void entityNameVisible(const QString& id);
    void entityFocusing(const QString& id);
protected:

private:
    void initUI();
    void connects();

    bool connectServerConditionJudge();

public slots:
    void connectServer();
    void disConnectServer();

    void readMessage();

    void displaySocketError(QAbstractSocket::SocketError);

    void updateEntity();

    void parsingData(const QString& data);

private slots:
    void onTreeDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);;

    void showMenu(const QPoint &point);

    void actionTriggered(QAction *action);

private:
    QVBoxLayout* mMainVLayout;

    QHBoxLayout* mHostHLayout;
    QLabel* mLabelHost;
    QLineEdit* mLineEditHost;
    QHBoxLayout* mPortHLayout;
    QLabel* mLabelPort;
    QLineEdit* mLineEditPort;
    LightPoint* mLightPoint;

    QHBoxLayout* mControlHLayout;
    SwitchButton* mSwitchButton;
    QToolButton* mUpdateEntityButton;

    QTreeView* mEntityTreeView;
    TreeModel* mEntityTreeModel;
    TreeItem* mEntityTreeRootItem;

    QMenu* mEntityContentMenu;
    QAction* mEntityLocationAction;
    QAction* mEntityRouteVisibleAction;
    QAction* mEntityNameVisibleAction;
    QAction* mEntityFocusingAction;

    TcpSocket* mTcpSocket;
};

#endif // ENTITYWIDGET_H
