File size: 4,863 Bytes
a5ffdcd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /*
**********************************************************************************
**
** This file is part of the LibreCAD project (librecad.org), a 2D CAD program.
**
** Copyright (C) 2024 LibreCAD.org
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
**********************************************************************************
*/
#include <QListView>
#include <QStandardItemModel>
#include "lg_dimzerosbox.h"
LG_DimzerosBox::LG_DimzerosBox(QWidget *parent) : QComboBox(parent) {
dimLine = false;
view = new QListView();
model = new QStandardItemModel(3, 1);
QStandardItem* item = new QStandardItem(tr("select:"));
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
model->setItem(0,0,item);
item = new QStandardItem(tr("remove left"));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
model->setItem(1,0,item);
item = new QStandardItem(tr("remove right"));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
model->setItem(2,0,item);
setModel(model);
setView(view);
setEditable(false);
setEditText("selectar:");
}
LG_DimzerosBox::~LG_DimzerosBox() {
delete model;
delete view;
}
void LG_DimzerosBox::setLinear(){
dimLine = true;
QStandardItem* item = new QStandardItem(tr("remove 0'"));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
model->appendRow(item);
item = new QStandardItem(tr("remove 0\""));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
model->appendRow(item);
}
void LG_DimzerosBox::setData(int i){
if (dimLine) {
if (i & 1) {
if (i&2)
model->item(3)->setCheckState(Qt::Checked);
} else {
model->item(4)->setCheckState(Qt::Checked);
if (!(i&2))
model->item(3)->setCheckState(Qt::Checked);
}
if (i&4)
model->item(1)->setCheckState(Qt::Checked);
if (i&8)
model->item(2)->setCheckState(Qt::Checked);
} else {
if (i & 1)
model->item(1)->setCheckState(Qt::Checked);
if (i & 2)
model->item(2)->setCheckState(Qt::Checked);
}
}
int LG_DimzerosBox::getData(){
int ret = 0;
if (dimLine){
if (model->item(1)->checkState() == Qt::Checked)
ret |= 4;
if (model->item(2)->checkState() == Qt::Checked)
ret |= 8;
//imperial:
if (model->item(3)->checkState() == Qt::Checked){
if (model->item(4)->checkState() == Qt::Unchecked)
ret |= 3;
} else {
if (model->item(4)->checkState() == Qt::Checked)
ret |= 2;
else
ret |= 1;
}
} else {
if (model->item(1)->checkState() == Qt::Checked)
ret |= 1;
if (model->item(2)->checkState() == Qt::Checked)
ret |= 2;
}
return ret;
}
/**
* helper function for DIMZIN var.
*/
int LG_DimzerosBox::convertDimZin(int v, bool toIdx){
if (toIdx){
if (v < 5)
return 0;
int res = 0;
if (v & 4)
res = 3;
if (v & 8)
return (res==3) ? 5 :4;
}
//toIdx false
switch (v) {
case 3:
return 4;
break;
case 4:
return 8;
break;
case 5:
return 12;
break;
default:
break;
}
return 1;
}
/*MyModel::MyModel(QObject *parent)
:QAbstractTableModel(parent)
{
}
int MyModel::rowCount(const QModelIndex & parent) const
{
return 2;
}
int MyModel::columnCount(const QModelIndex & parent) const
{
return 3;
}
QVariant MyModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::DisplayRole)
{
return QString("Row%1, Column%2")
.arg(index.row() + 1)
.arg(index.column() +1);
}
return QVariant();
}*/
|