XMLEditFields.C 39.2 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
bonnell's avatar
bonnell committed
3
* Copyright (c) 2000 - 2015, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9 10 11 12 13 14 15 16 17 18
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
19 20 21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22 23 24 25 26
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
27 28 29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30 31 32 33 34 35 36 37
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
whitlocb's avatar
whitlocb committed
38
#include "XMLEditStd.h"
hrchilds's avatar
hrchilds committed
39 40 41 42
#include "XMLEditFields.h"

#include <XMLDocument.h>
#include <Attribute.h>
whitlocb's avatar
whitlocb committed
43 44 45 46 47 48 49 50 51 52 53 54 55
#include <QButtonGroup>
#include <QCheckBox>
#include <QComboBox>
#include <QGroupBox>
#include <QBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QRadioButton>
#include <QTextEdit>
hrchilds's avatar
hrchilds committed
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
// ****************************************************************************
//  Class:  QNarrowLineEdit
//
//  Purpose:
//    A QLineEdit that has a narrower default size.
//
//  Programmer:  Jeremy Meredith
//  Creation:    September 25, 2001
//
// ****************************************************************************
class QNarrowLineEdit : public QLineEdit
{
  public:
    QNarrowLineEdit(QWidget *p)
        : QLineEdit(p)
    {
    }
    QNarrowLineEdit(const QString &s, QWidget *p)
        : QLineEdit(s, p)
    {
    }
    QSize sizeHint() const
    {
        QSize size = QLineEdit::sizeHint();
        QFontMetrics fm(font());
        int w = fm.width('x') * 4; // 4 characters
        size.setWidth(w);
        return size;
    }
};
hrchilds's avatar
hrchilds committed
87 88 89 90 91 92 93

// ****************************************************************************
//  Constructor:  XMLEditFields::XMLEditFields
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
hrchilds's avatar
hrchilds committed
94 95 96 97 98
//  Modifications:
//    Brad Whitlock, Fri Dec 10 10:29:49 PDT 2004
//    I added code to create widgets that have to do with attributes for the
//    variablename type.
//
hrchilds's avatar
hrchilds committed
99 100 101
//    Brad Whitlock, Fri Apr 1 16:05:13 PST 2005
//    Added Labels variable type.
//
hrchilds's avatar
hrchilds committed
102 103 104
//    Hank Childs, Tue Jul 19 14:08:19 PDT 2005
//    Added arrays.
//
hrchilds's avatar
hrchilds committed
105 106 107
//    Brad Whitlock, Wed Feb 28 18:42:51 PST 2007
//    Added public/protected/private.
//
whitlocb's avatar
whitlocb committed
108 109 110
//    Brad Whitlock, Fri Mar 7 10:26:23 PDT 2008
//    Made values/code monospace.
//
whitlocb's avatar
whitlocb committed
111 112 113
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
114 115 116
//    Kathleen Biagas, Thu Aug 25 14:24:11 MST 2011 
//    Added persistent checkbox.
//
hrchilds's avatar
hrchilds committed
117
// ****************************************************************************
hrchilds's avatar
hrchilds committed
118

whitlocb's avatar
whitlocb committed
119 120
XMLEditFields::XMLEditFields(QWidget *p)
    : QFrame(p)
hrchilds's avatar
hrchilds committed
121 122
{
    QHBoxLayout *hLayout = new QHBoxLayout(this);
whitlocb's avatar
whitlocb committed
123 124
    
    QGridLayout *listLayout = new QGridLayout();
hrchilds's avatar
hrchilds committed
125

whitlocb's avatar
whitlocb committed
126 127 128 129
    fieldlist = new QListWidget(this);
    fieldlist->addItem("testint");
    fieldlist->addItem("testfloat");
    listLayout->addWidget(fieldlist, 0,0, 1,2);
hrchilds's avatar
hrchilds committed
130

131
    upButton = new QPushButton(tr("Up"), this);
hrchilds's avatar
hrchilds committed
132 133
    listLayout->addWidget(upButton, 1,0);

134
    downButton = new QPushButton(tr("Down"), this);
hrchilds's avatar
hrchilds committed
135 136
    listLayout->addWidget(downButton, 1,1);

137
    newButton = new QPushButton(tr("New"), this);
hrchilds's avatar
hrchilds committed
138 139
    listLayout->addWidget(newButton, 2,0);

140
    delButton = new QPushButton(tr("Del"), this);
hrchilds's avatar
hrchilds committed
141
    listLayout->addWidget(delButton, 2,1);
whitlocb's avatar
whitlocb committed
142 143
    
    hLayout->addLayout(listLayout);
hrchilds's avatar
hrchilds committed
144 145
    hLayout->addSpacing(10);

whitlocb's avatar
whitlocb committed
146
    QGridLayout *topLayout = new QGridLayout();
hrchilds's avatar
hrchilds committed
147 148
    int row = 0;

whitlocb's avatar
whitlocb committed
149 150 151 152 153
    topLayout->setColumnMinimumWidth(0, 0);
    topLayout->setColumnMinimumWidth(1, 0);
    topLayout->setColumnMinimumWidth(2, 75);
    topLayout->setColumnMinimumWidth(3, 0);
    topLayout->setColumnMinimumWidth(4, 25);
hrchilds's avatar
hrchilds committed
154 155

    name = new QLineEdit(this);
whitlocb's avatar
whitlocb committed
156 157
    topLayout->addWidget(new QLabel(tr("Name"), this), row,0);
    topLayout->addWidget(name, row,1,1,5);
hrchilds's avatar
hrchilds committed
158 159 160
    row++;

    label = new QLineEdit(this);
whitlocb's avatar
whitlocb committed
161 162
    topLayout->addWidget(new QLabel(tr("Label"), this), row,0);
    topLayout->addWidget(label, row,1, 1,5);
hrchilds's avatar
hrchilds committed
163 164 165
    row++;

    type = new QComboBox(this);
whitlocb's avatar
whitlocb committed
166
    type->addItem("");
hrchilds's avatar
hrchilds committed
167
    type->setMinimumWidth(150);
whitlocb's avatar
whitlocb committed
168 169 170 171 172 173 174 175
    topLayout->addWidget(new QLabel(tr("Type"), this), row,0);
    topLayout->addWidget(type, row,1, 1,3);
    
    QHBoxLayout *lengthHBox = new QHBoxLayout();
    lengthHBox->addWidget(new QLabel(tr("Length"), this)); 
    length = new QNarrowLineEdit(this);
    lengthHBox->addWidget(length);
    topLayout->addLayout(lengthHBox, row, 4);
hrchilds's avatar
hrchilds committed
176
    row++;
whitlocb's avatar
whitlocb committed
177
    
hrchilds's avatar
hrchilds committed
178
    subtype = new QLineEdit(this);
whitlocb's avatar
whitlocb committed
179 180
    topLayout->addWidget(new QLabel(tr("Subtype"), this), row,0);
    topLayout->addWidget(subtype, row,1, 1,5);
hrchilds's avatar
hrchilds committed
181 182 183
    row++;

    enabler = new QComboBox(this);
whitlocb's avatar
whitlocb committed
184 185 186
    enabler->addItem(tr("(none)"));
    topLayout->addWidget(new QLabel(tr("Enabler"), this), row,0);
    topLayout->addWidget(enabler, row,1, 1,5);
hrchilds's avatar
hrchilds committed
187 188 189
    row++;

    enableval = new QLineEdit(this);
whitlocb's avatar
whitlocb committed
190 191
    topLayout->addWidget(new QLabel(tr("Values"), this), row,1, 1,1);
    topLayout->addWidget(enableval, row,2, 1,3); 
hrchilds's avatar
hrchilds committed
192 193
    row++;

194
    internal = new QCheckBox(tr("Internal use only"), this);
whitlocb's avatar
whitlocb committed
195
    topLayout->addWidget(internal, row,0, 1,3);
196 197 198 199
    row++;

    persistent = new QCheckBox(tr("Persistent"), this);
    topLayout->addWidget(persistent, row,0, 1,3);
hrchilds's avatar
hrchilds committed
200 201 202

    // Add a group box that contains controls to set the variable
    // types that will be accepted by a variablename object.
whitlocb's avatar
whitlocb committed
203
    variableNameGroup = new QGroupBox(this);
204
    variableNameGroup->setTitle(tr("Accepted variable types"));
whitlocb's avatar
whitlocb committed
205 206
    
    QHBoxLayout *innerVarNameLayout = new QHBoxLayout(variableNameGroup);
hrchilds's avatar
hrchilds committed
207
    innerVarNameLayout->setMargin(10);
whitlocb's avatar
whitlocb committed
208
    QGridLayout *vnLayout = new QGridLayout();
hrchilds's avatar
hrchilds committed
209
    vnLayout->setSpacing(5);
whitlocb's avatar
whitlocb committed
210
    varNameButtons = new QButtonGroup(this);
211
    varNameButtons->setExclusive(false);
whitlocb's avatar
whitlocb committed
212
    connect(varNameButtons, SIGNAL(buttonClicked(int)),
hrchilds's avatar
hrchilds committed
213
            this, SLOT(variableTypeClicked(int)));
214
    QCheckBox *cb = new QCheckBox(tr("Meshes"), variableNameGroup);
whitlocb's avatar
whitlocb committed
215
    varNameButtons->addButton(cb,0);
hrchilds's avatar
hrchilds committed
216
    vnLayout->addWidget(cb, 0, 0);
217
    cb = new QCheckBox(tr("Scalars"), variableNameGroup);
whitlocb's avatar
whitlocb committed
218
    varNameButtons->addButton(cb,1);
hrchilds's avatar
hrchilds committed
219
    vnLayout->addWidget(cb, 1, 0);
220
    cb = new QCheckBox(tr("Materials"), variableNameGroup);
whitlocb's avatar
whitlocb committed
221
    varNameButtons->addButton(cb,2);
hrchilds's avatar
hrchilds committed
222
    vnLayout->addWidget(cb, 2, 0);
223
    cb = new QCheckBox(tr("Labels"), variableNameGroup);
whitlocb's avatar
whitlocb committed
224
    varNameButtons->addButton(cb,9);
hrchilds's avatar
hrchilds committed
225
    vnLayout->addWidget(cb, 3, 0);
hrchilds's avatar
hrchilds committed
226

227
    cb = new QCheckBox(tr("Vectors"), variableNameGroup);
whitlocb's avatar
whitlocb committed
228
    varNameButtons->addButton(cb,3);
hrchilds's avatar
hrchilds committed
229
    vnLayout->addWidget(cb, 0, 1);
230
    cb = new QCheckBox(tr("Subsets"), variableNameGroup);
whitlocb's avatar
whitlocb committed
231
    varNameButtons->addButton(cb,4);
hrchilds's avatar
hrchilds committed
232
    vnLayout->addWidget(cb, 1, 1);
233
    cb = new QCheckBox(tr("Species"), variableNameGroup);
whitlocb's avatar
whitlocb committed
234
    varNameButtons->addButton(cb,5);
hrchilds's avatar
hrchilds committed
235
    vnLayout->addWidget(cb, 2, 1);
236
    cb = new QCheckBox(tr("Arrays"), variableNameGroup);
whitlocb's avatar
whitlocb committed
237
    varNameButtons->addButton(cb,10);
hrchilds's avatar
hrchilds committed
238
    vnLayout->addWidget(cb, 3, 1);
hrchilds's avatar
hrchilds committed
239

240
    cb = new QCheckBox(tr("Curves"), variableNameGroup);
whitlocb's avatar
whitlocb committed
241
    varNameButtons->addButton(cb,6);
hrchilds's avatar
hrchilds committed
242
    vnLayout->addWidget(cb, 0, 2);
243
    cb = new QCheckBox(tr("Tensors"), variableNameGroup);
whitlocb's avatar
whitlocb committed
244
    varNameButtons->addButton(cb,7);
hrchilds's avatar
hrchilds committed
245
    vnLayout->addWidget(cb, 1, 2);
246
    cb = new QCheckBox(tr("Symmetric Tensors"), variableNameGroup);
whitlocb's avatar
whitlocb committed
247
    varNameButtons->addButton(cb,8);
hrchilds's avatar
hrchilds committed
248
    vnLayout->addWidget(cb, 2, 2);
whitlocb's avatar
whitlocb committed
249 250 251
    innerVarNameLayout->addLayout(vnLayout);
    
    topLayout->addWidget(variableNameGroup, row,3,3,2);
hrchilds's avatar
hrchilds committed
252 253
    row++;

254
    ignoreeq = new QCheckBox(tr("Ignore field for attribute\nequality calculations"), this);
whitlocb's avatar
whitlocb committed
255
    topLayout->addWidget(ignoreeq, row,0, 1,3);
hrchilds's avatar
hrchilds committed
256 257
    row++;

whitlocb's avatar
whitlocb committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    accessGroup = new QGroupBox(tr("Access"),this);
    
    access = new QButtonGroup(accessGroup);
    QRadioButton *access_private   = new QRadioButton(tr("private"), accessGroup);
    QRadioButton *access_protected = new QRadioButton(tr("protected"), accessGroup);
    QRadioButton *access_public    = new QRadioButton(tr("public"), accessGroup);
    
    access->addButton(access_private,0);
    access->addButton(access_protected,1);
    access->addButton(access_public,2);
    
    // create a vbox layout for the access group box
    QVBoxLayout *access_layout= new QVBoxLayout(accessGroup);
    accessGroup->setLayout(access_layout);
    access_layout->addWidget(access_private);
    access_layout->addWidget(access_protected);
    access_layout->addWidget(access_public);
        
    topLayout->addWidget(accessGroup, row,0, 1,3);
hrchilds's avatar
hrchilds committed
277 278
    row++;

279
    init = new QCheckBox(tr("Special initialization code"), this);
whitlocb's avatar
whitlocb committed
280
    topLayout->addWidget(init, row,0, 1,3);
hrchilds's avatar
hrchilds committed
281 282
    row++;

whitlocb's avatar
whitlocb committed
283
    topLayout->addWidget(new QLabel(tr("Initialization Values / Code"), this), row,0, 1,4);
hrchilds's avatar
hrchilds committed
284 285
    row++;

whitlocb's avatar
whitlocb committed
286
    values = new QTextEdit(this);
whitlocb's avatar
whitlocb committed
287 288
    QFont monospaced("Courier");
    values->setFont(monospaced);
whitlocb's avatar
whitlocb committed
289 290 291 292 293
    values->setWordWrapMode(QTextOption::NoWrap);
    topLayout->addWidget(values, row,1, 1,4);
    hLayout->addLayout(topLayout);
    
    connect(fieldlist, SIGNAL(currentRowChanged(int)),
hrchilds's avatar
hrchilds committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
            this, SLOT(UpdateWindowSingleItem()));
    connect(name, SIGNAL(textChanged(const QString&)),
            this, SLOT(nameTextChanged(const QString&)));
    connect(label, SIGNAL(textChanged(const QString&)),
            this, SLOT(labelTextChanged(const QString&)));
    connect(type, SIGNAL(activated(int)),
            this, SLOT(typeChanged(int)));
    connect(subtype, SIGNAL(textChanged(const QString&)),
            this, SLOT(subtypeTextChanged(const QString&)));
    connect(enabler, SIGNAL(activated(int)),
            this, SLOT(enablerChanged(int)));
    connect(enableval, SIGNAL(textChanged(const QString&)),
            this, SLOT(enablevalTextChanged(const QString&)));
    connect(length, SIGNAL(textChanged(const QString&)),
            this, SLOT(lengthTextChanged(const QString&)));
    connect(internal, SIGNAL(clicked()),
            this, SLOT(internalChanged()));
311 312
    connect(persistent, SIGNAL(clicked()),
            this, SLOT(persistentChanged()));
hrchilds's avatar
hrchilds committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326
    connect(ignoreeq, SIGNAL(clicked()),
            this, SLOT(ignoreeqChanged()));
    connect(init, SIGNAL(clicked()),
            this, SLOT(initChanged()));
    connect(values, SIGNAL(textChanged()),
            this, SLOT(valuesChanged()));
    connect(newButton, SIGNAL(pressed()),
            this, SLOT(fieldlistNew()));
    connect(delButton, SIGNAL(pressed()),
            this, SLOT(fieldlistDel()));
    connect(upButton, SIGNAL(pressed()),
            this, SLOT(fieldlistUp()));
    connect(downButton, SIGNAL(pressed()),
            this, SLOT(fieldlistDown()));
whitlocb's avatar
whitlocb committed
327
    connect(access, SIGNAL(buttonClicked(int)),
hrchilds's avatar
hrchilds committed
328
            this, SLOT(accessChanged(int)));
hrchilds's avatar
hrchilds committed
329 330 331 332 333 334 335 336 337 338 339
}

// ****************************************************************************
//  Method:  XMLEditFields::UpdateWindowContents
//
//  Purpose:
//    Update the window based on the current state.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
340 341 342 343
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
344 345 346 347 348 349 350 351
// ****************************************************************************
void
XMLEditFields::UpdateWindowContents()
{
    BlockAllSignals(true);

    Attribute *a = xmldoc->attribute;
    fieldlist->clear();
352
    for (size_t i=0; i<a->fields.size(); i++)
hrchilds's avatar
hrchilds committed
353
    {
whitlocb's avatar
whitlocb committed
354
        fieldlist->addItem(a->fields[i]->name);
hrchilds's avatar
hrchilds committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    }
    BlockAllSignals(false);

    UpdateWindowSingleItem();
}

// ****************************************************************************
//  Method:  XMLEditFields::UpdateWindowSensitivity
//
//  Purpose:
//    Enable/disable widget sensitivity based on the current state.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
hrchilds's avatar
hrchilds committed
370 371 372 373
//  Modifications:
//    Brad Whitlock, Fri Dec 10 10:35:26 PDT 2004
//    I added variableNameGroup.
//
hrchilds's avatar
hrchilds committed
374 375 376
//    Brad Whitlock, Wed Feb 28 18:47:36 PST 2007
//    Added access.
//
whitlocb's avatar
whitlocb committed
377 378 379
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
380 381 382
//    Kathleen Biagas, Thu Aug 25 14:24:11 MST 2011 
//    Added persistent checkbox.
//
hrchilds's avatar
hrchilds committed
383
// ****************************************************************************
hrchilds's avatar
hrchilds committed
384

hrchilds's avatar
hrchilds committed
385 386 387
void
XMLEditFields::UpdateWindowSensitivity()
{
whitlocb's avatar
whitlocb committed
388
    bool active = fieldlist->currentRow() != -1;
hrchilds's avatar
hrchilds committed
389 390

    delButton->setEnabled(fieldlist->count() > 0);
whitlocb's avatar
whitlocb committed
391 392
    upButton->setEnabled(fieldlist->currentRow() > 0);
    downButton->setEnabled(fieldlist->currentRow() < fieldlist->count()-1);
hrchilds's avatar
hrchilds committed
393 394 395 396 397 398 399
    name->setEnabled(active);
    label->setEnabled(active);
    type->setEnabled(active);
    subtype->setEnabled(active && (type->currentText() == "att" ||
                                   type->currentText() == "attVector"));
    length->setEnabled(active && (type->currentText().right(5) == "Array"));
    enabler->setEnabled(active);
400
    enableval->setEnabled(active && enabler->currentText() != tr("(none)"));
hrchilds's avatar
hrchilds committed
401
    internal->setEnabled(active);
402
    persistent->setEnabled(active);
hrchilds's avatar
hrchilds committed
403
    ignoreeq->setEnabled(active);
hrchilds's avatar
hrchilds committed
404
    variableNameGroup->setEnabled(active && type->currentText() == "variablename");
hrchilds's avatar
hrchilds committed
405 406
    init->setEnabled(active);
    values->setEnabled(active);
whitlocb's avatar
whitlocb committed
407
    accessGroup->setEnabled(active);
hrchilds's avatar
hrchilds committed
408 409 410 411 412 413 414 415 416 417 418
}

// ****************************************************************************
//  Method:  XMLEditFields::UpdateWindowSingleItem
//
//  Purpose:
//    Update the window based on the state a single item in the list.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
hrchilds's avatar
hrchilds committed
419 420 421 422
//  Modifications:
//     Brad Whitlock, Fri Dec 10 10:35:44 PDT 2004
//     I added code to update a new button group.
//
hrchilds's avatar
hrchilds committed
423 424 425
//     Brad Whitlock, Wed Feb 28 18:49:14 PST 2007
//     Added access.
//
whitlocb's avatar
whitlocb committed
426 427 428
//     Brad Whitlock, Thu Mar 6 15:00:08 PST 2008
//     Deal with multi-target init codes.
//
429 430 431 432 433
//     Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//     First pass at porting to Qt 4.4.0
//
//     Jeremy Meredith, Thu Mar 19 12:01:02 EDT 2009
//     Finish Qt4 port -- ids for variable type buttons weren't used.
whitlocb's avatar
whitlocb committed
434
//
435 436 437
//     Kathleen Biagas, Thu Aug 25 14:24:11 MST 2011 
//     Added persistent checkbox.
//
hrchilds's avatar
hrchilds committed
438
// ****************************************************************************
hrchilds's avatar
hrchilds committed
439

hrchilds's avatar
hrchilds committed
440 441 442 443 444 445
void
XMLEditFields::UpdateWindowSingleItem()
{
    BlockAllSignals(true);

    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
446
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
447 448 449 450 451 452 453 454 455 456 457

    if (index == -1)
    {
        name->setText("");
        label->setText("");
        type->clear();
        subtype->setText("");
        length->setText("");
        enabler->clear();
        enableval->setText("");
        internal->setChecked(false);
458
        persistent->setChecked(true);
hrchilds's avatar
hrchilds committed
459
        ignoreeq->setChecked(false);
whitlocb's avatar
whitlocb committed
460
        access->button(0)->setChecked(true);
hrchilds's avatar
hrchilds committed
461 462 463 464 465 466 467 468 469 470 471 472
        init->setChecked(false);
        values->setText("");
    }
    else
    {
        Field *f = a->fields[index];
        name->setText(f->name);
        label->setText(f->label);
        UpdateTypeList();
        if (f->type == "enum")
        {
            QString enumtype = QString("enum:")+f->GetSubtype();
473
            for (int i=0; i<type->count(); i++)
hrchilds's avatar
hrchilds committed
474
            {
whitlocb's avatar
whitlocb committed
475 476
                if (type->itemText(i) == enumtype)
                    type->setCurrentIndex(i);
hrchilds's avatar
hrchilds committed
477 478 479 480
            }
        }
        else
        {
481
            for (int i=0; i<type->count(); i++)
hrchilds's avatar
hrchilds committed
482
            {
whitlocb's avatar
whitlocb committed
483 484
                if (type->itemText(i) == f->type)
                    type->setCurrentIndex(i);
hrchilds's avatar
hrchilds committed
485 486 487 488 489 490 491 492 493 494 495 496 497
            }
        }
        if (f->type == "att" || f->type == "attVector")
        {
            subtype->setText(f->GetSubtype());
        }
        else
        {
            subtype->setText("");
        }
        if (f->type.right(5) == "Array")
        {
            QString str;
whitlocb's avatar
whitlocb committed
498
            str.sprintf("%d",f->length); 
hrchilds's avatar
hrchilds committed
499 500 501 502 503 504 505 506 507
            length->setText(str);
        }
        else
        {
            length->setText("");
        }
        UpdateEnablerList();
        if (f->enabler)
        {
508
            for (int i=0; i<enabler->count(); i++)
hrchilds's avatar
hrchilds committed
509
            {
whitlocb's avatar
whitlocb committed
510 511
                if (enabler->itemText(i) == f->enabler->name)
                    enabler->setCurrentIndex(i);
hrchilds's avatar
hrchilds committed
512 513 514 515 516
            }
            enableval->setText(JoinValues(f->enableval, ' '));
        }
        else
        {
whitlocb's avatar
whitlocb committed
517
            enabler->setCurrentIndex(0);
hrchilds's avatar
hrchilds committed
518 519 520
            enableval->setText("");
        }
        internal->setChecked(f->internal);
521
        persistent->setChecked(f->persistent);
hrchilds's avatar
hrchilds committed
522
        ignoreeq->setChecked(f->ignoreEquality);
hrchilds's avatar
hrchilds committed
523
        if(f->accessType == Field::AccessPrivate)
whitlocb's avatar
whitlocb committed
524
            access->button(0)->setChecked(true);
hrchilds's avatar
hrchilds committed
525
        else if(f->accessType == Field::AccessProtected)
whitlocb's avatar
whitlocb committed
526
            access->button(1)->setChecked(true);
hrchilds's avatar
hrchilds committed
527
        else if(f->accessType == Field::AccessPublic)
whitlocb's avatar
whitlocb committed
528
            access->button(2)->setChecked(true);
hrchilds's avatar
hrchilds committed
529 530
        if(f->type == "variablename")
        {
whitlocb's avatar
whitlocb committed
531
            foreach (QAbstractButton *b, varNameButtons->buttons())
hrchilds's avatar
hrchilds committed
532
            {
533
                int mask = (1 << varNameButtons->id(b));
whitlocb's avatar
whitlocb committed
534
                b->setChecked((f->varTypes & mask) != 0);
hrchilds's avatar
hrchilds committed
535 536 537
            }
        }

whitlocb's avatar
whitlocb committed
538
        if (f->initcode.size() < 1)
hrchilds's avatar
hrchilds committed
539 540 541 542 543 544 545
        {
            init->setChecked(false);
            values->setText(JoinValues(f->GetValueAsText(), '\n'));
        }
        else
        {
            init->setChecked(true);
whitlocb's avatar
whitlocb committed
546
            values->setText(f->InitCodeAsString());
hrchilds's avatar
hrchilds committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
        }
    }

    UpdateWindowSensitivity();

    BlockAllSignals(false);
}

// ****************************************************************************
//  Method:  XMLEditFields::UpdateTypeList
//
//  Purpose:
//    Update the combo box listing the available types.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
//  Modifications:
//    Brad Whitlock, Mon Dec 9 13:33:54 PST 2002
//    I added ucharVector.
//
hrchilds's avatar
hrchilds committed
568 569 570
//    Brad Whitlock, Fri Dec 10 10:01:30 PDT 2004
//    I added variablename.
//
hrchilds's avatar
hrchilds committed
571 572 573
//    Brad Whitlock, Thu Mar 1 17:15:02 PST 2007
//    Added built-in AVT enums.
//
hrchilds's avatar
hrchilds committed
574 575 576
//    Kathleen Bonnell, Thu Mar 22 17:12:44 PDT 2007
//    Added scalemode.
//
whitlocb's avatar
whitlocb committed
577 578 579
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
580 581 582 583 584
// ****************************************************************************
void
XMLEditFields::UpdateTypeList()
{
    type->clear();
whitlocb's avatar
whitlocb committed
585 586 587 588 589 590
    type->addItem("int");
    type->addItem("intArray");
    type->addItem("intVector");
    type->addItem("bool");
    type->addItem("float");
    type->addItem("floatArray");
591
    type->addItem("floatVector");
whitlocb's avatar
whitlocb committed
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    type->addItem("double");
    type->addItem("doubleArray");
    type->addItem("doubleVector");
    type->addItem("uchar");
    type->addItem("ucharArray");
    type->addItem("ucharVector");
    type->addItem("string");
    type->addItem("stringVector");
    type->addItem("colortable");
    type->addItem("color");
    type->addItem("opacity");
    type->addItem("linestyle");
    type->addItem("linewidth");
    type->addItem("scalemode");
    type->addItem("variablename");
    type->addItem("att");
    type->addItem("attVector");
hrchilds's avatar
hrchilds committed
609 610

    // Add built-in AVT enums
whitlocb's avatar
whitlocb committed
611 612 613 614 615 616 617 618
    type->addItem("LoadBalanceScheme");
    type->addItem("avtCentering");
    type->addItem("avtExtentType");
    type->addItem("avtGhostType");
    type->addItem("avtMeshCoordType");
    type->addItem("avtMeshType");
    type->addItem("avtSubsetType");
    type->addItem("avtVarType");
hrchilds's avatar
hrchilds committed
619 620

    // Add enums
621
    for (size_t i=0; i<EnumType::enums.size(); i++)
hrchilds's avatar
hrchilds committed
622
    {
whitlocb's avatar
whitlocb committed
623
        type->addItem(QString("enum:") + EnumType::enums[i]->type);
hrchilds's avatar
hrchilds committed
624 625 626 627 628 629 630 631 632 633 634 635
    }
}

// ****************************************************************************
//  Method:  XMLEditFields::UpdateEnablerList
//
//  Purpose:
//    Update the combo box lsting the available fields as enablers.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
636 637 638
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
639 640 641 642 643 644 645
// ****************************************************************************
void
XMLEditFields::UpdateEnablerList()
{
    Attribute *a = xmldoc->attribute;

    enabler->clear();
whitlocb's avatar
whitlocb committed
646
    enabler->addItem(tr("(none)"));
647
    for (size_t i=0; i<a->fields.size(); i++)
hrchilds's avatar
hrchilds committed
648 649
    {
        if (name->text() != a->fields[i]->name)
whitlocb's avatar
whitlocb committed
650
            enabler->addItem(a->fields[i]->name);
hrchilds's avatar
hrchilds committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
    }
}

// ****************************************************************************
//  Method:  XMLEditFields::BlockAllSignals
//
//  Purpose:
//    Blocks/unblocks signals to the widgets.  This lets them get
//    updated by changes in state without affecting the state.
//
//  Arguments:
//    block      whether to block (true) or unblock (false) signals
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
hrchilds's avatar
hrchilds committed
667 668 669 670
//  Modifications:
//    Brad Whitlock, Fri Dec 10 10:45:37 PDT 2004
//    Added variablename type support.
//
hrchilds's avatar
hrchilds committed
671 672 673
//    Brad Whitlock, Wed Feb 28 18:49:38 PST 2007
//    Added access.
//
674 675 676
//    Kathleen Biagas, Thu Aug 25 14:24:11 MST 2011 
//    Added persistent checkbox.
//
hrchilds's avatar
hrchilds committed
677 678 679 680 681 682 683 684 685 686 687 688 689
// ****************************************************************************
void
XMLEditFields::BlockAllSignals(bool block)
{
    fieldlist->blockSignals(block);
    name->blockSignals(block);
    label->blockSignals(block);
    type->blockSignals(block);
    subtype->blockSignals(block);
    length->blockSignals(block);
    enabler->blockSignals(block);
    enableval->blockSignals(block);
    internal->blockSignals(block);
690
    persistent->blockSignals(block);
hrchilds's avatar
hrchilds committed
691
    ignoreeq->blockSignals(block);
hrchilds's avatar
hrchilds committed
692
    varNameButtons->blockSignals(block);
hrchilds's avatar
hrchilds committed
693 694
    init->blockSignals(block);
    values->blockSignals(block);
hrchilds's avatar
hrchilds committed
695
    access->blockSignals(block);
hrchilds's avatar
hrchilds committed
696 697 698 699 700 701 702 703 704 705 706 707 708
}

// ----------------------------------------------------------------------------
//                                 Callbacks
// ----------------------------------------------------------------------------


// ****************************************************************************
//  Method:  XMLEditFields::nameTextChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
709 710 711 712
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
713 714 715 716 717
// ****************************************************************************
void
XMLEditFields::nameTextChanged(const QString &text)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
718
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
719 720 721 722
    if (index == -1)
        return;
    Field *f = a->fields[index];

whitlocb's avatar
whitlocb committed
723
    QString newname = text.trimmed();
hrchilds's avatar
hrchilds committed
724 725 726
    f->name = newname;

    BlockAllSignals(true);
whitlocb's avatar
whitlocb committed
727
    fieldlist->item(index)->setText(newname);
hrchilds's avatar
hrchilds committed
728 729 730 731 732 733 734 735 736
    BlockAllSignals(false);
}

// ****************************************************************************
//  Method:  XMLEditFields::labelTextChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
737 738 739 740
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
741 742 743 744 745
// ****************************************************************************
void
XMLEditFields::labelTextChanged(const QString &text)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
746
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->label = text;
}

// ****************************************************************************
//  Method:  XMLEditFields::typeChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
//  Modifications:
//    Jeremy Meredith, Tue Dec 10 10:24:31 PST 2002
//    Fixed a bug where setting a type to an enum would fail.
//
whitlocb's avatar
whitlocb committed
764 765 766
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
767 768 769 770 771
// ****************************************************************************
void
XMLEditFields::typeChanged(int typeindex)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
772
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
773 774 775 776
    if (index == -1)
        return;
    Field *f = a->fields[index];

whitlocb's avatar
whitlocb committed
777
    QString t = type->itemText(typeindex);
hrchilds's avatar
hrchilds committed
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
    QString st;
    if (t.left(5) == "enum:")
    {
        st = t.right(t.length()-5);
        t = "enum";
    }
    else
    {
        st = subtype->text();
    }

    Field *n = FieldFactory::createField(f->name,
                                         t,
                                         st,
                                         length->text(),
                                         f->label);
    n->CopyValues(f);

796
    for (size_t i=0; i<a->fields.size(); i++)
hrchilds's avatar
hrchilds committed
797
    {
hkrishna's avatar
hkrishna committed
798
        if (i == (size_t)index)
hrchilds's avatar
hrchilds committed
799 800 801 802 803 804 805 806 807 808
            continue;

        if (a->fields[i]->enabler == f)
            a->fields[i]->enabler = n;
    }

    a->fields[index] = n;
    delete f;

    UpdateWindowContents();
whitlocb's avatar
whitlocb committed
809
    fieldlist->setCurrentRow(index);
hrchilds's avatar
hrchilds committed
810 811 812 813 814 815 816 817
}

// ****************************************************************************
//  Method:  XMLEditFields::subtypeTextChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
818 819 820 821
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
822 823 824 825 826
// ****************************************************************************
void
XMLEditFields::subtypeTextChanged(const QString &text)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
827
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->SetSubtype(text);
}

// ****************************************************************************
//  Method:  XMLEditFields::enablerChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
//  Modifications:
//    Jeremy Meredith, Thu Mar 27 12:55:33 PST 2003
//    Fixed a bug with the enabler field selection not being translated
//    into the correct Field pointer.
//
whitlocb's avatar
whitlocb committed
846 847 848
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
849 850 851 852 853
// ****************************************************************************
void
XMLEditFields::enablerChanged(int enablerindex)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
854
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
    if (index == -1)
        return;
    Field *f = a->fields[index];

    // The index of the signal is the index of the selected entry in the list.
    // The current field is not in that list, but a "(none)" entry  does
    // appear at the top.  Thus, the mapping of list index to field index is
    // shifted up one because of the first entry, and then shifted back down
    // one after the index of the current field because it is skipped.
    int enablerfieldindex = (enablerindex <= index) ? 
                                                enablerindex-1 : enablerindex;
    if (enablerfieldindex == -1)
    {
        f->enabler = NULL;
        f->enableval.clear();
        enableval->clear();
    }
    else
    {
        f->enabler = a->fields[enablerfieldindex];
    }

    UpdateWindowSensitivity();
}

// ****************************************************************************
//  Method:  XMLEditFields::enablevalTextChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
886 887 888 889
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
890 891 892 893 894
// ****************************************************************************
void
XMLEditFields::enablevalTextChanged(const QString &text)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
895
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
896 897 898 899 900 901 902 903 904 905 906 907 908
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->enableval = SplitValues(text);
}

// ****************************************************************************
//  Method:  XMLEditFields::lengthTextChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
909 910 911 912
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
913 914 915 916 917
// ****************************************************************************
void
XMLEditFields::lengthTextChanged(const QString &text)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
918
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
919 920 921 922 923 924 925 926 927 928 929 930 931
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->length = text.toInt();
}

// ****************************************************************************
//  Method:  XMLEditFields::internalChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
932 933 934 935
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
936 937 938 939 940
// ****************************************************************************
void
XMLEditFields::internalChanged()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
941
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
942 943 944 945 946 947 948
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->internal = internal->isChecked();
}

949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
// ****************************************************************************
//  Method:  XMLEditFields::persistentChanged
//
//  Programmer:  Kathleen Biagas 
//  Creation:    August 25, 2011
//
//  Modifications:
//
// ****************************************************************************
void
XMLEditFields::persistentChanged()
{
    Attribute *a = xmldoc->attribute;
    int index = fieldlist->currentRow();
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->persistent = persistent->isChecked();
}

hrchilds's avatar
hrchilds committed
970 971 972 973 974 975
// ****************************************************************************
//  Method:  XMLEditFields::ignoreeqChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
976 977 978 979
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
980 981 982 983 984
// ****************************************************************************
void
XMLEditFields::ignoreeqChanged()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
985
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
986 987 988 989 990 991 992
    if (index == -1)
        return;
    Field *f = a->fields[index];

    f->ignoreEquality = ignoreeq->isChecked();
}

hrchilds's avatar
hrchilds committed
993 994 995 996 997 998
// ****************************************************************************
//  Method:  XMLEditFields::accessChanged
//
//  Programmer:  Brad Whitlock
//  Creation:    Wed Feb 28 18:50:06 PST 2007
//
whitlocb's avatar
whitlocb committed
999 1000 1001 1002
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
1003 1004 1005 1006 1007
// ****************************************************************************
void
XMLEditFields::accessChanged(int btn)
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
1008
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
    if (index == -1)
        return;
    Field *f = a->fields[index];

    if(btn == 0)
        f->SetPrivateAccess();
    else if(btn == 1)
        f->SetProtectedAccess();
    else
        f->SetPublicAccess();
}

hrchilds's avatar
hrchilds committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
// ****************************************************************************
// Method: XMLEditFields::variableTypeClicked
//
// Purpose: 
//   This slot function is called when one of the vartype checkboxes is
//   clicked.
//
// Arguments:
//   bIndex : The index of the button that was clicked.
//
// Programmer: Brad Whitlock
// Creation:   Fri Dec 10 10:51:49 PDT 2004
//
// Modifications:
whitlocb's avatar
whitlocb committed
1035 1036 1037
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
1038 1039 1040
//    Jeremy Meredith, Thu Mar 19 12:01:02 EDT 2009
//    Finish Qt4 port.
//
hrchilds's avatar
hrchilds committed
1041 1042 1043 1044 1045
// ****************************************************************************

void
XMLEditFields::variableTypeClicked(int bIndex)
{
1046
    QAbstractButton *b = varNameButtons->button(bIndex);
whitlocb's avatar
whitlocb committed
1047 1048 1049 1050 1051 1052

    Attribute *a = xmldoc->attribute;
    int index = fieldlist->currentRow();
    if (index == -1)
        return;

1053 1054 1055 1056 1057 1058
    Field *f = a->fields[index];
    if(f->type == "variablename")
    {
        int mask = ~(1 << bIndex);
        int bit = (b->isChecked() ? 1 : 0) << bIndex;
        f->varTypes = (f->varTypes & mask) | bit;
hrchilds's avatar
hrchilds committed
1059 1060 1061
    }
}

hrchilds's avatar
hrchilds committed
1062 1063 1064 1065 1066 1067
// ****************************************************************************
//  Method:  XMLEditFields::initChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
1068 1069 1070 1071
//  Modifications:
//    Brad Whitlock, Thu Mar 6 15:36:09 PST 2008
//    Updated.
//
whitlocb's avatar
whitlocb committed
1072 1073 1074
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
1075 1076 1077 1078 1079
// ****************************************************************************
void
XMLEditFields::initChanged()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
1080
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
1081 1082 1083 1084 1085 1086
    if (index == -1)
        return;
    Field *f = a->fields[index];

    if (init->isChecked())
    {
whitlocb's avatar
whitlocb committed
1087
        f->SetInitCodeFromString(values->toPlainText());
hrchilds's avatar
hrchilds committed
1088 1089 1090
    }
    else
    {
1091
        std::vector<QString> splitvalues = SplitValues(values->toPlainText());
bonnell's avatar
bonnell committed
1092
        int length = (int)splitvalues.size();
hrchilds's avatar
hrchilds committed
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
        if (!f->isVector && (length > f->length))
            length = f->length;
        f->ClearValues();
        for (int i=0; i<length; i++)
        {
            try
            {
                f->SetValue(splitvalues[i], i);
            }
            catch(...)
            {
            }
        }
whitlocb's avatar
whitlocb committed
1106
        f->SetInitCodeFromString(QString());
hrchilds's avatar
hrchilds committed
1107 1108 1109 1110 1111 1112 1113 1114 1115
    }
}

// ****************************************************************************
//  Method:  XMLEditFields::valuesChanged
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
1116 1117 1118 1119
//  Modifications:
//    Brad Whitlock, Thu Mar 6 15:38:41 PST 2008
//    Updated init coding.
//
whitlocb's avatar
whitlocb committed
1120 1121 1122
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
1123 1124 1125 1126 1127
// ****************************************************************************
void
XMLEditFields::valuesChanged()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
1128
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
1129 1130 1131 1132 1133 1134
    if (index == -1)
        return;
    Field *f = a->fields[index];

    if (init->isChecked())
    {
whitlocb's avatar
whitlocb committed
1135
        f->SetInitCodeFromString(values->toPlainText());
hrchilds's avatar
hrchilds committed
1136 1137 1138
    }
    else
    {
1139
        std::vector<QString> splitvalues = SplitValues(values->toPlainText());
bonnell's avatar
bonnell committed
1140
        int length = (int)splitvalues.size();
hrchilds's avatar
hrchilds committed
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
        if (!f->isVector && (length > f->length))
            length = f->length;
        f->ClearValues();
        for (int i=0; i<length; i++)
        {
            try
            {
                f->SetValue(splitvalues[i], i);
            }
            catch(...)
            {
            }
        }
whitlocb's avatar
whitlocb committed
1154
        f->SetInitCodeFromString(QString());
hrchilds's avatar
hrchilds committed
1155 1156 1157 1158 1159 1160 1161 1162 1163
    }
}

// ****************************************************************************
//  Method:  XMLEditFields::fieldlistNew
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
1164 1165 1166 1167
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
// ****************************************************************************
void
XMLEditFields::fieldlistNew()
{
    Attribute *a = xmldoc->attribute;
    int newid = 1;
    bool okay = false;
    QString newname;
    while (!okay)
    {
        okay = true;
        newname.sprintf("unnamed%d", newid);
1180
        for (int i=0; i<fieldlist->count() && okay; i++)
hrchilds's avatar
hrchilds committed
1181
        {
whitlocb's avatar
whitlocb committed
1182
            if (fieldlist->item(i)->text() == newname)
hrchilds's avatar
hrchilds committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
                okay = false;
        }
        if (!okay)
            newid++;
    }
    
    Field *f = FieldFactory::createField(newname,"int","","",newname);
    
    a->fields.push_back(f);
    UpdateWindowContents();
1193
    for (int i=0; i<fieldlist->count(); i++)
hrchilds's avatar
hrchilds committed
1194
    {
whitlocb's avatar
whitlocb committed
1195
        if (fieldlist->item(i)->text() == newname)
hrchilds's avatar
hrchilds committed
1196
        {
whitlocb's avatar
whitlocb committed
1197
            fieldlist->setCurrentRow(i);
hrchilds's avatar
hrchilds committed
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
            UpdateWindowSingleItem();
        }
    }
}

// ****************************************************************************
//  Method:  XMLEditFields::fieldlistDel
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
1209 1210 1211 1212
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
1213 1214 1215 1216 1217
// ****************************************************************************
void
XMLEditFields::fieldlistDel()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
1218
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
1219 1220 1221 1222 1223

    if (index == -1)
        return;

    Field *f = a->fields[index];
1224
    std::vector<Field*> newlist;
1225
    for (size_t i=0; i<a->fields.size(); i++)
hrchilds's avatar
hrchilds committed
1226 1227 1228 1229 1230 1231 1232 1233
    {
        if (a->fields[i] != f)
            newlist.push_back(a->fields[i]);
    }
    a->fields = newlist;

    // Make sure anyone with a reference to the old one
    // points to the new one instead
1234
    for (size_t i=0; i<a->fields.size(); i++)
hrchilds's avatar
hrchilds committed
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
    {
        if (a->fields[i]->enabler == f)
        {
            a->fields[i]->enabler = NULL;
            a->fields[i]->enableval.clear();
        }
    }

    delete f;

    UpdateWindowContents();

    if (index >= fieldlist->count())
        index = fieldlist->count()-1;
whitlocb's avatar
whitlocb committed
1249
    fieldlist->setCurrentRow(index);
hrchilds's avatar
hrchilds committed
1250 1251 1252 1253 1254 1255 1256 1257
}

// ****************************************************************************
//  Method:  XMLEditFields::fieldlistUp
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
1258 1259 1260 1261 1262 1263 1264 1265
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 2008
//    First pass at porting to Qt 4.4.0
//
//    Cyrus Harrison, Mon Nov 24 09:09:51 PST 2008
//    Fixed bug w/ wrong text label in fieldList.
//
//
hrchilds's avatar
hrchilds committed
1266 1267 1268 1269 1270
// ****************************************************************************
void
XMLEditFields::fieldlistUp()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
1271
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286

    if (index == -1)
        return;

    if (index < 1)
        return;

    Field *f = a->fields[index];
    a->fields[index] = a->fields[index-1];
    a->fields[index-1] = f;

    a->fields[index]->index   = index;
    a->fields[index-1]->index = index-1;

    BlockAllSignals(true);
whitlocb's avatar
whitlocb committed
1287 1288 1289
    fieldlist->item(index)->setText(a->fields[index]->name);
    fieldlist->item(index-1)->setText(a->fields[index-1]->name);
    fieldlist->setCurrentRow(index-1);
hrchilds's avatar
hrchilds committed
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
    BlockAllSignals(false);

    UpdateWindowSensitivity();
}

// ****************************************************************************
//  Method:  XMLEditFields::fieldlistDown
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 17, 2002
//
whitlocb's avatar
whitlocb committed
1301 1302 1303 1304
//  Modifications:
//    Cyrus Harrison, Thu May 15 16:00:46 PDT 200
//    First pass at porting to Qt 4.4.0
//
hrchilds's avatar
hrchilds committed
1305 1306 1307 1308 1309
// ****************************************************************************
void
XMLEditFields::fieldlistDown()
{
    Attribute *a = xmldoc->attribute;
whitlocb's avatar
whitlocb committed
1310
    int index = fieldlist->currentRow();
hrchilds's avatar
hrchilds committed
1311 1312 1313 1314

    if (index == -1)
        return;

hkrishna's avatar
hkrishna committed
1315
    if ((size_t)index > a->fields.size() - 2)
hrchilds's avatar
hrchilds committed
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
        return;

    Field *f = a->fields[index];
    a->fields[index] = a->fields[index+1];
    a->fields[index+1] = f;

    a->fields[index]->index   = index;
    a->fields[index+1]->index = index+1;

    BlockAllSignals(true);
whitlocb's avatar
whitlocb committed
1326 1327 1328
    fieldlist->item(index)->setText(a->fields[index]->name);
    fieldlist->item(index+1)->setText(a->fields[index+1]->name);
    fieldlist->setCurrentRow(index+1);
hrchilds's avatar
hrchilds committed
1329 1330 1331 1332
    BlockAllSignals(false);

    UpdateWindowSensitivity();
}