| 1 |
|
|---|
| 2 | /* -------------------------------------------------------------------------
|
|---|
| 3 | * RTNet GUI
|
|---|
| 4 | * -------------------------------------------------------------------------
|
|---|
| 5 | *
|
|---|
| 6 | * Class: t_uniLine
|
|---|
| 7 | *
|
|---|
| 8 | * Purpose: Universal-Line Widget (subclasses QTableWidget)
|
|---|
| 9 | *
|
|---|
| 10 | * Author: L. Mervart
|
|---|
| 11 | *
|
|---|
| 12 | * Created: 08-Jan-2013
|
|---|
| 13 | *
|
|---|
| 14 | * Changes:
|
|---|
| 15 | *
|
|---|
| 16 | * -----------------------------------------------------------------------*/
|
|---|
| 17 |
|
|---|
| 18 | #include "uniline.h"
|
|---|
| 19 |
|
|---|
| 20 | using namespace std;
|
|---|
| 21 | using namespace GnssCenter;
|
|---|
| 22 |
|
|---|
| 23 | static const char* plus_xpm[] = {
|
|---|
| 24 | "16 16 2 1",
|
|---|
| 25 | " c #FFFFFFFFFFFF",
|
|---|
| 26 | ". c #00000000FFFF",
|
|---|
| 27 | " ",
|
|---|
| 28 | " ... ",
|
|---|
| 29 | " ... ",
|
|---|
| 30 | " ... ",
|
|---|
| 31 | " ... ",
|
|---|
| 32 | " ... ",
|
|---|
| 33 | " .............. ",
|
|---|
| 34 | " .............. ",
|
|---|
| 35 | " .............. ",
|
|---|
| 36 | " ... ",
|
|---|
| 37 | " ... ",
|
|---|
| 38 | " ... ",
|
|---|
| 39 | " ... ",
|
|---|
| 40 | " ... ",
|
|---|
| 41 | " ",
|
|---|
| 42 | " "};
|
|---|
| 43 |
|
|---|
| 44 | static const char* minus_xpm[] = {
|
|---|
| 45 | "16 16 2 1",
|
|---|
| 46 | " c #FFFFFFFFFFFF",
|
|---|
| 47 | ". c #00000000FFFF",
|
|---|
| 48 | " ",
|
|---|
| 49 | " ",
|
|---|
| 50 | " ",
|
|---|
| 51 | " ",
|
|---|
| 52 | " ",
|
|---|
| 53 | " ",
|
|---|
| 54 | " .............. ",
|
|---|
| 55 | " .............. ",
|
|---|
| 56 | " .............. ",
|
|---|
| 57 | " ",
|
|---|
| 58 | " ",
|
|---|
| 59 | " ",
|
|---|
| 60 | " ",
|
|---|
| 61 | " ",
|
|---|
| 62 | " ",
|
|---|
| 63 | " "};
|
|---|
| 64 |
|
|---|
| 65 | // Constructor
|
|---|
| 66 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 67 | t_uniLine::t_uniLine(const QString& fldMask, const QStringList& values,
|
|---|
| 68 | QWidget* parent) : QTableWidget(parent) {
|
|---|
| 69 |
|
|---|
| 70 | static const QPixmap plusXPM(plus_xpm);
|
|---|
| 71 | static const QPixmap minusXPM(minus_xpm);
|
|---|
| 72 | static const QIcon plusIcon(plusXPM);
|
|---|
| 73 | static const QIcon minusIcon(minusXPM);
|
|---|
| 74 |
|
|---|
| 75 | setRowCount(values.size());
|
|---|
| 76 |
|
|---|
| 77 | QStringList labels = fldMask.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
|---|
| 78 | if (labels.size() > 0) {
|
|---|
| 79 | setColumnCount(labels.size() + 2);
|
|---|
| 80 | labels << "" << "";
|
|---|
| 81 | setHorizontalHeaderLabels(labels);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | for (int iRow = 0; iRow < values.size(); iRow++) {
|
|---|
| 85 | QStringList txt = values.at(iRow).split(QRegExp("\"\\s*\""));
|
|---|
| 86 | if (labels.size() == 0 && iRow == 0) {
|
|---|
| 87 | setColumnCount(txt.size() + 2);
|
|---|
| 88 | }
|
|---|
| 89 | for (int iCol = 0; iCol < txt.size(); iCol++) {
|
|---|
| 90 | setItem(iRow, iCol, new QTableWidgetItem(txt.at(iCol).trimmed()));
|
|---|
| 91 | }
|
|---|
| 92 | for (int iCol = txt.size(); iCol < columnCount()-2; iCol++) {
|
|---|
| 93 | setItem(iRow, iCol, new QTableWidgetItem(""));
|
|---|
| 94 | }
|
|---|
| 95 | setItem(iRow, columnCount()-2, new QTableWidgetItem(plusIcon, QString()));
|
|---|
| 96 | setItem(iRow, columnCount()-1, new QTableWidgetItem(minusIcon, QString()));
|
|---|
| 97 | }
|
|---|
| 98 | connect(this, SIGNAL(itemClicked(QTableWidgetItem*)),
|
|---|
| 99 | this, SLOT(slotItemClicked(QTableWidgetItem*)));
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | // Destructor
|
|---|
| 103 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 104 | t_uniLine::~t_uniLine() {
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | // Add/Remove Line
|
|---|
| 108 | ////////////////////////////////////////////////////////////////////////////////
|
|---|
| 109 | void t_uniLine::slotItemClicked(QTableWidgetItem* item) {
|
|---|
| 110 |
|
|---|
| 111 | static const QPixmap plusXPM(plus_xpm);
|
|---|
| 112 | static const QPixmap minusXPM(minus_xpm);
|
|---|
| 113 | static const QIcon plusIcon(plusXPM);
|
|---|
| 114 | static const QIcon minusIcon(minusXPM);
|
|---|
| 115 |
|
|---|
| 116 | int iCol = item->column();
|
|---|
| 117 | if (iCol == columnCount()-2) {
|
|---|
| 118 | int iRow = item->row() + 1;
|
|---|
| 119 | insertRow(iRow);
|
|---|
| 120 | setItem(iRow, columnCount()-2, new QTableWidgetItem(plusIcon, QString()));
|
|---|
| 121 | setItem(iRow, columnCount()-1, new QTableWidgetItem(minusIcon, QString()));
|
|---|
| 122 | }
|
|---|
| 123 | else if (iCol == columnCount()-1) {
|
|---|
| 124 | removeRow(item->row());
|
|---|
| 125 | }
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|