6,13 → 6,9 |
ui(new Ui::MainWindow) |
{ |
ui->setupUi(this); |
rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
rootItem1->setText(0, tr("Óðîâåíü 1")); |
rootItem2 = new QTreeWidgetItem(rootItem1); |
rootItem2->setText(0, tr("óðîâåíü 2")); |
rootItem1->setCheckState(0,Qt::Checked); |
rootItem2->setCheckState(0,Qt::Checked); |
|
MainWindow::readModel(); |
|
} |
|
MainWindow::~MainWindow() |
31,3 → 27,155 |
break; |
} |
} |
|
|
bool MainWindow::readModel(){ |
bool result; |
QString model_str; |
QFile file(":/model.txt"); |
rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
rootItem1->setText(0, tr("Óðîâåíü 1")); |
// rootItem2 = new QTreeWidgetItem(rootItem1); |
// rootItem2->setText(0, tr("óðîâåíü 2")); |
rootItem1->setCheckState(0,Qt::Checked); |
// rootItem2->setCheckState(0,Qt::Checked); |
|
|
|
result = file.open(QIODevice::ReadOnly); |
if (result) { |
model_str = QString(file.readAll()); |
} |
|
setupModelData(model_str.split(QString("\n")), rootItem1); |
|
|
return result; |
|
} |
|
|
void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent) |
{ |
QList<QTreeWidgetItem*> parents; |
QList<int> indentations; |
parents << parent; |
indentations << 0; |
|
int number = 0; |
|
while (number < lines.count()) { |
int position = 0; |
while (position < lines[number].length()) { |
if (lines[number].mid(position, 1) != " ") |
break; |
position++; |
} |
|
QString lineData = lines[number].mid(position).trimmed(); |
|
if (!lineData.isEmpty()) { |
// Read the column data from the rest of the line. |
QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
QList<QVariant> columnData; |
for (int column = 0; column < columnStrings.count(); ++column) |
columnData << columnStrings[column]; |
|
if (position > indentations.last()) { |
// The last child of the current parent is now the new parent |
// unless the current parent has no children. |
|
if (parents.last()->childCount() > 0) { |
parents << parents.last()->child(parents.last()->childCount()-1); |
indentations << position; |
} |
} else { |
while (position < indentations.last() && parents.count() > 0) { |
parents.pop_back(); |
indentations.pop_back(); |
} |
} |
|
// Append a new item to the current parent's list of children. |
// // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last())); |
QTreeWidgetItem* itm_tmp; |
itm_tmp = new QTreeWidgetItem( parents.last()); |
|
itm_tmp->setText(0, QString(columnData.at(0).toString())); |
if (columnData.at(1).toString() == "true") { |
itm_tmp->setCheckState(0,Qt::Checked); |
} |
else itm_tmp->setCheckState(0,Qt::Unchecked); |
|
|
} |
|
number++; |
} |
} |
|
|
/* |
void MainWindow::openBase() |
{ |
|
db = QSqlDatabase::addDatabase("QMYSQL"); |
pdb = &db; |
raportFrm.pdb = &db; |
|
pdb->setHostName(hostName); |
pdb->setDatabaseName(baseName); |
pdb->setUserName(userName); |
pdb->setPassword(password); |
bool ok = pdb->open(); |
if (!ok) { |
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå. |
this, // Ðîäèòåëüñêèé âèäæåò. |
QObject::tr("Database Error"), // Çàãîëîâîê. |
pdb->lastError().text()); // Òåêñò ñîîáùåíèÿ. |
} |
if (ok) |
{lineEdit-> insert(tr("Áàçà óñïåøíî îòêðûòà")); |
} |
else {lineEdit-> insert(tr("Áàçà íåäîñòóïíà. Êîä îøèáêè: ")); |
lineEdit-> insert(pdb->lastError().text()); |
} |
|
|
|
model = new QSqlTableModel(this); |
model->setTable(tableName); |
|
model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
model->setSort(0, Qt::AscendingOrder); |
|
model->select(); |
|
|
QSqlField field(tr("age"), QVariant::Int); |
field.setValue(QString(tr("123"))); |
|
bool okey; |
int index; |
QSqlRecord record; |
|
|
tableView->setModel(model); |
view.setModel(model); |
|
|
tableView->setAlternatingRowColors(true); |
view.setAlternatingRowColors(true); |
|
tableView->resizeColumnsToContents(); |
|
|
view.resizeColumnsToContents(); |
|
tableView->show(); |
|
|
|
initTreeWidget(); |
} |
*/ |