SHOW:
|
|
- or go back to the newest paste.
1 | - | // model.h |
1 | + | |
2 | - | #ifndef MODEL_H |
2 | + | #include "mainwindow.h" |
3 | - | #define MODEL_H |
3 | + | #include "ui_mainwindow.h" |
4 | ||
5 | - | #include <QAbstractTableModel> |
5 | + | |
6 | - | #include <QStringList> |
6 | + | #include <QDebug> |
7 | #include <QStandardItemModel> | |
8 | ||
9 | - | class TableModel : public QAbstractTableModel |
9 | + | #include <QStandardItem> |
10 | #include <QStringListModel> | |
11 | - | Q_OBJECT |
11 | + | |
12 | ||
13 | - | public: |
13 | + | #include <QAbstractItemModel> |
14 | - | TableModel(int rows = 1, int columns = 1, QObject *parent = 0); |
14 | + | #include <QListView> |
15 | #include <QVariant> | |
16 | - | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
16 | + | #include "model.h" |
17 | - | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
17 | + | #include <cstdlib> |
18 | - | QVariant data(const QModelIndex &index, int role) const; |
18 | + | #include <stdlib.h> |
19 | - | QVariant headerData(int section, Qt::Orientation orientation, |
19 | + | |
20 | - | int role = Qt::DisplayRole) const; |
20 | + | MainWindow::MainWindow(QWidget *parent) : |
21 | QMainWindow(parent), | |
22 | - | Qt::ItemFlags flags(const QModelIndex &index) const; |
22 | + | ui(new Ui::MainWindow) |
23 | - | bool setData(const QModelIndex &index, const QVariant &value, |
23 | + | |
24 | - | int role = Qt::EditRole); |
24 | + | ui->setupUi(this); |
25 | ||
26 | - | bool insertRows(int position, int rows, const QModelIndex &parent = QModelIndex()); |
26 | + | testCmdAlternative(); |
27 | - | bool insertColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); |
27 | + | } |
28 | - | bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()); |
28 | + | |
29 | - | bool removeColumns(int position, int columns, const QModelIndex &parent = QModelIndex()); |
29 | + | MainWindow::~MainWindow() |
30 | { | |
31 | - | private: |
31 | + | delete ui; |
32 | - | QList<QStringList> rowList; |
32 | + | } |
33 | - | }; |
33 | + | |
34 | ||
35 | - | #endif |
35 | + | |
36 | int MainWindow::testCmdAlternative() { | |
37 | ||
38 | FILE *in; | |
39 | char buff[512]; | |
40 | ||
41 | if(!(in = popen("export", "r"))){ | |
42 | return 1; | |
43 | } | |
44 | ||
45 | ||
46 | // TableModel *model = new TableModel(4, 2, this); | |
47 | ||
48 | // ui->tableView->setModel(model); | |
49 | ||
50 | // ui->tableView->horizontalHeader()->setModel(model); | |
51 | ||
52 | // for (int row = 0; row < 4; ++row) { | |
53 | // for (int column = 0; column < 2; ++column) { | |
54 | // QModelIndex index = model->index(row, column, QModelIndex()); | |
55 | // model->setData(index, QVariant(QString("(%1, %2)").arg(row).arg(column))); | |
56 | // } | |
57 | // } | |
58 | ||
59 | ||
60 | QStringList envVarNames; | |
61 | QStringList envVarPaths; | |
62 | ||
63 | int row = 1; | |
64 | ||
65 | while(fgets(buff, sizeof(buff), in)!=NULL){ | |
66 | ||
67 | // cout << buff << "TEST " << endl; | |
68 | string envPathVar = buff; | |
69 | ||
70 | // string envPathVar = cmdResultList.at(i).toLocal8Bit().data(); | |
71 | // // Convert to QString variable | |
72 | QString envPathVarQ = QString::fromStdString(envPathVar); | |
73 | ||
74 | // // Split PATH=/path/to/lib at the = to get varName and varPath(s) | |
75 | QStringList nameSplitPath = envPathVarQ.split("="); | |
76 | ||
77 | qDebug() << "AT0" << nameSplitPath.at(0).toLocal8Bit().data(); | |
78 | qDebug() << "AT0" << nameSplitPath.at(1).toLocal8Bit().data(); | |
79 | ||
80 | // // Add EnvPath name to list | |
81 | string envVarNameString = nameSplitPath.at(0).toLocal8Bit().data(); | |
82 | QString envVarName = QString::fromStdString(envVarNameString); | |
83 | envVarNames.append(envVarName); | |
84 | ||
85 | // // Add EnvPath path to list | |
86 | string envVarPathString = nameSplitPath.at(1).toAscii().data(); | |
87 | QString envVarPath = QString::fromStdString(envVarPathString); | |
88 | envVarPaths.append(envVarPath); | |
89 | ||
90 | ||
91 | ||
92 | /********************8 Add Path name to list*****************/ | |
93 | QString itemText = envVarName.replace("export", ""); | |
94 | QListWidgetItem *newItem = new QListWidgetItem; | |
95 | newItem->setText(itemText); | |
96 | ||
97 | ui->pathNameListWidget->insertItem(row, newItem); | |
98 | row++; | |
99 | ||
100 | } | |
101 | pclose(in); | |
102 | ||
103 | return 0; | |
104 | } | |
105 | ||
106 | ||
107 | void MainWindow::on_pathNameListWidget_currentRowChanged(int currentRow) | |
108 | { | |
109 | QString currentVal = (ui->pathNameListWidget->currentIndex().data().toString()); | |
110 | ||
111 | currentVal.trimmed(); | |
112 | currentVal.remove(" "); | |
113 | // Convert QString to const char* | |
114 | QByteArray currentValByteArray = currentVal.toUtf8(); | |
115 | const char *envVariable = currentValByteArray.data(); | |
116 | ||
117 | ||
118 | const char *getEnvPaths = getenv(envVariable); | |
119 | ||
120 | qDebug() << "char " << strlen(envVariable); | |
121 | qDebug() << getEnvPaths; | |
122 | ||
123 | if(getEnvPaths == NULL){ | |
124 | qDebug() << "getenv is null"; | |
125 | } | |
126 | // Set table model | |
127 | TableModel *tableModel = new TableModel(5, 1, this); | |
128 | ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); | |
129 | ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection); | |
130 | ui->tableView->setEditTriggers(QAbstractItemView::DoubleClicked); | |
131 | ||
132 | int row = 0; | |
133 | ||
134 | QModelIndex index = tableModel->index(row, 0, QModelIndex()); | |
135 | // Set table column data | |
136 | tableModel->setData(index, getEnvPaths, Qt::ItemIsEditable); | |
137 | ||
138 | ui->tableView->setModel(tableModel); | |
139 | ||
140 | } |