void StocksDialog::split () { int rc = QMessageBox::warning(this, tr("Warning"), tr("Are you sure to split this stock?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton); if (rc == QMessageBox::No) return; QDate dt = splitDate->date(); // verify if split date < first bar Bar bar; db->getFirstBar(bar); if (! bar.getEmptyFlag()) { QDateTime td; bar.getDate(td); if (dt < td.date()) { QMessageBox::information(this, tr("Qtstalker: Error"), tr("Invalid split date.")); return; } } // verify if split date > last bar Bar bar2; db->getLastBar(bar2); if (! bar.getEmptyFlag()) { QDateTime td; bar2.getDate(td); if (dt > td.date()) { QMessageBox::information(this, tr("Qtstalker: Error"), tr("Invalid split date.")); return; } } // verify if the ratio format is correct ?:? QStringList l = QStringList::split(":", splitRatio->text(), FALSE); if (l.count() != 2) { QMessageBox::information(this, tr("Qtstalker: Error"), tr("Invalid split ratio format.\neg. 2:1")); return; } double plyer = l[1].toDouble() / l[0].toDouble(); double volplyer = l[0].toDouble() / l[1].toDouble(); QString s; db->getSymbol(s); BarData *bars = new BarData(s); db->getAllBars(bars); int loop; for (loop = 0; loop < bars->count(); loop++) { Bar bar; bars->getBar(loop, bar); QDateTime td; bar.getDate(td); if (td.date() < dt) { bar.setOpen(bar.getOpen() * plyer); bar.setHigh(bar.getHigh() * plyer); bar.setLow(bar.getLow() * plyer); bar.setClose(bar.getClose() * plyer); bar.setVolume(bar.getVolume() * volplyer); db->setBar(bar); } } delete bars; // adjust any chart objects QDateTime adt(dt, QTime(0,0,0,0)); QString fn; db->getIndexKey(fn); index->getChartObjects(fn, l); for (loop = 0; loop < (int) l.count(); loop++) { Setting set; set.parse(l[loop]); COBase tco; COBase *co = tco.getCO(set); if (! co) continue; co->adjustForSplit(adt, plyer); set.clear(); co->getSettings(set); s = "Name"; QString s2; set.getData(s, s2); index->setChartObject(fn, s2, set); } QMessageBox::information(this, tr("Qtstalker: Split Complete"), tr("Split complete.")); reloadFlag = TRUE; }