Go to the documentation of this file.00001 #ifndef GLOBAL_H
00002 #define GLOBAL_H
00003
00004 #include <QDebug>
00005
00006
00007
00008 class QString;
00009 #include <QDir>
00010 #include <QCoreApplication>
00011
00015 namespace GlobalConst {
00016 const QString SMARTLET_SCHEMA = "smartlet";
00017 const QString TEMPLATES_SCHEMA = "templates01";
00018 const QDir TEMP_DIR = QDir::currentPath() + QDir::separator() + "temp";
00019 const QDir EXPORT_DIR = QDir::currentPath() + QDir::separator() + "export";
00020 const QDir LOG_DIR = QDir::currentPath() + QDir::separator() + "log";
00021 const QString CALI_FORMULA_HELP = "<body><h4>Note on formula:</h4>"
00022 "'$1' refers to raw data. "
00023 "Most common arithmetic operators which can be used on such data are: '+' (addition), '-' (subtraction), '*' (multiplication), '/' (division), and '^' (exponentiation). "
00024 "For a whole reference documentation, see <a href=\"http://www.postgresql.org/docs/current/static/functions.html\">functions</a> or its subset "
00025 "<a href=\"http://www.postgresql.org/docs/current/static/functions-math.html\">math functions</a>. "
00026 "A valid formula for example is: '($1)^2*5'. It will take data, raise it to the second power, and multiply it by five.</body>";
00027 const QString DB_TABLE_CHANGE_NOTIFY = "NOTIFICATION_TABLE_CHANGE_%1";
00028 const QString DB_BASE_DATA_QUERY = "("
00029 "SELECT sens_chan_data_timestamp AS \"timestamp\", "
00030 "sens_chan_data_data AS %1 "
00031 "FROM tbl_sensor_channel_data "
00032 "WHERE tree_id = %2 "
00033 "AND sens_chan_data_timestamp >= '%3' "
00034 "AND sens_chan_data_timestamp <= '%4' "
00035 ") AS \"%2\" \n";
00036 const QString URL_DOCS = "http://pleco10.ugent.be:10000/projects/docs/smartlet/html/current/";
00037 };
00038
00042 namespace GlobalEnum {
00043 enum BuilderHeaderDataRole {
00044 BuilderHeaderDataUnitSymbolRole = 1200 + Qt::UserRole
00045 };
00046
00047 };
00048
00054 class TablePrefs{
00055 public:
00056 TablePrefs(){};
00057 TablePrefs(const QString &tableName, const QString &descFieldName){
00058 m_tableName = tableName;
00059 m_descFieldName = descFieldName;
00060 }
00061
00062 QString tableName(){
00063 return m_tableName;
00064 }
00065
00066 QString descFieldName(){
00067 return m_descFieldName;
00068 }
00069
00070 private:
00071 QString m_tableName;
00072 QString m_descFieldName;
00073 };
00074
00075 #include <QHash>
00076
00082 class Tables : public QHash<QString, TablePrefs> {
00083 public:
00084 static Tables *instance(){
00085 static Tables tables;
00086 return &tables;
00087 }
00088
00089 private:
00090 Tables(){
00091 insert("proj_id", TablePrefs("tbl_projects", "proj_desc"));
00092 insert("inst_id", TablePrefs("tbl_installations", "inst_desc"));
00093 insert("loca_id", TablePrefs("tbl_locations", "loca_desc"));
00094 insert("sens_cate_id", TablePrefs("tbl_sensor_categories", "sens_cate_desc"));
00095 insert("sens_id", TablePrefs("tbl_sensors", "sens_desc"));
00096 insert("sens_chan_nr", TablePrefs("tbl_sensor_channels", "sens_chan_desc"));
00097 }
00098 };
00099
00100
00101 bool copyFile(char *dest, char *src);
00102
00103 class QDateTime;
00104 QString generateKey(const QDateTime ×tamp, const QString &component);
00105
00106 class QSqlQuery;
00107 class QSqlRecord;
00108 class QVariant;
00109
00110 int seekRow(QSqlQuery query, const QSqlRecord &record);
00111 quint64 cantor (const int &x, const int &y);
00112 QVariant formulaRead(const QVariant &data);
00113 QVariant formulaWrite(const QVariant &data);
00114
00115 #include <QObject>
00116 #include <QDialog>
00117 #include <QAbstractItemModel>
00118 #include <QVBoxLayout>
00119 #include <QListView>
00120 #include <QDialogButtonBox>
00121 #include <QItemSelection>
00122 #include <QPushButton>
00123
00127 class SimpleViewSelectionDialog : public QDialog {
00128 Q_OBJECT
00129 public:
00130 SimpleViewSelectionDialog(const QString &title, QAbstractItemModel *model, QWidget *parent = 0) : QDialog(parent){
00131 setWindowTitle(title);
00132 view = new QListView(this);
00133 view->setSelectionMode(QAbstractItemView::SingleSelection);
00134 view->setModel(model);
00135
00136 buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
00137 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
00138 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
00139 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
00140 connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
00141 this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
00142
00143 setLayout(new QVBoxLayout());
00144 layout()->addWidget(view);
00145 layout()->addWidget(buttonBox);
00146 }
00147
00148 QModelIndex selection(){
00149 return view->selectionModel()->selectedIndexes().first();
00150 }
00151
00152 private slots:
00153 void selectionChanged(QItemSelection selected, QItemSelection){
00154 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!selected.isEmpty());
00155 }
00156 private:
00157 QListView *view;
00158 QDialogButtonBox *buttonBox;
00159 };
00160
00161 #endif // GLOBAL_H