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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 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 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
|
/* massXpert - the true massist's program.
--------------------------------------
Copyright(C) 2006,2007 Filippo Rusconi
http://www.massxpert.org/massXpert
This file is part of the massXpert project.
The massxpert project is the successor to the "GNU polyxmass"
project that is an official GNU project package(see
www.gnu.org). The massXpert project is not endorsed by the GNU
project, although it is released ---in its entirety--- under the
GNU General Public License. A huge part of the code in massXpert
is actually a C++ rewrite of code in GNU polyxmass. As such
massXpert was started at the Centre National de la Recherche
Scientifique(FRANCE), that granted me the formal authorization to
publish it under this Free Software License.
This software is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 3, as published by the Free Software Foundation.
This software 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 software; if not, write to the
Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/////////////////////// Qt includes
#include <QtGui>
#include <QtGlobal>
/////////////////////// Local includes
#include "mzLabWnd.hpp"
#include "mainWindow.hpp"
#include "application.hpp"
#include "mzLabInputOligomerTreeViewDlg.hpp"
#include "mzLabOutputOligomerTreeViewDlg.hpp"
#include "oligomerPair.hpp"
#include "fragmentOligomer.hpp"
namespace massXpert
{
MzLabWnd::MzLabWnd(QString &filePath)
{
m_forciblyClose = false;
m_noDelistWnd = false;
if (filePath.isEmpty())
{
QMessageBox::warning(0,
tr("massXpert - Calculator"),
tr("Polymer chemistry definition "
"filepath empty."),
QMessageBox::Ok);
return;
}
m_polChemDef.setFilePath(filePath);
if (!initialize())
{
QMessageBox::warning(0,
tr("massXpert - Calculator"),
tr("Failed to initialize the mz lab window."),
QMessageBox::Ok);
}
setWindowTitle(tr("%1 %2[*]")
.arg(tr("massXpert: mz Lab - "))
.arg(m_polChemDef.name()));
QSettings settings
(static_cast<Application *>(qApp)->configSettingsFilePath(),
QSettings::IniFormat);
settings.beginGroup("mz_lab_wnd");
restoreGeometry(settings.value("geometry").toByteArray());
m_ui.leftSplitter->
restoreState(settings.value("leftSplitter").toByteArray());
m_ui.rightSplitter->
restoreState(settings.value("rightSplitter").toByteArray());
settings.endGroup();
show();
}
MzLabWnd::~MzLabWnd()
{
while(m_dlgList.size())
delete m_dlgList.takeFirst();
}
void
MzLabWnd::closeEvent(QCloseEvent *event)
{
Application *application = static_cast<Application *>(qApp);
// We are asked to close the window even if it has unsaved data.
if (m_forciblyClose)
{
m_forciblyClose = false;
// We have to delist the window.
if(!m_noDelistWnd)
{
m_noDelistWnd = false;
int index = application->mzLabWndList()->indexOf(this);
application->mzLabWndList()->takeAt(index);
}
writeSettings();
event->accept();
return;
}
if (maybeSave())
{
// We are asked not to remove this window from the list of all
// the mz lab windows. This occurs when all the windows are
// closed in a raw in the application object.
if(m_noDelistWnd)
{
m_noDelistWnd = false;
writeSettings();
event->accept();
return;
}
// We must remove this window from the application's list of
// such windows:
int index = application->mzLabWndList()->indexOf(this);
application->mzLabWndList()->takeAt(index);
writeSettings();
event->accept();
}
else
{
event->ignore();
}
}
bool
MzLabWnd::initialize()
{
m_ui.setupUi(this);
QPixmap pixmap(":/images/massxpert-icon-32.png");
QIcon icon(pixmap);
setWindowIcon(icon);
setAttribute(Qt::WA_DeleteOnClose);
statusBar()->setSizeGripEnabled(true);
m_ui.ionizationChargeSpinBox->setRange(1, 1000000000);
m_ui.ionizationLevelSpinBox->setRange(0, 1000000000);
m_ui.incrementChargeSpinBox->setRange(-1000000000, 1000000000);
// The tolerance when filtering mono/avg masses...
QStringList stringList;
stringList << tr("AMU") << tr("PCT") << tr("PPM");
m_ui.toleranceComboBox->insertItems(0, stringList);
m_ui.toleranceComboBox->setCurrentIndex(0);
m_ui.toleranceComboBox->setToolTip(tr("AMU: atom mass unit \n"
"PCT: percent \n"
"PPM: part per million"));
m_ui.toleranceLineEdit->setText("1");
////// Connection of the SIGNALS and SLOTS //////
connect(m_ui.applyFormulaPushButton,
SIGNAL(clicked()),
this,
SLOT(applyFormulaPushButton()));
connect(m_ui.applyMassPushButton,
SIGNAL(clicked()),
this,
SLOT(applyMassPushButton()));
connect(m_ui.applyThresholdPushButton,
SIGNAL(clicked()),
this,
SLOT(applyThresholdPushButton()));
connect(m_ui.incrementChargePushButton,
SIGNAL(clicked()),
this,
SLOT(incrementChargePushButton()));
connect(m_ui.reionizePushButton,
SIGNAL(clicked()),
this,
SLOT(reionizePushButton()));
connect(m_ui.performMatchesPushButton,
SIGNAL(clicked()),
this,
SLOT(performMatchesPushButton()));
connect(m_ui.newInputListPushButton,
SIGNAL(clicked()),
this,
SLOT(newInputList()));
connect(m_ui.catalogue1ListWidget,
SIGNAL(itemClicked(QListWidgetItem *)),
this,
SLOT(inputListWidgetItemClicked(QListWidgetItem *)));
connect(m_ui.catalogue2ListWidget,
SIGNAL(itemClicked(QListWidgetItem *)),
this,
SLOT(inputListWidgetItemClicked(QListWidgetItem *)));
connect(m_ui.deleteInputListPushButton,
SIGNAL(clicked()),
this,
SLOT(deleteInputListItem()));
if (!m_polChemDef.renderXmlPolChemDefFile())
return false;
m_ionizeRule = m_polChemDef.ionizeRule();
m_ui.ionizationFormulaLineEdit->setText(m_ionizeRule.formula());
m_ui.ionizationChargeSpinBox->setValue(m_ionizeRule.charge());
m_ui.ionizationLevelSpinBox->setValue(m_ionizeRule.level());
m_ui.reIonizationFormulaLineEdit->setText(m_ionizeRule.formula());
m_ui.reIonizationChargeSpinBox->setValue(m_ionizeRule.charge());
m_ui.reIonizationLevelSpinBox->setValue(m_ionizeRule.level());
return true;
}
PolChemDef *
MzLabWnd::polChemDef()
{
return &m_polChemDef;
}
const IonizeRule &
MzLabWnd::ionizeRule() const
{
return m_ionizeRule;
}
void
MzLabWnd::writeSettings()
{
QSettings settings
(static_cast<Application *>(qApp)->configSettingsFilePath(),
QSettings::IniFormat);
settings.beginGroup("mz_lab_wnd");
settings.setValue("geometry", saveGeometry());
settings.setValue("leftSplitter", m_ui.leftSplitter->saveState());
settings.setValue("rightSplitter", m_ui.rightSplitter->saveState());
settings.endGroup();
}
void
MzLabWnd::updateWindowTitle()
{
setWindowTitle(tr("%1 %2[*]")
.arg(tr("massXpert: mz Lab - "))
.arg(m_polChemDef.name()));
}
double
MzLabWnd::calculateTolerance(double value)
{
int index = m_ui.toleranceComboBox->currentIndex();
QString text = m_ui.toleranceLineEdit->text();
bool ok = false;
double nominal = qAbs(text.toDouble(&ok));
if (!nominal && !ok)
return -1;
if (index == 0)
{
// MXT_MASS_TOLERANCE_AMU
return nominal;
}
else if (index == 1)
{
// MXT_MASS_TOLERANCE_PCT
return(nominal *(value / 100));
}
else if (index == 2)
{
// MXT_MASS_TOLERANCE_PPM
return(nominal *(value / 1000000));
}
else
Q_ASSERT(0);
return -1;
}
void
MzLabWnd::fillMolecularMassList(const OligomerList *oligomerList,
QList<double> *listM, MassType &massType)
{
Q_ASSERT(oligomerList);
Q_ASSERT(listM);
double mass = 0;
for (int iter = 0; iter < oligomerList->size(); ++iter)
{
Oligomer *oligomer = oligomerList->at(iter);
FragmentOligomer *fragOligomer =
dynamic_cast<FragmentOligomer *>(oligomer);
if(fragOligomer)
{
// Depending on the massType, select the proper molecular
// mass. Note that it is not possible that the mass be < 0.
mass = fragOligomer->molecularMass(massType);
}
else
mass = oligomer->molecularMass(massType);
if(mass < 0)
qFatal("Fatal error at %s@%d. Program aborted. Mass was:%.5f",
__FILE__, __LINE__, mass);
listM->append(mass);
}
}
void
MzLabWnd::applyFormulaPushButton()
{
MzLabInputOligomerTreeViewDlg *dlg = 0;
if (!inputListDlg(&dlg))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, select one input list first.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
QString text = m_ui.formulaLineEdit->text();
if (text.isEmpty())
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, enter a valid formula.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
Formula formula(text);
if (!formula.validate(m_polChemDef.atomList()))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"The formula '%3' is not valid.")
.arg(__FILE__)
.arg(__LINE__)
.arg(formula.formula()));
return;
}
// At this point we can ask the list modification.
bool inPlace = m_ui.inPlaceCalculationCheckBox->isChecked();
dlg->applyFormula(formula, inPlace);
}
void
MzLabWnd::applyMassPushButton()
{
MzLabInputOligomerTreeViewDlg *dlg = 0;
if (!inputListDlg(&dlg))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, select one input list first.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
QString text = m_ui.massLineEdit->text();
if (text.isEmpty())
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, enter a valid mass.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
Application *application = static_cast<Application *>(qApp);
QLocale locale = application->locale();
bool ok = false;
double mass = locale.toDouble(text, &ok);
if (!mass && !ok)
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Failed to convert %3 to double")
.arg(__FILE__)
.arg(__LINE__)
.arg(text));
return;
}
// At this point we can ask the list modification.
bool inPlace = m_ui.inPlaceCalculationCheckBox->isChecked();
dlg->applyMass(mass, inPlace);
}
void
MzLabWnd::applyThresholdPushButton()
{
MzLabInputOligomerTreeViewDlg *dlg = 0;
if (!inputListDlg(&dlg))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, select one input list first.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
QString text = m_ui.thresholdLineEdit->text();
if (text.isEmpty())
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, enter a valid threshold.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
Application *application = static_cast<Application *>(qApp);
QLocale locale = application->locale();
bool ok = false;
double threshold = locale.toDouble(text, &ok);
if (!threshold && !ok)
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Failed to convert %3 to double")
.arg(__FILE__)
.arg(__LINE__)
.arg(text));
return;
}
// At this point we can ask the list modification.
bool inPlace = m_ui.inPlaceCalculationCheckBox->isChecked();
bool onMz = m_ui.mzThresholdRadioButton->isChecked();
dlg->applyThreshold(threshold, inPlace, onMz);
}
void
MzLabWnd::incrementChargePushButton()
{
MzLabInputOligomerTreeViewDlg *dlg = 0;
if (!inputListDlg(&dlg))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, select one input list first.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
int increment = m_ui.incrementChargeSpinBox->value();
if (!increment)
{
QMessageBox::warning
(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, enter a valid increment.")
.arg(__FILE__)
.arg(__LINE__),
QMessageBox::Ok);
return;
}
// At this point we can ask the list modification.
bool inPlace = m_ui.inPlaceCalculationCheckBox->isChecked();
dlg->applyChargeIncrement(increment, inPlace);
}
void
MzLabWnd::reionizePushButton()
{
MzLabInputOligomerTreeViewDlg *dlg = 0;
if (!inputListDlg(&dlg))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Please, select one input list first.")
.arg(__FILE__)
.arg(__LINE__));
return;
}
IonizeRule ionizeRule;
ionizeRule.setFormula(m_ui.reIonizationFormulaLineEdit->text());
ionizeRule.setCharge(m_ui.reIonizationChargeSpinBox->value());
ionizeRule.setLevel(m_ui.reIonizationLevelSpinBox->value());
if (!ionizeRule.validate(m_polChemDef.atomList()))
{
QMessageBox::warning
(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"Failed to validate ionization rule.")
.arg(__FILE__)
.arg(__LINE__),
QMessageBox::Ok);
return;
}
// At this point we can ask the list modification.
bool inPlace = m_ui.inPlaceCalculationCheckBox->isChecked();
dlg->applyIonizeRule(ionizeRule, inPlace);
}
void
MzLabWnd::performMatchesPushButton()
{
// We have to get the name of two lists. The first list's item
// should be matched to the second list's items. The user might ask
// that the second list's items be modified to match the first
// list's ones.
MzLabInputOligomerTreeViewDlg *dlg1 = 0;
MzLabInputOligomerTreeViewDlg *dlg2 = 0;
if (!inputListsDlg(&dlg1, &dlg2))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("This feature performs matches between "
"two input lists.\n"
"Please, select two input lists first."),
QMessageBox::Ok);
return;
}
// The general idea is to first create for each m/z--z list a
// corresponding list of M values(that is to first deionize the
// m/z into M). Next, the comparison will be performed on the M
// lists. This will ensure that all peaks are matched even if
// simulation peaks are for z=1 and z=2, for example, and the
// measured m/z has peaks with z=3.
// The m/z--z lists and the M lists will retain a complete
// correlation, that is the order of their components will not be
// modified, and the their number neither. Which means that, for
// example, the item in m/z list 1 [index 0] will correspond to
// the item in M list [index 0].
// The comparison of M list 1 with M list 2 will possibly yield
// matches which will be reported in an output list of which the
// items will retain links to the initial m/z lists 1 and 2. This
// way, it will be possible to trace back the matched m/z items
// for a given match.
// The dlg1 holds the list that has the measured data(that is
// factual m/z values that cannot be changed in any way). The dlg2
// holds the theoretical m/z values that might undergo chemical
// modifications in order to seek matches in the dlg1 list.
// The two lists might not have the same item count.
MassType massType1 = dlg1->massType();
MassType massType2 = dlg2->massType();
if (massType1 != massType2)
{
int ret =
QMessageBox::question(this, tr("massXpert - mz Lab"),
tr("The lists to match are not of the same "
"mass type.\n\nContinue?"),
QMessageBox::Yes | QMessageBox::No);
if(ret == QMessageBox::No)
return;
}
// For clearness...
MassType massType = massType1;
// qDebug() << __FILE__ << __LINE__
// << "massType:" << massType;
// Create the two lists that will hold the double values.
// First list.
const OligomerList *listMz1 = dlg1->oligomerList();
QList<double> listM1;
fillMolecularMassList(listMz1, &listM1, massType);
Q_ASSERT(listMz1->size() == listM1.size());
// Second list.
const OligomerList *listMz2 = dlg2->oligomerList();
QList<double> listM2;
fillMolecularMassList(listMz2, &listM2, massType);
Q_ASSERT(listMz2->size() == listM2.size());
// Allocate the new list of OligomerPair instances into which
// we'll append OligomerPairs instances corresponding to
// successful matches between oligomers.
QList <OligomerPair *> *oligomerPairList =
new QList <OligomerPair *>();
// At this point we have the two lists with molecular masses. We
// can start doing the matches.
for (int iter = 0; iter < listM1.size(); ++iter)
{
double mass1 = listM1.at(iter);
for(int jter = 0; jter < listM2.size(); ++jter)
{
double mass2 = listM2.at(jter);
double tolerance = calculateTolerance(mass1);
if (mass2 >= mass1 - tolerance &&
mass2 <= mass1 + tolerance)
{
// qDebug() << __FILE__ << __LINE__
// << "M1 at index:" << iter
// << "matches"
// << "M2 at index:" << jter;
// At this point we can create a new OligomerPair.
OligomerPair *oligomerPair =
new OligomerPair(listMz1->at(iter), listMz2->at(jter),
massType,
qAbs(mass2 - mass1), "NOT_SET");
oligomerPairList->append(oligomerPair);
// qDebug() << __FILE__ << __LINE__
// << "Appended oligomer pair:"
// << oligomerPair->oligomer1()->name()
// << oligomerPair->oligomer2()->name()
// << "checksum:" << oligomerPair->oligomer1()->
// polymer()->checksum();
}
}
}
// qDebug() << __FILE__ << __LINE__
// << "Found pairs:" << oligomerPairList->size();
// Allocate the new dialog, we pass
QString dialogName = tr("%1 vs %2")
.arg(dlg1->name())
.arg(dlg2->name());
// Ownership of oligomerPairList is going to be transferred to the
// dialog being created (note that to the dialog and not the tree
// view model in the dialog's tree view).
MzLabOutputOligomerTreeViewDlg *dlg =
new MzLabOutputOligomerTreeViewDlg(this, oligomerPairList,
massType1,
dlg1, dlg2, dialogName);
dlg->show();
}
bool
MzLabWnd::inputListDlg(MzLabInputOligomerTreeViewDlg **dlg)
{
QListWidgetItem *item = 0;
// Which list of lists is selected ?
if (m_ui.catalogue1RadioButton->isChecked())
item = m_ui.catalogue1ListWidget->currentItem();
else
item = m_ui.catalogue2ListWidget->currentItem();
if (!item)
return false;
// Get the name of the dialog window represented by the item and
// find the dialog window itself.
QString text = item->text();
MzLabInputOligomerTreeViewDlg *dialog = findDlg(text);
Q_ASSERT(dialog);
*dlg = dialog;
return true;
}
bool
MzLabWnd::inputListsDlg(MzLabInputOligomerTreeViewDlg **dlg1,
MzLabInputOligomerTreeViewDlg **dlg2)
{
QListWidgetItem *item1 = 0;
QListWidgetItem *item2 = 0;
// Which lists of lists is selected ?
item1 = m_ui.catalogue1ListWidget->currentItem();
item2 = m_ui.catalogue2ListWidget->currentItem();
if (!item1 || !item2)
return false;
// Get the name of the dialog window represented by the two items
// and find the corresponding dialog windows.
QString text = item1->text();
MzLabInputOligomerTreeViewDlg *dialog = findDlg(text);
Q_ASSERT(dialog);
*dlg1 = dialog;
text = item2->text();
dialog = 0;
dialog = findDlg(text);
Q_ASSERT(dialog);
*dlg2 = dialog;
return true;
}
MzLabInputOligomerTreeViewDlg *
MzLabWnd::newInputList()
{
// Ask that the user give a name to the list.
bool ok;
QString name =
QInputDialog::getText(this, tr("Give a name to the new input list"),
tr("List name:"),
QLineEdit::Normal,
tr("New input list name"), &ok);
if (name.isEmpty() || !ok)
return 0;
// Make sure the name is not already taken.
if (findDlg(name))
{
QMessageBox::warning(this,
tr("massXpert: mz Lab"),
tr("%1@%2\n"
"The '%3' name is already taken.")
.arg(__FILE__)
.arg(__LINE__)
.arg(name),
QMessageBox::Ok);
return 0;
}
MzLabInputOligomerTreeViewDlg *dlg =
new MzLabInputOligomerTreeViewDlg(this, name);
dlg->show();
// Now we can add the item to the lists of input...
m_ui.catalogue1ListWidget->addItem(name);
m_ui.catalogue2ListWidget->addItem(name);
// Finally we can add the list to the list of dialog windows.
m_dlgList.append(dlg);
setWindowModified(true);
return dlg;
}
MzLabInputOligomerTreeViewDlg *
MzLabWnd::findDlg(const QString &name)
{
for (int iter = 0; iter < m_dlgList.size(); ++iter)
{
MzLabInputOligomerTreeViewDlg *dlg = m_dlgList.at(iter);
if(dlg->name() == name)
return dlg;
}
return 0;
}
void
MzLabWnd::inputListWidgetItemClicked(QListWidgetItem *item)
{
QString text = item->text();
MzLabInputOligomerTreeViewDlg *dlg = findDlg(text);
Q_ASSERT(dlg);
dlg->show();
}
void
MzLabWnd::deleteInputListItem()
{
// Do this for input 1 list only.
QListWidgetItem *item = m_ui.catalogue1ListWidget->currentItem();
if (!item)
return ;
// Get the name of the dialog window represented by the item and
// find the dialog window itself.
QString text = item->text();
// Destroy the dialog window and update the 2 lists contents.
destroyDlg(text);
// If the last dialog window is destroyed, then the lab is not
// modified anymore.
if (!m_dlgList.size())
setWindowModified(false);
}
void
MzLabWnd::destroyDlg(const QString &name)
{
MzLabInputOligomerTreeViewDlg *dlg = findDlg(name);
Q_ASSERT(dlg);
// Remove the dialog window from the list of dialog windows and
// delete it.
#ifdef DEBUG
int result = m_dlgList.removeAll(dlg);
Q_ASSERT(result);
#else
m_dlgList.removeAll(dlg);
#endif
delete(dlg);
// Update the listWidgets(1 and 2) corresponding items.
QList<QListWidgetItem *> list =
m_ui.catalogue1ListWidget->findItems(name,
Qt::MatchExactly);
Q_ASSERT(list.size() == 1);
QListWidgetItem *item = list.first();
m_ui.catalogue1ListWidget->takeItem(m_ui.catalogue1ListWidget->row(item));
if (item)
delete(item);
list = m_ui.catalogue2ListWidget->findItems(name,
Qt::MatchExactly);
Q_ASSERT(list.size() == 1);
item = list.first();
m_ui.catalogue2ListWidget->takeItem(m_ui.catalogue2ListWidget->row(item));
if (item)
delete(item);
}
bool
MzLabWnd::maybeSave()
{
// Returns true if we can continue(either saved ok or discard). If
// save failed or cancel we return false to indicate to the caller
// that something is wrong.
if (isWindowModified())
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning
(this, tr("massXpert - mz Lab"),
tr("The mz Lab has been modified.\n"
"OK to exit?"),
QMessageBox::Yes | QMessageBox::No);
if(ret == QMessageBox::Yes)
return true;
else
return false;
}
return true;
}
} // namespace massXpert
|