#ifndef CONNECTIONDIALOG_H
#define CONNECTIONDIALOG_H

#include "global.h"
#include <QDialog>

class MainWindow;

QT_BEGIN_NAMESPACE
namespace Ui {
class ConnectionDialog;
}
QT_END_NAMESPACE

class ConnectionDialog : public QDialog
{
    Q_OBJECT

public:
    ConnectionDialog(QWidget *parent = nullptr);
    ~ConnectionDialog();

    void setMainWindow(MainWindow*);
    void setErrorInfo(const QString&);
    void clearErrorInfo();

protected:
    virtual void showEvent(QShowEvent*);
    virtual void closeEvent(QCloseEvent*);

private:
    void initialize();
    void appendConnListItem(const QString&, const QString&, const QString&);
    void addNewConnListItem();
    void removeConnListItem(int);
    void loadConnInfo(const QString&);

    Ui::ConnectionDialog *ui;
    MainWindow* m_pMainWindow;
    bool m_isNewStatus;//是否是新建链接编辑状态
    int m_curConnListRow;

signals:
    void addConnection(DatabaseConfig&);

public slots:
    void onBtnClicked_open();
    void onBtnClicked_cancle();
    void onBtnClicked_save();
    void onBtnClicked_add();
    void onBtnClicked_remove();
    void onComboxChanged_dbType(const QString&);
    void onTableCellClicked_connList(int, int);
};

#endif // CONNECTIONDIALOG_H
